Unity Integration

Prerequisites

  1. MAS supports Unity LTS versions from 2017 and above
  2. To deploy to Android, you need to target API 19+
  3. To deploy to iOS, you need to use Xcode 12
  4. To build on iOS, you need to be running Cocoapods
  5. Please make sure to check the Unity Samples to aid your integration
  6. Please complete this step for Android builds

1. Download the Correct Unity Plugin

MAS provides 2 versions of the Unity plugin, and you need to select one depending on your game:

  • If your game is not part of the “Designed for Families Program”, please use the Standard MAS Plugin.
  • If your game is a part of Google Play’s “Designed for Families” program, you will need to use the Designed For Families plugin in order to comply with the program’s requirements.

Note: If you are using Unity 2017, please make sure to check the Custom Gradle Template through the following steps:

File -> Build Settings -> Player Settings -> Publishing Settings -> Check as illustrated bellow

Note: To build for iOS, you need to remove Facebook SDK and make sure to untick these settings in External Dependency Manger -> iOS Resolver -> Settings:

2. Integrate the SDK Into Your Project

Open your Unity project and import the Unity package. Double click the compressed package icon. The files will auto-populate as illustrated below.

Important! The MAS Unity Plugin is built for Android & iOS platforms. Please run your projects on Android and/or iOS devices to test ads when integration is complete.

3. Enter Application Information

MAS provides a Unity configuration wizard for quick configuration application of information. You can access it through Assets/Yodo1/MAS Settings.

You will need to take the app key (generated in the game submission process) and add it into the configuration fields. You will also need to use the Admob ID generated by the MAS Dashboard.

3.1 Set Android Configuration

3.2 Set iOS Configuration

4. Support AndroidX

4.1 Under “Assets”, click on “Settings”.

4.2 Select Use Jetifier.

4.3 Force Resolve

Please follow the steps of the screenshot bellow to Force Resolve.

Once Force Resolve is complete you should see this pop up bellow.

5. 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)
Yodo1AdBuildConfig config = new Yodo1AdBuildConfig().enableUserPrivacyDialog(true);
Yodo1U3dMas.SetAdBuildConfig(config);
  1. Custom user agreement
Yodo1AdBuildConfig config = new Yodo1AdBuildConfig().enableUserPrivacyDialog(true).userAgreementUrl("Your user agreement url");
Yodo1U3dMas.SetAdBuildConfig(config);
  1. Custom privacy policy
Yodo1AdBuildConfig config = new Yodo1AdBuildConfig().enableUserPrivacyDialog(true).privacyPolicyUrl("Your privacy policy url");
Yodo1U3dMas.SetAdBuildConfig(config);

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

6. Initialize the SDK

6.1 Include the following line at the top of the file where you initialize the MAS SDK:

using Yodo1.MAS;


6.2 Initialize the using SDK the Start method.

void Start()  {
  Yodo1U3dMas.InitializeSdk();
}

7. Proguard

Note: If you don’t need to use Proguard to obfuscate the code, please ignore this item.

If you need to use Proguard to obfuscate the code, make sure you don’t obfuscate the SDK code.

7.1 Please open the custom Proguard file as illustrated below

7.2 Add the following code to your ProGuard file such as Proguard-user.txt in the path /Assets/Plugins/Android/

-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.** { *; } 

8. Select Ad Formats To Implement

Banners are rectangular image or text ads that occupy a spot within an app’s layout. They stay on screen while users are interacting with the app.

Interstitial

Interstitials are full-screen ads that cover the interface of an app until closed by the user. They’re best used at natural pauses in the flow of an app’s execution, such as in between levels of a game or after completing a task.

Rewarded Video

Rewarded video ads are full-screen video ads that users have the option of watching in full in exchange for in-app rewards.

9. Set Up Your App-Ads.txt File

Click here for details!

Updated on September 24, 2021

Was this article helpful?

Related Articles