Skip to content

Setting Up the Android Development Environment

Set up your Android environment for Native OData app development.

! Restriction Android Studio is the official IDE for Android, you should not use Eclipse with ADT, since further updates are unavailable. See https://developer.android.com/sdk/installing/migrate.html for information about migrating to Android Studio.

Create a new Android project in Android Studio, and add required JAR and AAR files to the project.

Android Environment Requirements

Complete the prerequisites for setting up the development environment.

Install Android Studio. See https://developer.android.com/tools/studio/index.html

For information on supported Google Android development environment in SAP Mobile Platform 3.1, see https://support.sap.com/release-upgrade-maintenance/pam.html

Setting Up Android Studio for Native SDK Development

Create a new Android project in Android Studio, and add required JAR and AAR files to the project.

Use the build.gradle file to add SAP Mobile Platform SDK OData library resources to your Android project and set other application properties.

Procedure

1.. Retrieve the SMP Native SDK 3.1.x.x zip file (the latest one) from Software Downloads

  • Under Installation and Upgrades, select Access downloads.
  • Expand By Alphabetical Index (A-Z), select M, then select SAP MOBILE PLATFORM SDK 3.1.
  • Select SAP NATIVE SDK3.1.
  • Extract the contents of the .zip file to a temporary directory on the target host.

2.. Open Android Studio

3.. Create new Android Studio Project

The folder structure of your new project should look similar to the below example.

.
├── MyFirstProject.iml
├── app
│   ├── app.iml
│   ├── build
│   ├── build.gradle
│   ├── libs
│   ├── proguard-rules.pro
│   └── src
│       ├── androidTest
│       ├── main
│       └── test
├── build.gradle
├── gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle

4.. Copy JAR and AAR files necessary for your project.

We encourage you to only use dependencies that are used in their projects. Copying all jar and aar files will create a much larger apk file, and in some case will make root cause analysis much harder and more time consuming. We have included proper dependency information for every component in the respective developer guide chapters.

In our example application we will only need network support. There will be no authentication, thus we will only need HttpConversation.aar. From the directory you unzipped the SMP SDK distribution bundle, please copy <path to SMP SDK folder>/libraries/HttpConversation-4.0.0.aar file to your <project-folder>/app/libs folder.

.
├── MyFirstProject.iml
├── app
│   ├── app.iml
│   ├── build
│   ├── build.gradle
│   └── libs
|       ├── HttpConversation-4.0.0.aar
│   ├── proguard-rules.pro
│   └── src
│       ├── androidTest
│       ├── main
│       └── test
├── build.gradle
├── gradle
├── gradle.properties
├── gradlew
├── gradlew.bat
├── local.properties
└── settings.gradle

5.. Open your app module build file build.gradle (Module: app) Copy these lines into your gradle file:

    repositories{
        flatDir{
            dirs 'libs'
        }
    }
  • Verify (or add) this line into the dependencies section of the build.gradle file:
   implementation fileTree(include: ['*.jar'], dir: 'libs')

In our example we have not used any jar dependencies but later you might need to add other dependencies that are shipped in form of jar files.

After this line within the dependencies section, insert the following lines for each of the AAR files you copied into the libs folder:

   implementation(name:'<AAR FILE NAME>', ext:'aar')

For example:

javaimplementation(name:'HttpConversation-4.0.0', ext:'aar') //component and product version numbers can defer

and so on. Insert a line for each AAR file.

6.. Click Sync Now to sync your project.

Your newly referenced AAR libs also should appear among the external libraries: alt text

Check if you can use the selected dependencies.

Having a successful gradle build and seeing the newly added dependency in the External Libraries list is a good start. In order to be 100% sure that your setup is complete we recommend trying out the following simple network call from your MainActivity.java file.

Please note that in order for Android to allow a network request to reach the internet you have to provide access to the proper services on the phone and you also need to make sure that the necessary trust privileges are provided for the server you are trying to reach. Please read the respective Android developer guides.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        HttpConversationManager manager = new HttpConversationManager(this);
        IHttpConversation conv = manager.create(Uri.parse("http://services.odata.org/V3/OData/OData.svc/"));

        conv.setResponseListener(event -> {
            Log.i("MyFirstProject",IReceiveEvent.Util.getResponseBody(event.getReader()));
        });
        conv.start();
    }

Please note that our java APIs are prepared to support Java Lambda Expressions throughout your application. In order to compile the above code you might need to adjust your android studio and module settings.

drawing

If you run your application now you might face one or all of the below problems.

Missing permission to use INTERNET on the test device.

Please make sure that you have added the correct permission <uses-permission android:name="android.permission.INTERNET" /> line to your AndroidManifest.xml file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sap.myfirstproject">

<uses-permission android:name="android.permission.INTERNET" />

<application
...

Missing required dependencies

The fact that you specified HttpConversation module does not mean that all transient dependencies are compiled into the mobile application.

14:07:11.053 1976-1976/com.sap.myfirstproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sap.myfirstproject, PID: 1976
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/sap/smp/client/supportability/Supportability;
    at com.sap.smp.client.httpc.HttpConversationManager.<init>(HttpConversationManager.java:299)
    at com.sap.myfirstproject.MainActivity.onCreate(MainActivity.java:19)

Should you see similar exception you will need to analyse carefully all the dependencies in these guides for every SMP client library you used.

In our example you will need to add these additional aar modules: * SupportabilityFacade-4.0.0.aar * ClientLog-4.0.0.aar * E2ETrace-4.0.0.aar

Now your project should run properly.

7.. Start developing your mobile app.