question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Requiring images with Gradle 4 fails release builds

See original GitHub issue

Hello 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:

  1. Init a new project: react-native init Test
  2. 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
  1. Require an image in index.js
  2. 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:closed
  • Created 6 years ago
  • Reactions:221
  • Comments:122 (15 by maintainers)

github_iconTop GitHub Comments

86reactions
SharpMobileCodecommented, Jan 26, 2018

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.

55reactions
iqbalshirolcommented, Feb 15, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Requiring images in React Native with latest gradle fails ...
If I update to the latest Gradle and then require an image in React Native, I cannot build release builds. I posted an...
Read more >
Known issues with Android Studio and Android Gradle Plugin
To fix the issue for all future projects, click File > Close Project. You should see the welcome screen. Then click Configure >...
Read more >
Build Cache - Gradle User Manual
When using a shared build cache for task output caching this even works across ... build failures if Gradle does not completely capture...
Read more >
Build for Android 11 with Unity | ARCore - Google Developers
Go to Preferences > External Tools > Android > Gradle, and set the custom Gradle to Gradle 5.6.4 or later. See Gradle build...
Read more >
How to fix all build errors in react native(Android specific).
Basically, what this error is trying to tell you is that this particular package does not support the Gradle version you are using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found