Panchaksharappa, Varuna

Upgrade Mobile App Performance (MAP) SDK - version 20.32 and above for Android

 

This document tells you how to upgrade the MAP SDK to work with the Akamai Common Framework. The Akamai Common Framework ensures a consistent and efficient experience for mobile app developers while minimizing resource utilization, and ensuring compatibility between Akamai SDKs and end-user devices.

 

Sample App: Download

We've created a sample project that you can use to validate the setup and functionality of the SDK. You can use this sample app to compare against your legacy and make sure everything is working correctly, as outlined in the step below.
 

Prerequisites:

  • An Android app using the MAP SDK with an associated API/license key. If you are trying to integrate the MAP SDK for the first time, please check our article here on how to get started.
  • Familiarity with MAP SDK features and configurations. For more information, see our MAP SDK Configuration Guide.

 

Step 1: Support AndroidX libraries


The SDK supports API 15 and above. The target/compile SDK should be at least set to API 28 and it is also required by Google for any app updates from November 2019. Google no longer maintains support libraries up until version 28 and has made AndroidX the default support library in Android Studio. MAP SDK has migrated from Android Support libraries to androidx-packaged library artifacts. This will not only make our SDK better but also allows us to use the latest Jetpack features. If you have not migrated to AndroidX library artifacts, add the following two lines to your gradle.properties file to use MAP SDK.

android.useAndroidX=true

android.enableJetifier=true

Androidx also requires the minimum build tools version to be set at 'com.android.tools.build:gradle:3.2.0' in the root build.gradle file. The minimum gradle version should be set at gradle-4.6 in the gradle-wrapper.properties. MAP SDK has a dependency on Work Manager ('androidx.work:work-runtime:2.2.0') and the dependency is automatically pulled into your project.
 

Step 2: Adding Dependencies

If you have previously included the aar file locally in the lib folder, remove that library first. The project gradle file should have jcenter() by default.

If not, add it as shown below.

allprojects {

   repositories {

       jcenter()

   }

}

In the following steps, the column on the left shows the existing code. Replace this code with the code in the column on the right.

 

When Using Maven:

Legacy SDK

Akamai Common Framework SDK


implementation 'com.akamai.android:map-sdk:20.1.3@aar'

implementation 'com.akamai.android:aka-map:2x.xx'

 

Step 3: Initialization

Legacy SDK

Akamai Common Framework SDK

VocService vocService = VocService.createVocService(this);

<!--Note: createVocService API is deprecated and does not initialize the sdk.-->

Auto Initialization

 

Step 4: Getting an instance

Legacy SDK

Akamai Common Framework SDK

VocService vocService = VocService.createVocService(this);

<!--Note: createVocService API is deprecated.-->

AkaMap mMapInstance = AkaMap.getInstance();

 

Step 5: Third-party libraries traffic

If you’re using third-party networking libraries like OkHTTP/Retrofit, then you need to add the AkaOkHttpInterceptor wrapper if you are using Picasso then you need to add AkaPicassoDownloader to your app. If you ignore this part, you won’t be able to track traffic from those third-party libraries.

 

  • If you’re using OkHTTP, use the following. 

OkHTTP - Adding wrapper

OkHttpClient client = new OkHttpClient.Builder()

       .addInterceptor(new AkaOkHttpInterceptor())

       .build();

 

  • If you’re using Retrofit2, use the following. 

Retrofit - Adding wrapper

Retrofit retrofit = new Retrofit.Builder()

       .baseUrl(uri)

       .addConverterFactory(GsonConverterFactory.create())

       .client(AkaRetrofit2Client.getClient())

       .build();

 

  • If you’re using Picasso, use the following. 

Picasso - Adding wrapper

Picasso picasso = new Picasso.Builder(getContext())

       .downloader(new OkHttp3Downloader(AkaPicassoDownloader.getClient()))

       .build();

 

Step 6: Import statements

Android studio will usually import all the packages automatically. The packages will be changed as follows. 

Legacy SDK

Akamai Common Framework SDK

 

import com.akamai.android.sdk.VocNetworkQualityStatus;

import com.akamai.android.sdk.VocService;

<!--Note: Classes are deprecated.-->

import com.akamai.android.sdk.AkaMap;

import com.akamai.android.sdk.MapLogger;

import com.akamai.android.sdk.MapNetworkQualityStatus;

import com.akamai.android.sdk.net.AkaHttpClient;

 

Step 7: Segment subscription

This step is if you're using a Segment subscription. If the app doesn't need to preposition content in the background, then this step is optional. 

Legacy SDK

Akamai Common Framework SDK

 

vocService.updateSegmentSubscription(segmentsArray);

 

<!--Note: updateSegmentSubscription API is deprecated. vocService is the instance of VocService-->

mMapInstance.subscribeSegments(new HashSet<>(Arrays.asList(segments)));

 

Note: mMapInstance is the instance of AkaMap

 

After the above steps, your app should compile without errors and you are good to go.