Panchaksharappa, Varuna

Mobile App Performance, mPulse SDK - Cordova Integration Guide (Android)

 

Instructions for adding Mobile App Performance(MAP) / mPulse SDK to your Cordova app for Android.

Required For Setup

  • You must be an Akamai Ion customer to use this SDK. If you are not on ION and would like to know more, please reach out to us at specialist@akamai.com
  • MAP SDK License Key - Follow the steps given in our getting started guide to activate MAP SDK from the marketplace and to generate a license key.

 

Example Project

For your convenience, we've created a Sample App/project that you can use to get started and learn about using MAP SDK with Cordova.

The sample app demonstrates the features of both the MAP & MPulse SDK.

  1. Download and Unzip the sample.

  2. Use Command line/Terminal Go to the path where you have unzipped the sample.

  3. Go to path cordova_sample_application⁩ ▸ ⁨customPlugins⁩ ▸ ⁨akaIntegration⁩.

  4. Run the sample app using command “cordova emulate android”.

  5. You should see the sample app running on the emulator/device.

 

SDK Setup

1. Creating Application.

cordova create <directory> <application ID> <appName>

Eg: cordova create /ABC/Disk1/SampleCord com.akamai.sampleapp CordovaSampleApp

 

2. Adding Android to Cordova

cordova platform add android

 

3. Enabling the SDK

Create/Add akamai_sdk_init.xml to the root directory of the project

Add/Modify the licenses and segments you are using :

<?xml version="1.0" encoding="utf-8"?>
<com_akamai_sdk_init>
<com_akamai_map_license_key>Add MAP License Key</com_akamai_map_license_key>
<com_akamai_mpulse_license_key>Add Mpulse License Key</com_akamai_mpulse_license_key>
<com_akamai_map_segments>Add MAP segments</com_akamai_map_segments>
</com_akamai_sdk_init>

 

4. Modify Android platform in config.xml(in root directory of your project)

config.xml

5. Copy custom plugins from the Sample App (cordova_sample_application) to the root directory of the project.

custom plugin

 

6. Adding akaIntegration plugin to the app.

Run the below command at the root directory of the project.

cordova plugin add customPlugins/akaIntegration

 

akaIntegration will be added to the plugins folder.

 

7. If you later modify the plugin you will probably need to re-add it.

cordova plugin rm akaIntegration
cordova plugin add customPlugins/akaIntegration

8. Installing Advanced Http Cordova plugin- (for Android)

 

You will also need to install cordova-plugin-advanced-http (for Android) and make API calls using this plugin so that API calls are intercepted via MAP and mPulse SDK. You could see sample GET and POST requests usage in the link.

  • We also need to make changes to the plugin as there is a bug where network calls will be intercepted for the very first time and subsequent calls won’t have Akamai headers added to the API calls.
     
  • Go to the class CordovaHttpBase, in prepare request method HttpRequest.setConnectionFactory(new OkConnectionFactory()); This causes issues when working with MAP SDK.
     
  • Replace with HttpRequest.setConnectionFactory(null);

 

9. Prepare and build the app

cordova prepare android
cordova build android

 

Adding Firebase - (Only for MAP SDK)

 

If the app does not have a need for prepositioning content in the background then this step is optional. MAP SDK uses Firebase Cloud notifications to sync configuration and content to be prepositioned in the background.

Follow the steps given the Integration Guide.

Add google-services.json to the root directory of the project.

Modify package.json to add Firebase in the root directory of the project. 

firebase-1firebase-2

 

Prepare and build the app

cordova prepare android
cordova build android

 

MAP & mPulse SDK Configuration

 

AkaIntegration.java is the main file which has methods to call the native functions of both MAP & mPulse SDK.

Location of the file in the cordova_sample_application :

cordova_sample_application⁩ ▸ ⁨customPlugins⁩ ▸ ⁨akaIntegration⁩ ▸ ⁨src⁩ ▸ ⁨android⁩ ▸ ⁨com⁩ ▸ ⁨akamai⁩ ▸ ⁨android⁩ ▸ AkaIntegration.java

 

Troubleshooting

If you run into any issues, see our general Troubleshooting section.

See our Cordova Example Project for more help.

 

Debug logs

You need to set the log level to debug to see the debug logs associated with map-sdk.

Logger.setLevel(Logger.LEVEL.DEBUG);

 

Success

  • SDK discovered

D/AkaSDKLogger: Initialized com.akamai.android.aka_common, version D/AkaSDKLogger: ComponentContainer: Initialized com.akamai.android.sdk, 

D/AkaSDKLogger: AkaInitProvider: AkaCommon initialization successful through CP.

  • Sync started

D/AkaSDKLogger: AkaBackgroundService: com.akamai.anaina.FULL_SYNC

  • Interception started:

D/AkaSDKLogger: External Url Stream handler to handle http/s stream:: com.akamai.android.sdk.AkaMap

  • Config requested

D/AkaSDKLogger: Request headers for Url: https://configuration-map.akamai.com/config?id=

  • Config received

D/AkaSDKLogger: d: Capabilities: {"license_hash":

  • Prepositioning triggered 

D/AkaSDKLogger: AnaWebContentDownloader: WebContent: Queued for download  11, policy  0

  • Analytics success

D/AkaSDKLogger: AkaWebAnalyticsHandler: sendWebAccAnalytics: 200

  • Push notification

D/AkaSDKLogger: PushMessagingService: Fcm rcv Prepare sync

Failures

  • Wrong library

ERROR: Failed to resolve: com.akamai.android:aka-map:21.*.*

Solution: Integration step is wrong. Add jcenter() in the project build.gradle

  • Missing config file reference

E/AkaSDKLogger: Couldn't find resource file for meta-data key com.akamai.android.sdk!

Solution: Check akamai_sdk_init.xml file is in res/xml and reference it  in the AndroidManifest.xml