EMMA Android SDK Integration with UNITY

To integrate EMMA in your UNITY project please, follow the next steps:

Step 1. Plugin TrackEvent

  1. The first step is to create a plugin in Android Studio to use the function trackEvent. To do this, the first you thing you need to do is to edit gradle like this to import the needed libraries and set the project as library and not like App. Something like this:

  2. After this, review the manifest to be like this:

  3. Create a class singelton with the function trackEvent like this:

  4. Finally compile to generate the .jar file.



Step 2. Folders and manifest.

  1. Now, inside UNITY you need to create the next folders structure: /Plugins/Android (only if not exists) and import the plugin created in step 1.

  2. Create a manifest with the next code:

    <?xml version="1.0" encoding="utf-8"?>

    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.package" android:versionName="1.01" android:versionCode="1" android:installLocation="preferExternal">

    <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />

    <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">

    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">

          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
          <category android:name="android.intent.category.LEANBACK_LAUNCHER" />

       <meta-data android:name="unityplayer.UnityActivity" android:value="true" />


    service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />

    <receiver android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver" android:exported="true">

          <action android:name="com.android.vending.INSTALL_REFERRER" />


    <!-- Esto es de emma-->

    <receiver android:name="com.emma.android.eMMaReferralReceiver" android:exported="true">

    action android:name="com.android.vending.INSTALL_REFERRER"/>


    <!-- Fin esto es de emma-->


    <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="23" />
    <uses-feature android:glEsVersion="0x00020000" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-feature android:name="android.hardware.touchscreen" android:required="false" /><uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />

    !-- Esto es de emma-->

    <permission android:name="com.my.package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="com.my.package.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /><uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <!-- Fin esto es de emma-->


  3. Create the next script in UNITY to call trackevents of the plugin created in step 1.

    using UnityEngine;
    using System.Collections;

    public class eMMaTracker : MonoBehaviour {

       private AndroidJavaObject aplication;
       private AndroidJavaObject activityContext = null;
       private AndroidJavaObject emmaControllerJava = null;

       public static eMMaTracker instance = null;

       void Awake() {
          if (instance == null) instance = this;
          else if (instance != this) Destroy(gameObject);

       // Use this for initialization

       void Start() {
       using (AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
             activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
             aplication = activityContext.Call<AndroidJavaObject>("getApplication");
          using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.bemobile.emmaunity.EmmaController"))
             if (pluginClass != null) {
                emmaControllerJava = pluginClass.CallStatic<AndroidJavaObject>("instance");
          GameMuted ();


  4. This function need to be called in other UNITY's scripts to track an event.

    private void trackEvent(string eMMaevent) {

       emmaControllerJava.Call("trackEvent", activityContext);

  5. Add the script inside a gameobject for the scene where you are working to allow other scripts access to trackevent function.

  6. After the scritps call the trackevent function, you need to export the project as a Google Android Project like this:

Paso 3. APK Generation

  1. Delet the support and cardview from settings.gradle of the project (if they exist)

  2. The build.gradle will be like this:

  3. Add this to the activity UnityPlayerActivity:

  1. Delete the line android:debuggable="false"  from the manifest
  1. Generate the .apk file

  2. Done! Now you can use EMMA in your project!
Have more questions? Submit a request


Article is closed for comments.