-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Environment
- Caused by Ad Adapter: DTExchange
- Target Android SDK: 34
- Found in Unity: 2020.X.X, 2021.X.X
- Fixed in Unity: 2022.3.X
Description
When attempting to build the project with Target Android SDK 34 and Build Tools version below 34.0.0, the build fails due to an AAPT2 error. This issue arises because some dependencies require AAPT2 features that are only available in Build Tools version 34.0.0 and higher.
Unity versions 2020 and 2021 use Build-Tools 30.0.2, which lacks support for the required AAPT2 features.
Unity version 2022 has support for Gradle 7.0.2, which includes a fix for AAPT2 issue.
Build error
An example of gradle build error:
* What went wrong:
Execution failed for task ':launcher:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
> AAPT2 aapt2-4.2.2-7147631-osx Daemon #0: Unexpected error during link, attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
Solution:
To resolve this issue in Unity 2020, 2021:
- Download AAPT2.
Download Build-Tools 34.0.0 via Android SDK Manager or obtain just the AAPT2 component from Google Maven. - Override Gradle path to AAPT2
Add the following line before**ADDITIONAL_PROPERTIES**inAssets/Plugins/Android/gradleTemplate.propertiesfile:
android.aapt2FromMavenOverride=/full/path/to/AndroidSDK/build-tools/34.0.0/aapt2
Replace /full/path/to/AndroidSDK with the actual path to your Android SDK installation directory.
For Windows use file with extension: appt2.exe.
Note
Upgrading your project to Unity 2022 is recommended as it includes compatibility with the required AAPT2 features, thereby resolving this issue.