[Android] Requiring images with Gradle 4 fails release builds
See original GitHub issueHello guys,
I ran into this issue when updating Gradle and Android Studio.
Thanks for your help!
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: macOS Sierra 10.12.6 Node: 8.5.0 Yarn: 1.3.2 npm: 5.3.0 Watchman: 4.7.0 Xcode: Xcode 9.1 Build version 9B55 Android Studio: 3.0 AI-171.4408382
Packages: (wanted => installed) react: 16.0.0 => 16.0.0 react-native: 0.50.3 => 0.50.3
Target Platform: Android (22)
Steps to Reproduce
Requiring images with latest gradle
fails release builds
I created a small test project but here are the steps to reproduce it:
- Init a new project:
react-native init Test
- Update to latest Gradle:
- Open Android Studio and install recommended version
- Build from Android Studio, it should ask you to update build tools, do so
- Require an image in
index.js
- Run
cd android && ./gradlew assembleRelease
Expected Behavior
The command ./gradlew assembleRelease
should not fail
Actual Behavior
Running ./gradlew assembleRelease
when the image is required from the JS fails with:
/Users/almouro/bam/uefa/TestGradle3/android/app/build/intermediates/res/merged/release/drawable-mdpi/image.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
error: failed parsing overlays.
If the image is not required, the command works fine.
Reproducible Demo
git clone https://github.com/Almouro/react-native-with-gradle-4
yarn
cd android
./gradlew assembleRelease
Workaround
Adding android.enableAapt2=false
to android/gradle.properties
fixes the issue but it is only a workaround.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:221
- Comments:122 (15 by maintainers)
Top GitHub Comments
This bug has been a pain since we’ve upgraded to Android 3.x and setting
android.enableAapt2 = false
is not a sustainable long term workaround. It’s disappointing that there is no traction on this serious issue.I had the same issue. But did not fix with -
android.enableAapt2=false
, as this has issues with other drawable resources in the project.Fixed it with adding
org.gradle.configureondemand=true
in build.gradle, which shall disable the ‘bundleReleaseJsAndAssets’ task to run, which is the best solution and works in any condition. Hope this helps.