2.7.4 Android SDK Integration Guide

Integrate SDK 

You can use our demo app as a reference project.

Starting from SDK 2.7.2 we moved to AndroidX from support-library

Minimum requirements:

Android API level 16 (Android OS 4.1), but you can integrate the Appodeal SDK in apps with lower minSdkVersion. On the devices that don't support Android 4.1+, our SDK will just be disabled

Mediation A/B testing

If you want to compare Appodeal's performance to another mediation, please follow this Mediation A/B testing guide

1. Import SDK

Preparing your Gradle build for Android 11

Android 11 changes how apps can query and interact with other apps that the user has installed on a device. For that reason make sure you're using gradle version that matches one of listed here.

Add the Appodeal maven repository

Apps can import the Appodeal SDK with a Gradle dependency that points to the Appodeal's Maven repository. In order to use that repository, you need to reference it in the app's project-level build.gradle file. Open yours and look for an allprojects section:

Example project-level build.gradle (excerpt)

allprojects {
    repositories {
        // ... other project repositories
        maven {
            url "https://artifactory.appodeal.com/appodeal"
        }
    }
}

Add maven dependencies

Next, open the app-level build.gradle file for your app, and look for the dependencies section:

Example app-level build.gradle (excerpt)

dependencies {
    // ... other project dependencies

    implementation 'com.appodeal.ads:sdk:2.7.4.+'
}

Some networks are using Java 8 features (e.g - Smaato), so please make sure your Android Gradle plugin version greater or equal 3.2.0 and add next compile options to your app-level build.gradle:

Example app-level build.gradle (excerpt)

android {
    // ... other options
    
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Move to AndroidX from support-library

Next, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle.properties file:

Example project-level gradle.properties (excerpt)

android.useAndroidX=true
android.enableJetifier=true

Configure AndroidManifest.xml

  • Add the required permissions to your AndroidManifest.xml file under the manifest tag:

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

  • Add the optional permissions to your AndroidManifest.xml file under the manifest tag to improve ad targeting:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!--optional-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!--optional-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!--optional-->
<uses-permission android:name="android.permission.VIBRATE" /> <!--optional-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!--partially optional-->

Pay attention, that some permissions marked as partially optional as they are highly recommended for some networks (permission absence may cause crashes or ad fill problems):

  • For StartApp adapter on targetSdkVersion >= 29:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!--partially optional-->

Some networks and 3rd party dependencies (related to network dependencies) can include their own permissions to the manifest. If you want to force remove such permissions you can refer to this guide

Once that's done, save the file and perform the Gradle sync.

2. Network security configuration

Android 9.0 (API 28) blocks cleartext (non-HTTPS) traffic by default, which can prevent ads from serving correctly. Read more on this here.

1. Add the Network Security Configuration file to your AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest>
    <application 
		...
        android:networkSecurityConfig="@xml/network_security_config">
    </application>
</manifest>
2. In your network_security_config.xml file, add base-config that sets cleartextTrafficPermitted to true:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>
</network-security-config>

3. Add meta-data (if you use AdMob adapter)

Make sure to add Privacy Policy to your app on Google Play that links to Appodeal's Privacy Policy to avoid violating Google Play Developer Distribution Agreement.

All necessary dependencies are already included in the AdMob adapter.

If you use Play Services version 17 and higher, add <meta-data> tag to the AndroidManifest file. 

<manifest>
    <application>
        <!-- Add your AdMob App ID -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="[ADMOB_APP_ID]"/>
    </application>
</manifest>

4. Initialize SDK

To initialize SDK add the line below to onCreate method of your main activity:

1. Starting from version 2.7.1 you can use the Stack Consent Manager SDK to pass the user's consent:

public class MainActivity extends AppCompatActivity {
    ...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       	// NOTE: getConsent() - should be called after requesting user consent
       	Consent consent = ConsentManager.getInstance(this).getConsent();
       	Appodeal.initialize(this, "YOUR_APPODEAL_APP_KEY", adTypes, consent);
    }
    ...
}
consent is Consent object from Stack Consent Manager. 
Read our implementation Stack Consent Manager guide here.

2. If you don't want to use the Stack Content Manager SDK, you can use the old version to pass the user's consent:

public class MainActivity extends AppCompatActivity {
    ...
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Appodeal.initialize(this, "YOUR_APPODEAL_APP_KEY", adTypes, consentValue);
    }
    ...
}

consentValue is boolean, with 'false' meaning that the user declines to give the consent.
Read our guide on collecting consent here.
Make sure to replace "YOUR_APPODEAL_APP_KEY" with the actual app key.

Use the type codes below to set the preferred ad format:

  • Appodeal.INTERSTITIAL for interstitial;
  • Appodeal.REWARDED_VIDEO for rewarded videos;
  • Appodeal.NON_SKIPPABLE_VIDEO for non-skippable videos;
  • Appodeal.NATIVE for native ads;
  • Appodeal.BANNER for banners;
  • Appodeal.MREC for 300*250 banners.

Please note:

Ad types can be combined using "|" operator. For example, Appodeal.INTERSTITIAL | Appodeal.REWARDED_VIDEO.

Appodeal.NON_SKIPPABLE_VIDEO - the alias of Appodeal.REWARDED_VIDEO. Both of them shouldn't be used together.

If you are not sure, which ad formats would suit you the best, check out our FAQ.

Data Protection Regulation (GDPR, CCPA)

Publishers need to update their apps to collect the user consent prior to initializing our SDK (Read our guide on collecting consent here).

1. Starting from version 2.7.1 you can use the Stack Consent Manager SDK to process and pass the user's consent:

Read our implementation Stack Consent Manager guide here.

Publishers need to pass the Consent result object from Stack Consent Manager SDK to the Appodeal.initialize() method of our SDK.

// NOTE: getConsent() - should be called after requesting user consent
Consent consent = ConsentManager.getInstance(this).getConsent();
Appodeal.initialize(this, "YOUR_APPODEAL_APP_KEY", adTypes, consent);
2. If you don't want to use the Stack Content Manager SDK, you can use the old version to pass the user's consent:

Publishers need to pass the boolean consent flag(with 'false' meaning that the user declined to give the consent) to the Appodeal.initialize() method of our SDK.

Appodeal.initialize(this, "YOUR_APPODEAL_APP_KEY", adTypes, consentValue);

It’s done!

You are ready to use Appodeal and implement ad types. If you have any questions, check out our FAQ or contact the support team.

Third-Party SDKs

Integration

By default we include all required third-party networks without any additional dependencies. If you would like to add or remove any of them, you can use our Mediation Wizard tool: