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.
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.
Environment
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:
Solution:
To resolve this issue in Unity 2020, 2021:
**ADDITIONAL_PROPERTIES**
inAssets/Plugins/Android/gradleTemplate.properties
file:Replace
/full/path/to/AndroidSDK
with the actual path to your Android SDK installation directory.For Windows use file with extension:
appt2.exe
.