Hi everyone. My project builds fine with API 33. When I Changed it to API 34 it gives the following error.
I hope there will be a solution until August
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':launcher:bundleReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2ProcessResourcesRunnable
> AAPT2 aapt2-4.2.0-7147631-windows Daemon #0: Unexpected error during link, attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* 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.0-7147631-windows Daemon #1: Unexpected error during link, attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUİLD FAILED in 7s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Same problem with Unity 2021.3.23f1 version. Any help?
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':launcher:bundleReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2ProcessResourcesRunnable
> AAPT2 aapt2-4.2.0-7147631-windows Daemon #0: Unexpected error during link, attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
2: Task failed with an exception.
-----------
* 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.0-7147631-windows Daemon #1: Unexpected error during link, attempting to stop daemon.
This should not happen under normal circumstances, please file an issue if it does.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================
* Get more help at https://help.gradle.org
BUİLD FAILED in 15s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Hi folks, I assume this is for 2021 not 2023 right? If 2021 please do change the title if you can so other folks could find it.
We are aware of this issue, we continue investigating with high priority and expect to have some further information soon. This is an AGP (Android Gradle Plugin) linking bug. The bug will show up when specific Android legacy libraries are added as dependencies to an Android Project, and the project targets API 34. These libraries are usually added through a third-party SDK.
In the meantime, we have identified a couple of workarounds you could try. Can you try them in your projects and give us feedback if they work and if your projects look good?
Option 1 - set compileSDK to 33
Enable custom templates /launcherTemplate and set compileSdk 33 while raising targetSdk 34. This should enable your project to move past the issue. (This may not work for you if some of your plugins require compileSdk 34)
Option 2 - Direct Gradle to use a newer AAPT2 version to compile your project. You can do this by
Download AAPT2 7.2.2 JAR for your build architecture
Unpack jar file
From Unity editor, go to Player Settings → Publishing → Custom Gradle Templates
Enable Custom Gradle Properties Template.
Open the newly created: Assets/Plugins/Android/gradleTemplate.properties file.
Add a line with android.aapt2FromMavenOverride=/replace/with/path/to/your/aapt2
This will instruct the Android Gradle Plugin to use this newer version of the linking tool.
Build as usual. This should enable your project to move past the issue.
@Voxel-Busters thanks for the tip - sadly minSDK 24 did not work in our reproduction project with those library dependencies, FB inclusion, and the specific agp/gradle settings.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:linkReleaseManifestForAssetPacks'.
> Illegal char <:> at index 68: D:\GitHub\TheGame\Library\Bee\Android\Prj\IL2CPP\Gradle\launcher\C:
Can you please explain the part “unpck” and “path”. I unpacked it using jar xf.
Oh. Is it possible to share the sample project to see if there are any other quicker solutions possible? I’m not sure why I’m unable to reproduce the issue on my end. Also, thanks for checking the suggested solution!
@LegacySystem you likely need to escape those try \ instead of \ eg C:\Users\MONSTER\Downloads\aap\aapt2.exe or this should also work with gradle if i recollect C:/Users/MONSTER/Downloads/aap/aapt2.exe try it out and let us know
@Voxel-Busters You can reproduce it a couple of ways with Unity 2021.3 default setup.
Add Facebook SDK and change Target API to 34 and build
OR
Create a blank project in 2021.3 change Target API to 34
Enable custom templates gradle.properties and main Template
On main Template under *deps add
implementation ‘androidx.legacy:legacy-support-v4:1.0.0’
implementation ‘androidx.legacy:legacy-support-v13:1.0.0’
On gradle properties add
android.useAndroidX=true
android.enableJetifier=true
Thank you. I tried it both andboth seemed to pass that error. But I got a new error (I love the smell of new build error in the morning:smile:).
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:dexBuilderRelease'.
> Could not resolve all files for configuration ':launcher:detachedConfiguration4'.
> Failed to transform jetified-play-services-measurement-api-21.6.2-runtime.jar to match attributes {artifactType=ext-dex-dexBuilderRelease, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingExternalLibArtifactTransform: C:\Users\MONSTER\.gradle\caches\transforms-2\files-2.1\841f89a34660ff6a15f4a05b1ef11144\jetified-play-services-measurement-api-21.6.2-runtime.jar.
> Error while dexing.
A quick search suggested to update the Firebase. I was using 11.9. Updated to 12.0 and Got this error:
* What went wrong:
Execution failed for task ':launcher:dexBuilderRelease'.
> Could not resolve all files for configuration ':launcher:detachedConfiguration4'.
> Failed to transform jetified-play-services-measurement-api-22.0.0-runtime.jar to match attributes {artifactType=ext-dex-dexBuilderRelease, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for DexingExternalLibArtifactTransform: C:\Users\MONSTER\.gradle\caches\transforms-2\files-2.1\152dc3d04a4b917333541e0fc6835cc1\jetified-play-services-measurement-api-22.0.0-runtime.jar.
So now the issue is about Firebase and not Facebook.
I am using :
Firebase Crashlytics,
Firebase Analytics
Firebase Remote Config
@LegacySystem Thank you very much for letting us know. Out of curiosity - does the game work as expected
with targetAPI 33 with and without that new aapt2?
Yes. I have no problem when using API 33. I am still sending updates using API 33, firebase 11.9 without aap2 changes. I will try withh aap2 and api 33
Notification has some bug on aapt2 method. We are getting an error when requesting for notification permissions on Android 13 and 14 on the store.
Fatal Exception: java.lang.Exception: AndroidJavaException : java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.FragmentManagerImpl.checkStateLoss(android.app.FragmentManagerImpl)
at android.app.FragmentManagerImpl.enqueueAction(android.app.FragmentManagerImpl)
at android.app.BackStackRecord.commitInternal(android.app.BackStackRecord)
at android.app.BackStackRecord.commit(android.app.BackStackRecord)
at com.unity3d.player.UnityPermissions.requestUserPermissions(com.unity3d.player.UnityPermissions)
at com.unity3d.player.UnityPlayer.nativeRender(com.unity3d.player.UnityPlayer)
at com.unity3d.player.UnityPlayer.access$500(com.unity3d.player.UnityPlayer)
at com.unity3d.player.UnityPlayer$e$1.handleMessage(com.unity3d.player.UnityPlayer$e$1)
at android.os.Handler.dispatchMessage(android.os.Handler)
at android.os.Looper.loopOnce(android.os.Looper)
at android.os.Looper.loop(android.os.Looper)
at com.unity3d.player.UnityPlayer$e.run(com.unity3d.player.UnityPlayer$e)
at UnityEngine.AndroidJNISafe.CheckException(UnityEngine.AndroidJNISafe)
at UnityEngine.AndroidJavaObject._CallStatic(UnityEngine.AndroidJavaObject)
at Unity.Notifications.Android.PermissionRequest.RequestPermission(Unity.Notifications.Android.PermissionRequest)
at Unity.Notifications.Android.PermissionRequest..ctor(Unity.Notifications.Android.PermissionRequest.)
at NotificationManager+<RequestAndroidNotificationPermission>d__8.MoveNext(NotificationManager+<RequestAndroidNotificationPermission>d__8)
at UnityEngine.SetupCoroutine.InvokeMoveNext(UnityEngine.SetupCoroutine)