Android Project Setup

Android SDK Integration Steps

1. Dependencies

Recent changes: 

  • New! (2/3/2020) Our AppLovin and MoPub adapters now support Banner 320×50
  • New! (2/3/2020) Performance improvements to the core sdk
  • Updated our Criteo adapter with bug fix; still using their 3.2.2 sdk
  • Now supports Banner 300×250, 320×50, 728×90 (tablet)
  • Added new floor feature.  VPAID support, Auto pre-fetch.
  • Added Amazon Mobile Ads (vers. 5) to our mediation stack with floor support!
  • Added segments and A/B testing functionality.  New methods:
  • Chocolate.setCustomSegmentProperty(Context context, String key, String value)
  • Chocolate.setTotalInAppPurchases(Context context, float totalInAppPurchases)

 

Chocolate supports mediation of the following ad networks:
Demand Source Name SDK Version SDK Size/Footprint
Chocolate Core 2.8.14 300kb
AdColony 4.1.1 370kb
Amazon Mobile Ads 5.+ 580kb
AppLovin 9.8.4 300kb
Criteo 3.2.2 200kb
Facebook 4.99.3 680kb
AdMob and Google IMA (pre-roll)
  • Google IMA 3.11.2
  • Google play-services-ads 17.2.0
300kb
Mopub 5.8.0 400kb
TapJoy 12.2.1 680kb
UnityAds 3.4.0 470kb
Vungle 6.4.11 280kb
Yahoo/Flurry 10.0.0 400kb
Total Added Footprint for all above partners including the Google Play Services Ads and Android Support Libraries: 4.1mb after building a final release APK. There are some common shared code in the above partners.
Note: Google Play Services Ads and Android Support Libraries would be required for any ads mediation platform and are at least 1mb in size.

 

2. Add dependencies and other settings to your app ‘build.gradle’
android {

    defaultConfig {

        // ... existing settings ...

        multiDexEnabled true
    }

    compileOptions { 

        sourceCompatibility JavaVersion.VERSION_1_8 
        targetCompatibility JavaVersion.VERSION_1_8 

    }

}

repositories {
    maven { url 'https://jitpack.io' }
    maven { url "https://dl.bintray.com/vdopiacorp/sdk" }
    maven { url 'https://tapjoy.bintray.com/maven' }
    // If you're using a version of Gradle greater than or equal to 4.1, you must use:
    google()

    // If you're using a version of Gradle lower than 4.1, you must use:
    maven { url 'https://maven.google.com' }

    flatDir {
        dirs 'libs'
    }
}

Within the dependencies section, merge in the following block:

implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.vdopia.ads.lw:coresdk:2.8.14'
implementation 'com.vdopia.ads.lw:adcolony-adapter:4.1.1'
implementation 'com.vdopia.ads.lw:amazon-adapter:5.9.3.a'
implementation 'com.vdopia.ads.lw:applovin-adapter:9.8.4.a'
implementation 'com.applovin:applovin-sdk:9.8.4'
implementation 'com.vdopia.ads.lw:criteo-adapter:3.2.6.a'
implementation 'com.vdopia.ads.lw:google-adapter:17.2.0'
implementation 'com.google.android.gms:play-services-ads:17.2.0' //11.0.4 minimum is required, 16.0.0 or newer recommended! 
implementation('com.google.android.ads.consent:consent-library:1.0.7') {
   exclude group: 'com.android.support'
   exclude group: 'com.google.code.gson', module: 'gson'
}

implementation 'com.vdopia.ads.lw:facebook-adapter:1.0.6'
implementation('com.facebook.android:audience-network-sdk:4.99.3') {
   exclude group: 'com.google.android.exoplayer'
   exclude group: 'com.google.android.gms'
   exclude group: 'com.android.support'
}

implementation 'com.vdopia.ads.lw:tapjoy-adapter:12.2.1.a'
implementation 'com.tapjoy:tapjoy-android-sdk:12.2.1@aar'
implementation 'com.vdopia.ads.lw:unity-adapter:3.4.0' 
implementation 'com.vdopia.ads.lw:vungle-adapter:6.4.11'
implementation('com.github.vungle:vungle-android-sdk:6.4.11') {
   exclude group: 'com.android.support'
}
implementation 'com.vdopia.ads.lw:mopub-adapter:5.8.0.a'
implementation('com.mopub:mopub-sdk:5.8.0@aar') {
   transitive = true
   exclude group: 'com.android.support'
}
//Note: if you are using Pre-roll, un-comment the following line:
//implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.11.2'

//You do not have to use support library version 28.0.0, however, whichever version you do use
//must be the same throughout this gradle file.  This does not apply to multidex.
//Do not use '+' wildcards in the android support library version.
implementation "com.android.support:support-annotations:28.0.0"
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support:support-v4:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"
implementation 'com.android.support:multidex:1.0.3'

 

PROGUARD: If you use proguard, then copy the contents of our proguard-rules.pro and append to your proguard file.

 

3. Modify your AndroidManifest.xml

Make sure tools is added to the manifest tag (com.mypackage is just an example):

<manifest package="com.mypackage"
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools">

<application>

   <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

   <!-- If using Google Ads 17 or higher, we must include: -->
   <!-- Use this value until Chocolate provides the official one. -->
   <meta-data tools:replace="android:value"
              android:name="com.google.android.gms.ads.APPLICATION_ID"
              android:value="ca-app-pub-3940256099942544~3347511713"/>  
</application>

 

Declare the following permissions outside the application tag.

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

<!-- NOTE: We do NOT require the following permissions! -->
<!-- So, we are removing them below.  Unless your application needs them. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" tools:node="remove" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" /> 
<uses-permission android:name="android.permission.SEND_SMS" tools:node="remove" /> 
<uses-permission android:name="android.permission.CALL_PHONE" tools:node="remove" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /> 
<uses-permission android:name="android.permission.READ_CALENDAR" tools:node="remove" /> 
<uses-permission android:name="android.permission.WRITE_CALENDAR" tools:node="remove" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" tools:node="remove" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" />


 

4. GDPR Support

The Chocolate Ads SDK is GDPR-ready and supports the IAB Standards for GDPR compliance.

Use the following simple api in conjunction with your existing Consent Management Provider.  If you do not have a CMP solution, that’s ok, too!  Our mediation sdk will detect if the user is in the EU and automatically apply GDPR actions to the ad request.  So, by default, you do not have to do any extra work to use our sdk in a GDPR-compliant fashion.

/* Save consent string */
Chocolate.setGDPR(Context context, boolean isSubjectToGDPR, String iabConsentString);

/* Indicates if the device is subject to GDPR by checking device locale.  No network required! */
Chocolate.isSubjectToGDPR(Context context);

 

5. Initializing Chocolate

In native Android apps, please initialize the Chocolate Ads SDK:

In your main Activity, call Chocolate.initNote: please use the Activity context as some of our mediation partners sdk require Activity.  Do not pass the application context.

public class MyActivity extends AppCompatActivity {

    private static final String API_KEY = "XqjhRR";   //Feel free to use as a test key until you get your own!
    private LVDOAdRequest adRequest;

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

        adRequest = new LVDOAdRequest(this);

        //Be sure to set these values before going live.
        adRequest.setAppStoreUrl("https://play.google.com/store/apps/details?id=com.democompany.android");
        adRequest.setRequester("Chocolate Demo Company");
        adRequest.setAppDomain("http://democompany.com/test");
        adRequest.setAppName("Chocolate Demo");
        adRequest.setCategory("IAB2");
        adRequest.setPublisherDomain("http://democompany.com/");

        Chocolate.init(this, API_KEY, adRequest, new InitCallback() {
            @Override
            public void onSuccess() {
                //Do not fetch ad here; we will do it for you automatically.
            }

            @Override
            public void onError(String initError) {

            }
        });
    }   

}

 

Note on Background Fetch

Chocolate Android SDK runs some background fetch (using JobIntentService) in an effort to make sure that we will have ads available by the time user is ready to see an ad.

 

Now we are ready to implement the ad units (easy).  If you have already implemented the ad units, then you may build and run, manage in Android Studio.