Installation:
1. Android Studio
- SDK Manager
- Uncheck Hide obselete
- Check Show Package Details
- Check Android SDK Tools (Obselete)
- Android 11
2. Unity
- Edit > Preferences
- NDK r16b Download
- Gradle 5.6.4 Download (Android 11 introduce <queries> function so we need this support gradle, dont forget to check "Custom Gradle Template" on Player Setting)
- Unity in you Project after install Google Mobile Ads SDk
- Open : Asset > Plugin > Android > mainTemplate :
change 'com.android.tools.build:gradle:3.4.0'
to 'com.android.tools.build:gradle:3.6.0'
- AAB file in Temp Folder which produce by Unity is gradleOut-release.aab, But Gradle 5.6.4 Look for gradleOut.aab. So open ''mainTemplate'' and replace: Source
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
- with : defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
// MLR: rename aab for gradle 3.6.x
tasks.whenTaskAdded { task ->
if (task.name.startsWith("bundle")) {
def renameTaskName = "rename${task.name.capitalize()}Aab"
def flavor = task.name.substring("bundle".length()).uncapitalize()
tasks.create(renameTaskName, Copy) {
def path = "${buildDir}/outputs/bundle/${flavor}/"
from(path)
include "gradleOut-release.aab"
destinationDir file("${buildDir}/outputs/bundle/${flavor}/")
rename "gradleOut-release.aab", "gradleOut.aab"
}
task.finalizedBy(renameTaskName)
}
}
// MLR: End of rename
}
next:
go to the location
"C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0"
find a file named d8.bat. This is a Windows batch file.
rename d8.bat to dx.bat.
in the folder lib ("C:\Users\user\AppData\Local\Android\Sdk\build-tools\31.0.0\lib")
rename d8.jar to dx.jar
Remember AppData is a hidden folder. Turn on hidden items to see the AppData folder.
ERROR: The option setting 'android.enableR8=false' is deprecated.
FIX 1: Close Unity, delete Library Folder, Reopen unity.
FIX 2: open "gradleTemplate" add "#" on android.enableR8 then "Android Resolver > Delete Resolved Libraries"
ERROR: Mutidex
FIX: Open MainTemplate.gradle and add following lines.
defaultConfig {
...
multiDexEnabled true
}
and
dependencies {
...
implementation 'com.android.support:multidex:2.0.1'}
ERROR: Admob not showing ads
FIX: Uncheck all "Minify" settings
ERROR: Execution failed for task ':launcher:dexBuilderRelease'. > java.lang.UnsupportedOperationException: This feature requires ASM7
FIX: Player Setting > minify > Check: Use R8, Release, Debug
ERROR: You uploaded an APK or Android App Bundle which has an activity, activity alias, service or broadcast receiver with intent filter, but without 'android:exported' property set. This file can't be installed on Android 12 or higher. See: developer.android.com/about/versions/12/behavior-changes-12#exported
FIX 1: API Target version SDK 30
OR
FIX 2: Highest API but Change Android Manifest (Recommended)
- Build .aab file to produce AndroidManifest.xml temporary file
- Copy "\Temp\StagingArea\AndroidManifest.xml" to "Assets\Plugins\Android\"
- Find "activity"
- Add (android:exported="true")
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:exported="true" android:label="@string/app_name" android:screenOrientation="landscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false"> <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>