imageandroid-studioupgradeaapt2

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


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?


Solution

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