Generating Proxy Classes

You can generate proxy class Java files based on OData metadata using either the OData Gradle Plugin or the Proxy Generator CLI tool. Both tools are included in the software package.

These generated proxy classes help consume a specific OData service. Use the OData service’s metadata document to generate your data model. The generated code includes strongly typed functions to perform any OData operation on the data objects.

Using the OData Plug-in

The OData plugin supports OData proxy class generation with the Gradle build.

OData service metadata must be saved in a file in the project. Metadata can be downloaded from the OData service metadata URL. Check with your OData service developer or your SAP system administrator for the URL.

If service definition results in changing metadata, the file must be updated to save new metadata. In the case metadata is spread across multiple files, save all the files in the project and reference the top-level file in schemaFile. The proxy generation task executes when the file content changes.

Adding the OData Gradle Plugin

To add the OData gradle plugin to your project, edit the top-level build.gradle file of your new Android Studio project with the following:

buildscript {
    dependencies {
        classpath '${versions.sapCloudAndroidSdk}'

Configuring the OData Gradle Plugin

To configure the plugin task for proxy class generation, add an "odata" closure to the module-level build.gradle file as indicated in the example in this section.

OData Plugin Configuration

Property Description
verbose Turn on verbose logging. Default is false.
services Configures the OData task to generate proxy classes for the app
testServices Configures the OData task to generate proxy classes for local tests
androidTestServices Configures the OData task to generate proxy classes for Android connected tests

Service Proxy Class Generation Configuration

Property Description
schemaFile The metadata file for the OData service. Located at the $metadata endpoint of the OData service.
packageName Output package name (defaults to CSDL Schema Namespace)
serviceClass Service class name (defaults to entity container name)
nullableProperties All complex/entity properties are nullable (and no exception is thrown when undefined). Default is false.
disableOpenEnumeration Enumeration types permit member addition. Set this option for non-extensible enumerations. Default is false.
additionalParameters List of additional parameters to be passed to proxy class compiler. Default is none.

The following example shows some of the basic configuration elements for proxy class generation from a metadata file.

apply plugin: ''

odata {
    verbose true
    services {
        products {
            schemaFile file("src/main/odata/productssvcmetadata.xml")
            packageName "com.example.products"
            serviceClass "ProductsService"
        orders {
            schemaFile file("src/main/odata/orderssvcmetadata.xml")
            packageName "com.example.orders"
            serviceClass "OrdersService"

In some cases generation may fail and suggest internal options that can be provided to additionalParameters.


additionalParameters = ["-parser:ALLOW_CASE_CONFLICTS"]

Using the OData Proxy Class Generator Command-line Tool

You can also generate your proxy classes by running the OData Proxy Class Generator tool. Ensure you have a current Java installation and that it is in your system’s path.

The proxygenerator uses the following options:

Options Description
-m Metadata: metadata file
-d Destination: The destination where the proxy classes will be generated. (defaults to the current path)
-h Help
-np Nullable properties: All complex/entity properties are nullable. No exception is thrown when undefined. The default is false
-p Package: The output package name. Defaults to the CSDL Schema Namespace.
-s Service: The service class name. Defaults to the entity container name.
-v Verbose: Verbose mode on. The default is false.

To generate proxy classes using the OData Proxy Class Generator tool:

  1. Download the desired OData service metadata document from its URL and save it in a file (for example, MyMetadata.xml).
  2. Enter the following command in terminal to generate the Java proxy classes:

    • For Mac:

      $SAP_ANDROID_HOME/tools/proxygenerator/bin/proxygenerator -m <path to MyMetadata.xml> -s <MyServiceName> -p <Generated Proxy Class Package Name> -d <Generated Proxy Destination>

    • For Windows:

      proxygenerator.bat -m <path to MyMetadata.xml> -s <MyServiceName> -p <Generated Proxy Class Package Name> -d <Generated Proxy Destination>


      • SAP_ANDROID_HOME is environment variable set to point to the folder where SDK is unzipped.
      • MyMetadata.xml is the downloaded metadata document.
      • MyServiceName is the generated service class name.
  3. Find the generated .java file(s) by default in the current folder or whatever the -d option is set to.