Android Integration
1. Add the repositories
Open your project level build.gradle
and add the following repositories if your game is not enrolled in Designed for Families program.
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://artifact.bytedance.com/repository/pangle" }
maven { url "https://android-sdk.is.com" }
maven { url "https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea" }
}
}
Add these repositories instead if your game in enrolled in Designed for Families program.
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url 'https://android-sdk.is.com' }
}
}
2. Import the SDK
Open your app level build.gradle
and add the following dependency if your game is not enrolled in Designed for Families program.
implementation 'com.yodo1.mas:full:4.8.5'
Add this dependency if your game is enrolled in Designed for Families program.
implementation 'com.yodo1.mas:google:4.8.5'
3. Initial configuration
Make sure multiDex is enabled in your build.gradle
.
defaultConfig {
multiDexEnabled true
}
Make sure that minSdkVersion is at least 21 in the defaultConfig section.
defaultConfig {
minSdkVersion 21
}
Add these lines to gradle.properties
file.
android.useAndroidX=true
android.enableJetifier=true
android.enableDexingArtifactTransform=false
4. Add your Admob ID
- Add your
AdMob ID
to your app’s AndroidManifest.xml file. - Your Admob ID can be found under the “details” of your app on MAS Dashboard.
- Please replace
YOUR_ADMOB_ID
with your own Admob ID.
4. Download the plugin files
Download the plugin folder.
Extract it and place Yodo1Ads.h and Yodo1Ads.cpp under Classes folder located at the root of your project directory.
Then place Yodo1Ads.java under proj.android/app/src/org/cocos2dx/cpp folder.
5. Update AppActivity.java
Add the following code to this class.
public static void initializeSdk(String appKey)
{
Yodo1Ads.initializeSdk(activity, appKey);
}
public static void initializeInterstitialAds()
{
Yodo1Ads.initializeInterstitialAds();
}
public static void showInterstitialAds()
{
Yodo1Ads.showInterstitialAds();
}
public static void initializeRewardAds()
{
Yodo1Ads.initializeRewardAds();
}
public static void showRewardAds()
{
Yodo1Ads.showRewardAds();
}
public static void showBannerAds()
{
Yodo1Ads.showBannerAds("Banner", "CENTER", "BOTTOM");
}
public static void hideBannerAds()
{
Yodo1Ads.hideBannerAds();
}
6. Update CMakeLists.txt
In cross-platforms source files, add Classes/Yodo1Ads.cpp under APPEND GAME_SOURCE and Classes/Yodo1Ads.h under APPEND GAME_HEADER.
# add cross-platforms source files and header files
list(APPEND GAME_SOURCE
Classes/AppDelegate.cpp
Classes/HelloWorldScene.cpp
Classes/Yodo1Ads.cpp
)
list(APPEND GAME_HEADER
Classes/AppDelegate.h
Classes/HelloWorldScene.h
Classes/Yodo1Ads.h
)
7. Initialize MAS
Use this code to initialize our SDK and make sure you replace YourAppKey with your own App Key, you can find it in your dashboard under Games section.
Yodo1Ads::initializeSdk("YourAppKey");
8. Load the ads
If you want to use the interstitial ads, you need to load them after initializing MAS, you can use the following code.
Yodo1Ads::initializeInterstitialAds();
The same thing applies to the rewarded ads, you can load them using the following code.
Yodo1Ads::initializeRewardAds();
9. Show the ads
Interstitial ads
Yodo1Ads::showInterstitialAds();
Rewarded ads
Yodo1Ads::showRewardAds();
Banner ads
Yodo1Ads::showBannerAds();
Then make sure to specify the banner type, horizontal and vertical alignments in your AppActivity.java in showBannerAds() method.
Size: Banner, AdaptiveBanner, LargeBanner, SmartBanner, IABMediumRectangle (please ask the support to enable them for you, only Banner is enabled by default).
Horizontal alignment: CENTER, LEFT, RIGHT
Vertical alignment: TOP, BOTTOM
10. Ad events
You can use the ad events placed in Yodo1Ads.cpp to check if the ads are loaded, opened, closed… or to reward the player.
If you’re using rewarded ads for examlpe, you can call your reward code from onRewardAdEarned() located in Yodo1Ads.cpp.
void onRewardAdEarned() {
CCLOG("Yodo1 Mas : onRewardAdEarned");
// TODO : Add your reward code here
}