-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Requiring images with Gradle 4 fails release builds #16906
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
+1 have same issue with react-native 0.50
The file
indeed, is not present in the merged/release directory. But I have no idea who generates that file name for what reason/etc. |
My understanding is that the React Native bundleJS gradle task copies all the images in the android merged resources folder, but aapt now expects images there to be compiled in |
@Almouro I sorted out the issue with it turns out that something in aapt (or somewhere in gradle) chokes on image file names that are located in deep directory structures. the need to do the |
Same error:
node_modules: Has anyone had any success fixing this? I can't test the production app because of this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have the same issue. |
This bug has been a pain since we've upgraded to Android 3.x and setting |
This comment has been minimized.
This comment has been minimized.
Can't use |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
tl;dr - I think the bundling step in react.gradle should hand off to the Android build system much earlier in the build process I may have killed a few birds with one stone while working out a solution for something unrelated. I wanted to bundle the js ahead of time, then build multiple variants using that same bundle. The solution I came up with also allows you to keep AAPT2 enabled, which was a major plus. First I set a few environment variables, Then I bundle with The build.gradle adds those to the main source set: // not needed anymore in this setup:
// apply from: "../../node_modules/react-native/react.gradle"
android {
...
sourceSets {
// Android includes "main" in all application variants
main {
assets.srcDirs += System.env.REACT_NATIVE_JS_DIR
res.srcDirs += System.env.REACT_NATIVE_ASSETS_DIR
}
}
} Overall this feels a lot friendlier to the Android build system, as the resources and assets actually go through the I have a feeling that react.gradle could be modified to do something similar, like:
I'll try to find some time to put a PR together if that sounds reasonable. |
@CFKevinRef I've verified your approach works, as long as android_intermediates=$(mktemp -d)
export REACT_NATIVE_JS_DIR=$android_intermediates/assets/$build_type_lower
export REACT_NATIVE_ASSETS_DIR=$android_intermediates/res/merged/$build_type_lower It's not a great long-term solution, though, since avoiding the default gradle support may cause issues down the road, when new behavior is added, or something is changed. For now, it does allow things to work with AAPT2. Thank you! It'd be great to see that PR and have this ball rolling. |
Until this got fixed, there is another workaround similar to solution proposed by @CFKevinRef. This solution also allows you to keep using AAPT2. Workaround consists of three steps
please note that properties names are dynamic and depends on your target names, bundleIn, resourcesDir
with
|
Please give #17967 a try. You should be able to just replace your react.gradle with that one. Also if you have some old projects lying around based on the Android Gradle Plugin 1.x or 2.x I would appreciate a test as well! |
I had the same issue. But did not fix with - Fixed it with adding |
This comment has been minimized.
This comment has been minimized.
This should be fixed in 0.57 (see da6a5e0). |
THIS WORKED FOR ME, THANK YOU! |
This works for me on latest RN I did have to remove Thanks RN team |
Is this fix also added to 0.56.0 RN version? |
The reason it didn't work for me was because my |
React Native 0.48 I found solution for my issues, updating |
|
Could you please clarify what is your version of React and React Native? And maybe you will provide your full react.gradle file. Thanks in advance! |
I have "react-native": "^0.57.1", this issue still occurs. |
@khemrajsharma you need to bump to the version |
@SandroMachado react-native@0.57.3 expects peer dependency react@16.6.0-alpha.8af6728 which is still buggy |
The issue seemed to disappeared after I stepped back to this and deleted my build folder and rebuilt.
|
I am using the |
@rumax |
@iqbalshirol thanks for your suggestion. My project works again but what does This is my list of native libraries at the moment:
Thank you! |
This became the default with Android Gradle Plugin version 3.0.0: https://developer.android.com/studio/releases/gradle-plugin#3-0-0 So turning it off returns us to the behavior before we recently took that upgrade. Without this line, we run into this issue when attempting to make a release build: facebook/react-native#16906 That issue was closed long ago when an intended fix was merged, but then that was reverted. The fix went back in as da6a5e043 upstream, which is in v0.57.0, so we'll get it when we take that upgrade; hopefully that then fixes this for real.
|
android/app/build/intermediates/res/merged/debug/drawable-hdpi/node_modules_reactnavigationstack_dist_v iews_assets_backicon.png: error: uncompiled PNG file passed as argument. Must be compiled first into .flat file.. error: failed parsing overlays. this is the issue for me |
It is fixed in >=0.57.3. |
Summary: Mirrors facebook#17967 which was imported and reverted Original: Better integration with the Android Gradle-based build process, especially the changes introduced by the [Android Gradle Plugin 3.x and AAPT2](https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html). Fixes facebook#16906, the `android.enableAapt2=false` workaround is no longer required. Bases the task generation process on the actual application variants present in the project. The current manual process of iterating build types and product flavors could break down when more than one dimension type is present (see https://developer.android.com/studio/build/build-variants.html#flavor-dimensions). This also exposes a very basic set of properties in the build tasks, so that other tasks can more reliably access them: ```groovy android.applicationVariants.all { variant -> // This is the generated task itself: def reactBundleTask = variant.bundleJsAndAssets // These are the outputs by type: def resFileCollection = reactBundleTask.generatedResFolders def assetsFileCollection = reactBundleTask.generatedAssetsFolders } ``` I've tested various combinations of product flavors and build types ([Build Variants](https://developer.android.com/studio/build/build-variants.html)) to make sure this is consistent. This is a port of what we're currently deploying to our CI process. [ ANDROID ] [ BUGFIX ] [ react.gradle ] - Support Android Gradle Plugin 3.x and AAPT2 [ ANDROID ] [ FEATURE ] [ react.gradle ] - Expose the bundling task and its outputs via ext properties Pull Request resolved: facebook#20526 Differential Revision: D9164762 Pulled By: hramos fbshipit-source-id: 544798a912df11c7d93070ddad5a535191cc3284
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 buildsI created a small test project but here are the steps to reproduce it:
react-native init Test
index.js
cd android && ./gradlew assembleRelease
Expected Behavior
The command
./gradlew assembleRelease
should not failActual Behavior
Running
./gradlew assembleRelease
when the image is required from the JS fails with: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
toandroid/gradle.properties
fixes the issue but it is only a workaround.The text was updated successfully, but these errors were encountered: