I have a Mac with M1 Max chip running Monterey (12.3.1). I am running Android Studio Chipmunk(2021.2.1 Patch 1). Since I update the OS and the studio, I am having challenges in running Android SDK. My code was throwing following error during compilation:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeInternalDebugResources'.
> Multiple task action failures occurred:
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> AAPT2 aapt2-7.0.3-7396180-osx Daemon #0: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
> AAPT2 aapt2-7.0.3-7396180-osx Daemon #1: Daemon startup failed
....
Caused by: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-7.0.3-7396180-osx Daemon #7: Daemon startup failed
This should not happen under normal circumstances, please file an issue if it does.
at com.android.builder.internal.aapt.v2.Aapt2Daemon.handleError(Aapt2Daemon.kt:193)
at com.android.builder.internal.aapt.v2.Aapt2Daemon.handleError$default(Aapt2Daemon.kt:190)
at com.android.builder.internal.aapt.v2.Aapt2Daemon.checkStarted(Aapt2Daemon.kt:77)
at com.android.builder.internal.aapt.v2.Aapt2Daemon.compile(Aapt2Daemon.kt:100)
at
com.android.builder.internal.aapt.v2.Aapt2DaemonManager$LeasedAaptDaemon..compile(Aapt2DaemonManager.kt:170)
.....
Caused by: java.io.IOException: Cannot run program "/Users/myuser/.gradle/caches/transforms-3/83c6baf2eeddcf66af012c889d39d1c1/transformed/aapt2-7.0.3-7396180-osx/aapt2": error=86, Bad
CPU type in executable
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
at com.android.builder.internal.aapt.v2.Aapt2DaemonImpl.startProcess(Aapt2DaemonImpl.kt:86)
at com.android.builder.internal.aapt.v2.Aapt2Daemon.checkStarted(Aapt2Daemon.kt:56)
... 37 more
Caused by: java.io.IOException: error=86, Bad CPU type in executable
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
... 40 more
Since it was an AAPT error, I went to the SDK build-tools folder 30.0.2 and tried to run it from the terminal itself and it gave the following error(for both AAPT and AAPT2):
zsh: bad CPU type in executable: ./aapt2
I tried running the same from 32.1.0-rc1 and 33.0.0-rc4, it ran perfectly. So I tried to delete the .gradle and .android folder from the /Users location and .gradle from the studio workspace. Then removed the other build tools from the sdk manager and build apk again. But to my surprise, the gradle was looking for 30.0.2 build tool
License for package Android SDK Build-Tools 30.0.2 accepted.
Preparing "Install Android SDK Build-Tools 30.0.2 (revision: 30.0.2)".
"Install Android SDK Build-Tools 30.0.2 (revision: 30.0.2)" ready.
Installing Android SDK Build-Tools 30.0.2 in /Users/myuser/Library/Android/sdk/build-tools/30.0.2
"Install Android SDK Build-Tools 30.0.2 (revision: 30.0.2)" complete.
"Install Android SDK Build-Tools 30.0.2 (revision: 30.0.2)" finished.
So I assumed that this version of the studio have a minimum requirement for the build tool so that's why its downloading it! But still was expecting it to download a proper working one ! but still the gave me the same AAPT error !!
Any idea why AAPT/AAPT2 is not working for me?
Thanks in advance and Happy coding !!
CodePudding user response:
Finally resolved it after booting in safe mode and reinstall Rosetta 2 !!