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

4

12

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?

Rossierossing answered 21/11, 2020 at 19:38 Comment(0)
R
8

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.

Rossierossing answered 21/11, 2020 at 19:38 Comment(0)
M
6

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.

Margo answered 16/12, 2020 at 14:45 Comment(3)
These solutions operate on the assumption that those who have old development machines also have older versions of Studio on it that they can revert back to. Well actually its more likely that those that have old development machines want to keep them offline to keep the internet from destabilizing and exposing things. When they do upgrade, they are required to do a fresh install of Studio on a fresh drive. If I was an open source programmer I would just get a Chromebook for development and be done with it, but I've never made a dime on open source...Talebearer
You don't need to use old Android Studio, you can just update the AGP version. In case you don't want to do that, you can use the AAPT2 from build tools: Android/sdk/build-tools/30.0.x/aapt2Margo
2024, this is still a fix :). Thank you!Hogle
C
1

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.

Correy answered 25/12, 2020 at 4:55 Comment(0)
T
0

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...

Talebearer answered 24/11, 2020 at 23:54 Comment(3)
You may want to rewrite your questions in a comment to my answer, since it's not an answer to the question. I'll modify my answer to reflect your questions.Rossierossing
PS If you don't mind, vote this question & its answer up!Rossierossing
YinOrYan I also filed a bug report, and there were others. I must be unlucky, because I routinely encounter problems when Android Studio upgrades. I even keep one machine un-upgraded sometimes to be safe.Rossierossing

© 2022 - 2024 — McMap. All rights reserved.