build failing during merge resources with Android Gradle plugin 3.3.0

偶尔善良 提交于 2019-11-28 18:18:07

Updated 19th April, 2019

This issue has been fixed in Android Gradle Plugin 3.4.0.

After upgrading to Android Studio 3.4.0, the temporary fix suggested in the original answer can be removed. Hurray!

Original

This is a bug in AAPT2 in Android Gradle Plugin 3.3.0, when building a project with larger png's (around 2-3 mb and up).

@akong9759 created an issue for this on Googles issue tracker and it has been fixed.

https://issuetracker.google.com/issues/117900475

The problem has been fixed in Android Gradle Plugin 3.5.0-alpha03 and the fix is scheduled to be released in version 3.4.0.

A temporary fix for Android Gradle Plugin 3.3.0 has been suggested on the issue. Add the following to the project build.gradle:

allprojects {
    // Workaround for https://issuetracker.google.com/117900475
    // Remove when upgrading to AGP 3.4 or higher.
    configurations.matching { it.name == '_internal_aapt2_binary' }.all { config ->
        config.resolutionStrategy.eachDependency { details ->
            details.useVersion("3.5.0-alpha03-5252756")
        }
    }
}

I had the same issue. The build would break and mention different png files, like your background_4.png, but only on a Windows PC. The build on a Mac had no problems.

In my case the image size was the problem. Only images bigger than 2MB seamed to break the build. After reducing every image to something lesser than 2MB the build started working again.

Check your layout xml files carefully in my case issue was duplicate xml

<?xml version="1.0" encoding="utf-8"?>

You need to verify your layout.xml files. There may be something wrong. I got same error and fixed issue on layout file. It worked for me.

You need to clean up your older caches of gradle and maven dependencies. E.g, try to delete the files under .m2 and .gradle and then Invalidate Caches / Restart ...

Also, can try to disable enableAapt2 by setting it to false inside gradle.properties

android.enableAapt2=false

From the log It looks like one of your png image might be corrupt, Try replace or remove it and try to build.

\res\drawable-xxxhdpi\background_4.png

If you would change variants it would automatically configure itself... Means if you are going run free(Choose from built Variants) then paid flavor will be red and Vice-Versa.

After spending a long day on the issue, I have solved it by simply fetching the GIMP and converting the PNG files into JPG, as suggested by someone in google issue tracking.

It worked miracles, and I did not have to change any other file, package version or setting.

For me delete all build folders and restart system and reopen Android Studio works in debug mode.

Update:

One of my png was giving error : error: failed to read PNG signature: file does not start with PNG signature I open and export again in png. Now it is working with every build variant. And Delete one zero byte png. Anyone make it beautiful if works/ Thanks

I resolved this problem after reduce the image size.

  • noted size difference between the image who caused the problem and other images, you will found it great in size.

Solution:-

Just deleted drawable-xxxhdpi\background_4.png and re-generated android resources by running ionic cordova resources android --force

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