Panchaksharappa, Varuna

Upgrade mPulse SDK - version 20.32 and above for Android

 

Prerequisites:

  • An Android app using the mPulse SDK with an associated API/license key. 

  • Familiarity with mPulse features and configurations available with the SDK. For more information on that, see the Getting Started Guide.

 

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.

 

Upgrade to mPulse SDK v20.32 and above

Step 1: Support AndroidX libraries

The SDK supports API 15 and above.​ ​The target/compile SDK should be atleast set to API 28 and it is also ​required by Google for any app updates from Novemb​er 2019​. Google no longer maintains support libraries up until version 28 and has made androidX the default support library in Android Studio. ​mPulse 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 mPulse SDK.

android.useAndroidX=true

android.enableJetifier=true

AndroidX also requires minimum build tools version​ to be set '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​.

 

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()

   }

}

 

Note: For all the steps following, the column on the left shows the existing code. Replace this code with the code in the column on the right.  

 

Legacy SDK

mPulse SDK with Common Framework

apply plugin: "com.soasta.mpulse.android"

implementation 'com.soasta.mpulse:mpulse-android:2.6.1'

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

 

Step 3: Edit the app-level build.gradle to remove the plugin;

Legacy SDK

mPulse SDK with Akamai Common Framework

apply plugin: "com.soasta.mpulse.android"

 

Note: Remove the plugin

None

 

Step 4: Edit the project-level build.gradle to remove the classpath

Legacy SDK

mPulse SDK with Common Framework

classpath 'com.soasta.mpulse:mpulse-android-gradle-plugin:2.6.1'

None

Note: At this point you’ll see compile errors in your project. This is expected behavior because you’re no longer using the soasta package, com.soasta.mpulse.

 

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

After doing step 1, step 2 and step 3, you’ll see compile errors in your project. This is expected behavior because you’re no longer using the soasta package, com.soasta.mpulse. 

All com.soasta.* is renamed to com.akamai.*

Legacy SDK

mPulse SDK with Akamai Common Framework

import com.soasta.mpulse.android.MPulse;

import com.soasta.mpulse.core.MPLog;

 

import com.soasta.mpulse.android.beacons.MPApiNetworkRequestBeacon;

import com.soasta.mpulse.android.filter.MPUrlFilter;

import com.soasta.mpulse.core.beacons.MPBeacon;

import com.soasta.mpulse.core.filter.MPFilter;

import com.soasta.mpulse.core.filter.MPFilterResult;

 

import com.soasta.mpulse.core.MPulseMetricTimerOptions;

import com.soasta.mpulse.core.config.MPulseSettings;

import com.akamai.mpulse.android.MPulse;

import com.akamai.mpulse.core.MPLog;

 

import com.akamai.mpulse.android.beacons.MPApiNetworkRequestBeacon;

import com.akamai.mpulse.android.filter.MPUrlFilter;

import com.akamai.mpulse.core.beacons.MPBeacon;

import com.akamai.mpulse.core.filter.MPFilter;

import com.akamai.mpulse.core.filter.MPFilterResult;

 

import com.akamai.mpulse.core.MPulseMetricTimerOptions;

import com.akamai.mpulse.core.config.MPulseSettings;

 

Step 6: Third-party libraries traffic

If you’re using third-party networking libraries like OkHTTP/Retrofit, then you need to add the AkaOkHttpAppInterceptor 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 AkaOkHttpAppInterceptor())

       .build();

 

  • If you’re using Retrofit, 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 mPicasso = new Picasso.Builder(getApplicationContext())

           .downloader(new AkaPicassoDownloader(getApplicationContext()))

           .build();

 Picasso.setSingletonInstance(mPicasso);

 

Optional

Step 7: Initialization

Initialization has been improved and is auto-initialized. Remove usage of MPulse.initializeWithAPIKey API.

Legacy SDK

mPulse SDK with Akamai Common Framework

public static final String MPULSE_API_KEY = "28L3-XCVBGH-HGJ-UN5";

 

MPulse.initializeWithAPIKey(MPULSE_API_KEY, getApplicationContext());

 

Auto Initialization

 

Step 8: Adding API KEY

 

Next, you need to create a new file and add the API Key there. 

At the project level, in the res folder, create a folder called xml

In the xml folder, create a file named akamai_sdk_init.xml, as mentioned below. Note that your license key is unique, the one below is just an example. 

<?xml version="1.0" encoding="utf-8"?>
<com_akamai_sdk_init>
<!-- Add you API KEY -->
<com_akamai_mpulse_license_key>28L3-XXXBGH-HGJ-UN5</com_akamai_mpulse_license_key>
</com_akamai_sdk_init>

     

To reference the API key, you need to add below meta-data In AndroidManifest.xml.

<application...>
  <activity...   </activity>
  <meta-data
      android:name="com.akamai.android.sdk"
      android:resource="@xml/akamai_sdk_init" />

</application>

Save and close the file. 
 

Step 9: To enable Debug Logging, change the following lines as shown. 

 

Legacy SDK

mPulse SDK with Akamai Common Framework

import com.soasta.mpulse.core.MPLog;

MPLog.setDebug(true);

MPLog.setTrace(true);

 

Note: MPLog is deprecated.

import com.akamai.android.sdk.Logger;

 

Logger.setLevel(Logger.LEVEL.DEBUG);

As a final step, compile your app. It should compile without errors, and you’re good to go.