Why is Android Studio failing to build, with an AAPT2 error on images?

耗尽温柔 提交于 2021-01-22 19:03:46

问题


After a recent update, Android Studio fails to build an unmodified project with errors along these lines:

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

  > AAPT2 aapt2-4.1.1-6503028-linux Daemon #0: Unexpected error during compile '/path/to/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png', attempting to stop daemon.
    This should not happen under normal circumstances, please file an issue if it does.

Notice that it's failing on an image supplied by Android Studio itself!

What can I do to fix it?


回答1:


Sadly, it looks like an issue with older architectures. While the team at Google is looking into fixing it, in the meanwhile you can still use the new Android Studio and AGP, but temporarily revert to using an older version of AAPT2:

Try locating the old aapt2 executable in your gradle cache, e.g.: ~/.gradle/caches/<subdirectories, hashes etc>/aapt2-4.1.0-alpha03-6246747-/aapt2(.exe)

Once you have the path you can add to your gradle.properties file: android.aapt2FromMavenOverride=path/to/old/aapt2

To make this a little bit more robust you can actually copy that executable to a non-cache location, in case you clean your caches and it dissapears.

Hope this helps! Keep an eye on the Issue Tracker bug for updates.




回答2:


This seems to be an error in the newest (newer?) Gradle plugin(s) when it comes to PNG images; Google's IssueTracker lists several newly reported bugs along these lines. One of them mentions that it's a Gradle issue; I made mine work by reverting to a previous version: Gradle Plugin 4.0.1 and Gradle version 6.1.1 work fine.

It will be necessary to ignore AS' nagging about a newer version until this gets fixed.

[Added at the request of @YinOrYan]

To revert to an older version of Gradle:

  1. In the menu, select "Files", then "Project Structure..."
  2. In the dialog that pops up, select "Project" (first item in my version).
  3. You can select the desired versions of the Gradle plugin and of Gradle from the drop-down menus.

This should not lose any system calls, as this is different from the SDK or API versions. However, it's not independent of them, so there is probably a limit to where you can set them.

As usual you will want to be online when you first build, or whenever you have to import a dependency, but otherwise it should be possible to work offline.




回答3:


Wow, that's a real show-stopper! Can you explain how you reverted to an older gradle in Android Studio. Is it possible to work offline after doing this. And, did you lose any of the new system calls as a result? All this going on after finally getting my code working with the new AR Core stuff...




回答4:


Looks like Google's solution is for you to buy newer hardware, preferably Apple. They state:

"thanks, that matches what we've seen with the reported issue on Linux (which crashed more "obviously"), so this makes a convincing argument that the Windows and Linux issues have the same underlying (lack of SSSE3) cause."

My censored response was:

What??? (lack of HARDWARE) cause for something that looks like wrong paths for some new icon spec? Sounds like Apple's concept of planned-obsolescence! Is Android switching from the linux to BSD kernal? or is this just something that happens when working at home with your dependencies...




回答5:


I also had the same problem with AAPT2 errors and I have got over it.

First, downgrades Gradle to version 4.0.1, or

Second, I have done is upgrading the AMD Athlon processor to AMD FX-4300 without downgrading the gradle plugin version.




回答6:


My current solution: Go back to Eclipse. Almost forgot how much faster it compiles. I am putting all my ARCore projects on the back-burner until Google gets their act together. That, or I can afford another computer. Whichever comes first!



来源:https://stackoverflow.com/questions/64947285/why-is-android-studio-failing-to-build-with-an-aapt2-error-on-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!