-
Notifications
You must be signed in to change notification settings - Fork 4
Include Android
⚡ Before you start
Make sure you have correctly Configuring SDK.
- Configure Gradle
- Configure EDM4U
- Unity 2022.2+ Support
- Android 12 Support
- Included permissions in SDK
- Enable MultiDEX
The Clever Ads Solutions Unity plugin is distributed with the EDM4U library. This library is intended for use by any Unity plugin that requires access to Android specific libraries (e.g., AARs) or iOS CocoaPods. It provides Unity plugins the ability to declare dependencies, which are then automatically resolved and copied into your Unity project.
Using EDM4U, you will be able to avoid downloading the Android artifacts into your project. Instead, the artifacts will be added to your gradle file during the compilation. To enable this process, follow these steps:
- Go to:
Player Settings > Publishing Settings > Build
-
Custom Main Gradle Template
to configure third party dependencies. -
Custom Launcher Gradle Template
to enable MultiDEX.
You can read more about MuliDex on the Android Deleveloper page. -
Custom Base Gradle Template
to update Gradle plugin with fix support Android 11.
You can read more about fix Gradle plugin with support Android 11 on the Android Deleveloper page. -
Custom Gradle Properties Template
to use Jetfier by EDM4U. -
Custom Main Manifest
to modify application manifest.
- Go to:
Assets > External Dependency Manager > Android > Settings
-
Patch mainTemplate.gradle
The mainTemplate.gradle file will be patched with dependencies managed by the Android Resolver. -
Use Jetfier
Legacy Android support libraries and references to them from other libraries will be rewritten to use Jetpack using the Jetifier tool. -
Patch gradleTemplate.properties
For Unity 2019.3 and above, it is recommended to enable Jetfier and AndroidX via gradleTemplate.properties. This has no effect in older versions of Unity. - Save your changes, by pressing
OK
In the Unity editor, select Assets > External Dependency Manager > Android Resolver > Resolve
. The Unity External Dependency Manager library will append dependencies to mainTemplate.gradle
of your Unity app.
Unity switched to the new Android Gradle Plugin version (7.1.0). In this version, the repository setting was moved from the top-level build.gradle
file to the setting.gradle
file.
The error example from Unity Editor Log
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> Could not resolve all files for configuration ':launcher:releaseRuntimeClasspath'.
> Could not find com.***.ads.sdk:sdk:1.0.0.
Searched in the following locations:
- ***
Required by:
project :launcher > project :unityLibrary
To support this change, you must complete the following steps:
- Go to:
Player Settings > Publishing Settings > Build
-
Custom Gradle Settings Template
to createAssets/Plugins/Android/settingsTemplate.gradle
file
-
- Modify the
settingsTemplate.gradle
file by adding to thedependencyResolutionManagement
all therepositories
required for the project's dependencies.
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
repositories {
**ARTIFACTORYREPOSITORY**
google()
mavenCentral()
flatDir {
dirs "${project(':unityLibrary').projectDir}/libs"
}
// Add CAS Mediation repositories
maven { url = "https://android-sdk.is.com/" } // IronSource
maven { url = "https://aa-sdk.s3-eu-west-1.amazonaws.com/android_repo" } // SuperAwesome
maven { url = "https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea" } // Mintegral
maven { url = "https://artifact.bytedance.com/repository/pangle" } // Pangle
maven { url = "https://sdk.tapjoy.com/" } // TapJoy
// Add other repositories
}
}
We believe that the next EDM4U update will automate this support.
If your app targets Android 12, then you must explicitly declare the android:exported
attribute. For all changes in Android 12, see Behavior changes in Android 12
Add the android:exported="true"
attribute to the <activity>
tag to Assets/Plugins/Android/AndroidManifest.xml
:
<application ...>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
Sometimes permissions are included in the partner SDK’s internal AndroidManifest.
To remove a specific embedded permission (for example, ACCESS_COARSE_LOCATION), add the following tag to your top level AndroidManifest during integration:
<manifest>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove"/>
</manifest>
At times, including the CAS SDK may cause the 64K limit on methods that can be packaged in an Android dex file to be breached. This can happen if, for example, your app packs a lot of features for your users and includes substantive code to realize this.
The error example from Unity Editor Log
stderr[
D8: Cannot fit requested classes in a single dex file (# methods: 136481 > 65536)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:transformDexArchiveWithExternalLibsDexMergerForRelease'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The number of method references in a .dex file cannot exceed 64K.
If you would like to enable the MultiDEX support library, you can do so in the Assets > CleverAdsSolutions > Android Settings > Other Settings
by check:
- MultiDEX enabled
❕You can read more about MultiDex on the Android Deleveloper page.
🔗 Done! What’s Next?
- Read about compliance with the Google Plays Families Policy
- Make sure you are Include iOS platform as well.
- Project Setup
- Configuring SDK
- Include Android
- Include iOS
- Additional mediation steps
- App-ads.txt🔗