Android Integration

MAS supports Android version 4.4.+ (Android API level: 19+) and above

1. Open Your Project-Level build.gradle  and Add the repositories

mavenCentral()
maven { url "https://artifact.bytedance.com/repository/pangle" }
maven { url "https://android-sdk.is.com" }
maven { url "https://sdk.tapjoy.com/" }

Use the code bellow if you need to comply with the Google Family Policy.

mavenCentral()
maven { url "https://android-sdk.is.com" }
maven { url "https://sdk.tapjoy.com/" }

Note : If you create your project under Android Studio Arctic Fox, the repositories should be added to settings.gradle

2. Open Your App-Level build.gradle and Add the Relevant Code

2.1 If you’re only targeting children under 13 years of age, please add this Gradle dependency:

implementation 'com.yodo1.mas:google:4.3.1'

2.2 If you’re targeting all ages, or 13+, use this Gradle dependency:

implementation 'com.yodo1.mas:full:4.3.1'


2.3 Add the compileOptions property to the Android section:

android {
	compileOptions {
		sourceCompatibility = 1.8
		targetCompatibility = 1.8
	} 
}


3. Add the MultiDex Property to the defaultConfig Section

defaultConfig {
    ...
    multiDexEnabled true
    ...
}


4. Support AndroidX

Add this content to the gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true


5. Add AdMob App ID

  • Add your AdMob App ID to your app’s AndroidManifest.xml file by including the <meta-data> tag.
  • Your AdMob App ID can be found under the “details” of your app on MAS Dashboard.
  • Please replace android:value with your own AdMob App ID:
<manifest>
	<application>
	<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
	<meta-data
		android:name="com.google.android.gms.ads.APPLICATION_ID"
		android:value="YOUR_ADMOB_APP_ID"/>
	</application>
</manifest>


6. AdMob Android Manifest Merging Errors

The AdMob SDK uses the <queries> element in its bundled Android Manifest files. If you’re using an incompatible version of the Android Gradle plugin, you will encounter these build errors.

com.android.builder.internal.aapt.v2.Aapt2Exception: Android resource linking failed
error: unexpected element <queries> found in <manifest>.

You will then need to upgrade to any of the following versions of the Android Gradle plugin:

Current Android Gradle Plugin VersionSupported Android Gradle Plugin Version
4.1.*Already Supported
4.0.*4.0.1
3.6.*3.6.4
3.5.*3.5.4
3.4.*3.4.3
3.3.*3.3.3


7. Android P Adaptation

For compatibility with Android P (API level 28), please follow these steps:

  • Create an XML folder in your resources folder
  • Create an XML file named network_security_config.xml in the XML folder. In the res/xml/network_security_config.xml file, please add these lines:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
	...
	<base-config cleartextTrafficPermitted="true" />
	<domain-config cleartextTrafficPermitted="true">
	<domain includeSubdomains="true">127.0.0.1</domain>
	</domain-config>
	...
</network-security-config>  
  • Next, add these lines to the application element in the AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
	<application android:networkSecurityConfig="@xml/network_security_config"
	... >
	...
	</application>
</manifest>


8. Comply With Legal Frameworks

Please comply with all legal frameworks that apply to your game and its users. You can find references to major legal frameworks and details about how to comply with them while using MAS through these links:

If you’re using MAS 4.3.0+, you can enable the built-in privacy compliance dialog in the SDK to collect user information:

  1. Enable (Before the initialization)

For Java

Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).build();
Yodo1Mas.getInstance().setAdBuildConfig(config);

For Kotlin

val config = Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).build()
Yodo1Mas.getInstance().setAdBuildConfig(config)
  1. Custom user agreement (optional)

For Java

Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).userAgreementUrl("Your user agreement url").build();
Yodo1Mas.getInstance().setAdBuildConfig(config);

For Kotlin

val config = Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).userAgreementUrl("Your user agreement url").build()
Yodo1Mas.getInstance().setAdBuildConfig(config)
  1. Custom privacy policy (optional)

For Java

Yodo1MasAdBuildConfig config = new Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).privacyPolicyUrl("Your privacy policy url").build();
Yodo1Mas.getInstance().setAdBuildConfig(config);

For Kotlin

val config = Yodo1MasAdBuildConfig.Builder().enableUserPrivacyDialog(true).privacyPolicyUrl("Your privacy policy url").build()
Yodo1Mas.getInstance().setAdBuildConfig(config)

IMPORTANT! Failure to comply with these frameworks can lead to Google Play Store rejecting your game, as well as a negative impact of your game’s monetization.

9. Initialize the SDK

Initialize the SDK by using the onCreate method of Activity.

For Java

protected void onCreate() {
    super.onCreate();
    Yodo1Mas.getInstance().init(this, "Your Appkey", new Yodo1Mas.InitListener() {
      @Override
      public void onMasInitSuccessful() {
    }

    @Override
    public void onMasInitFailed(@NonNull Yodo1MasError error) {
    }
    });
}

For Kotlin

Yodo1Mas.getInstance().init(this, "YourAppKey", object : Yodo1Mas.InitListener {
  override fun onMasInitSuccessful() {    
    Toast.makeText(this@MainActivity, "[Yodo1 Mas] Successful initialization", Toast.LENGTH_SHORT).show()
  } 
  override fun onMasInitFailed(error: Yodo1MasError) {
    Toast.makeText(this@MainActivity, error.message, Toast.LENGTH_SHORT).show()  
  }
})
  • Note: Please use your Appkey for initialization, not the Admob App ID. Your Appkey can be found under the “details” of your app on MAS Dashboard.

10. ProGuard

If you’re using ProGuard with the MAS SDK, add the following code to your ProGuard file (Android Studio: proguard-rules.pro or Eclipse: proguard-project.txt):

-ignorewarnings
-keeppackagenames com.yodo1.**
-keep class com.yodo1.** { *; }
-keep class com.yodo1.mas.** { *; }
-keep class com.yodo1.mas.ads.** {*;}
-keep class com.yodo1.mas.error.** { *; }
-keep class com.yodo1.mas.event.** { *; }
-keep public class * extends com.yodo1.mas.mediation.Yodo1MasAdapterBase -keep class com.google.ads.** { *; } -keepclassmembers class com.ironsource.sdk.controller.IronSourceWebView$JSInterface { public *; } -keepclassmembers class * implements android.os.Parcelable { public static final android.os.Parcelable$Creator *; } -keep public class com.google.android.gms.ads.** { public *; } -keep class com.ironsource.adapters.** { *; } -dontwarn com.ironsource.mediationsdk.** -dontwarn com.ironsource.adapters.** -dontwarn com.moat.** -keep class com.moat.** { public protected private *; } -keepattributes SourceFile,LineNumberTable -keepattributes JavascriptInterface -keep class android.webkit.JavascriptInterface { *; } -keep class com.unity3d.ads.** { *; } -keep class com.unity3d.services.** { *; } -dontwarn com.google.ar.core.** -dontwarn com.unity3d.services.** -dontwarn com.ironsource.adapters.unityads.** -keepattributes Signature,InnerClasses,Exceptions,Annotation -keep public class com.applovin.sdk.AppLovinSdk{ *; } -keep public class com.applovin.sdk.AppLovin* { public protected *; } -keep public class com.applovin.nativeAds.AppLovin* { public protected *; } -keep public class com.applovin.adview.* { public protected *; } -keep public class com.applovin.mediation.* { public protected *; } -keep public class com.applovin.mediation.ads.* { public protected *; } -keep public class com.applovin.impl.*.AppLovin { public protected *; } -keep public class com.applovin.impl.**.*Impl { public protected *; } -keepclassmembers class com.applovin.sdk.AppLovinSdkSettings { private java.util.Map localSettings; } -keep class com.applovin.mediation.adapters.** { *; } -keep class com.applovin.mediation.adapter.**{ *; } -keep class com.chartboost.** { *; } -dontwarn com.facebook.ads.internal.** -keeppackagenames com.facebook.* -keep public class com.facebook.ads.** {public protected *;} -keep class com.tapjoy.** { *;} -keep class com.moat.** { *;} -keepattributes JavascriptInterface -keepattributes *Annotation* -keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); } -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; } -keepnames @com.google.android.gms.common.annotation.KeepName class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; } -keepnames class * implements android.os.Parcelable { public static final ** CREATOR; } -keep class com.google.android.gms.ads.identifier.** { *;} -dontwarn com.tapjoy.** -keep class com.vungle.warren.** { *;} -dontwarn com.vungle.warren.error.VungleError$ErrorCode -keep class com.moat.** { *;} -dontwarn com.moat.** -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement -dontwarn okio.** -dontwarn retrofit2.Platform$Java8 -keepattributes Signature -keepattributes *Annotation* -dontwarn sun.misc.** -keep class com.google.gson.examples.android.model.** { *;} -keep class * implements com.google.gson.TypeAdapterFactory -keep class * implements com.google.gson.JsonSerializer -keep class * implements com.google.gson.JsonDeserializer -keep class com.google.android.gms.internal.** { *;} -dontwarn com.google.android.gms.ads.identifier.** -keepattributes SourceFile,LineNumberTable -keep class com.my.target.** {*;} -keep class com.yandex.mobile.ads.** {*;} -dontwarn com.yandex.mobile.ads.** -keepattributes *Annotation* -keep public class com.bytedance.sdk.openadsdk.*{ public *;} -dontwarn com.tencent.bugly.** -keep public class com.tencent.bugly.**{*;} -dontwarn com.sensorsdata.analytics.android.** -keep class com.sensorsdata.analytics.android.** { *; } -keep class com.yodo1.sensor.** { *; } -keep class **.R$* { <fields>; } -keep public class * extends android.content.ContentProvider -keepnames class * extends android.view.View -keep class * extends android.app.Fragment { public void setUserVisibleHint(boolean); public void onHiddenChanged(boolean); public void onResume(); public void onPause(); } -keep class android.support.v4.app.Fragment { public void setUserVisibleHint(boolean); public void onHiddenChanged(boolean); public void onResume(); public void onPause(); } -keep class * extends android.support.v4.app.Fragment { public void setUserVisibleHint(boolean); public void onHiddenChanged(boolean); public void onResume(); public void onPause(); } -dontwarn org.json.** -keep class org.json.**{*;} -keep public class com.bytedance.sdk.openadsdk.*{ public *; } -keepattributes SourceFile,LineNumberTable -keep class com.inmobi.** { *; } -keep public class com.google.android.gms.** -dontwarn com.google.android.gms.** -dontwarn com.squareup.picasso.** -keep class com.google.android.gms.ads.identifier.AdvertisingIdClient{ public *; } -keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info{ public *; } # skip the Picasso library classes -keep class com.squareup.picasso.** {*;} -dontwarn com.squareup.okhttp.** # skip Moat classes -keep class com.moat.** {*;} -dontwarn com.moat.** # skip IAB classes -keep class com.iab.** {*;} -dontwarn com.iab.** -keep class com.umeng.** {*;} -keep class com.uc.** {*;} -keepclassmembers class * { public <init> (org.json.JSONObject); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class com.zui.** {*;} -keep class com.miui.** {*;} -keep class com.heytap.** {*;} -keep class a.** {*;} -keep class com.vivo.** {*;} -keep class com.uc.crashsdk.** { *; } -keep interface com.uc.crashsdk.** { *; }


11. AppLovin fix

Add this content to the gradle.properties file:

android.enableDexingArtifactTransform=false

For next step please test your integration.

Updated on September 24, 2021

Was this article helpful?

Related Articles