cleveradssolutions / CAS-Unity

CAS.AI Unity plugin for monetizing mobile applications.
https://cas.ai
Apache License 2.0
24 stars 4 forks source link

[Android] API 34 Build error: AAPT2 Unexpected error during link, attempting to stop daemon. #11

Open Str4tos opened 3 months ago

Str4tos commented 3 months ago

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:

* 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:

  1. Download AAPT2. Download Build-Tools 34.0.0 via Android SDK Manager or obtain just the AAPT2 component from Google Maven.
  2. Override Gradle path to AAPT2 Add the following line before **ADDITIONAL_PROPERTIES** in Assets/Plugins/Android/gradleTemplate.properties file:
    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.

Str4tos commented 3 months ago

Fixed in Unity 2021.3.41f1 with the following changes: