6

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?

John Perry
  • 2,283
  • 1
  • 15
  • 25

4 Answers4

6

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.

John Perry
  • 2,283
  • 1
  • 15
  • 25
3

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.

Izabela Orlowska
  • 6,846
  • 2
  • 17
  • 32
  • 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... – YinOrYan Dec 16 '20 at 23:50
  • 2
    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/aapt2 – Izabela Orlowska Dec 17 '20 at 15:08
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.

Irvan Dwi Pangga
  • 209
  • 4
  • 13
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...

YinOrYan
  • 76
  • 5
  • 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. – John Perry Nov 25 '20 at 19:05
  • PS If you don't mind, vote this question & its answer up! – John Perry Nov 25 '20 at 19:12
  • 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. – John Perry Nov 28 '20 at 01:26