Repository navigation
Description
Description
Some JS bundles (index.android.bundle) are missing in apks when using android flavors.
There has been this attempt to fix the bug: #32026
I can confirm the bug is still present in React Native 0.66.0.
React Native version:
System:
OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Memory: 3.84 GB / 15.26 GB
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 12.22.6 - ~/.nvm/versions/node/v12.22.6/bin/node
Yarn: Not Found
npm: 6.14.15 - ~/.nvm/versions/node/v12.22.6/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
Android SDK:
API Levels: 16, 23, 26, 27, 28, 29, 30
Build Tools: 23.0.1, 25.0.0, 25.0.2, 26.0.1, 27.0.3, 28.0.2, 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3
System Images: android-26 | Google Play Intel x86 Atom, android-29 | Intel x86 Atom_64
Android NDK: 20.1.5948944
IDEs:
Android Studio: Not Found
Languages:
Java: 1.8.0_252 - /home/michael/.sdkman/candidates/java/current/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.0 => 0.66.0
npmGlobalPackages:
*react-native*: Not Found
Steps To Reproduce
I have made this repository: https://github.com/MichaelBorde/RN066FlavorBundleIssue.
It is based on standard template (npx react-native init) with minimal modifications in android/app/build.gradle to define flavors.
Just create some release apks:
cd android
./gradlew clean assembleRelease
Inspect both crated apks you will find one with JS bundle and one missing it.
find . -name "*.apk" -exec unzip -l {} \; | grep assets
(Only 1 line will be present)
Expected Results
I expect to get a JS bundle in each created apk.
A potential fix
The following code could fix the issue: https://github.com/MichaelBorde/RN066FlavorBundleIssue/blob/main/android/app/build.gradle#L206.
Such a fix might be fragile because it is based on task name (a string) and such a name or task ordering might be changed in com.android.tools.build:gradle.
Similar issues
This issue is similar: #31157.
But this current issue does not concern proguard at all and targets React Native 0.66.0 which should include a fix (non working in my case).
Activity
cortinico commentedon Nov 1, 2021
Thanks for the reproducer. I was able to reproduce it locally, yet I wasn't able to find the root cause of the problems.
I believe this issue is happening only when you're building a multi-flavor version of an app. And is happening only when you're building more than one flavor due to a race condition on Gradle tasks.
Potentially moving to AGP 7.x and moving that logic to use the Artifact API might solve this issue.
If anyone else has the time to jump on this, feel free to ping me 👍
MichaelBorde commentedon Nov 2, 2021
I think these two assumptions are correct from my experience.
joeyfigaro commentedon Nov 7, 2021
Also affected by this issue. Am using
dev,beta, andprodflavors in a current application, and all*Debugbuilds (or anything with bundling disabled) fails. Metro is running as expected during my testing/attempts.hotaryuzaki commentedon Dec 10, 2021
maybe you can try this solution here
lfmatosm commentedon May 25, 2022
Still happens on
react-native==0.67.4, withcom.android.tools.build:gradle==4.2.2andgradle==7.2. Proguard is disabled on my app. Hermes is currently enabled, but the same problem happens if you disable it. Also, the problem was simuated on Linux environment. On macOs, this didn't happen.In my case, the error happens when building a single flavor from an app with multiple flavors configured. We have multiple types on our build stage (
dev,hml, etc.). Ourandroid/app/build.gradlelooks like this:So, for any flavor, there's actually 3 different APKs. So our assemble command looks like this:
The above command generates 3 APKs, where some of them randomly doesn't includes the
index.android.bundle. I didn't track down which tasks were being executed outside the required order, but that's probably the reason for the problem, as mentioned by @cortinico.If you build one type at a time, everything works smoothly:
Is worth to notice that this problem started happening only after upgrading from
react-nativeversion0.63.2to0.67.4. On the previous version, the Android Gradle plugin was3.5.3andgradlewas6.2.9christian9 commentedon Feb 9, 2023
Ciao,
I'm writing for all the people who, like me, have experienced this problem.
Affected Versions
The common error
In short, index.android.bundle is missing.
Common problem when trying to use productFlavors.
The problem
I found that the problem is in a native react gradle task, to be precise in the copy task called
currentAssetsCopyTasklocated inreact.gradlefile.As I understand, this "task" is responsible for copying the
assetsand in particularindex.android.bundleand pasting them into the temporary directories used to generate the APK.The solution
I created a repo that with a js script solves the problem before building the android app
https://github.com/9christian9/FIX-Android-productFlavors-RN0.67-gradle7.2-7.3
I hope this will help.
With ♥ by Christian
lucasantarella commentedon Feb 14, 2023
For those still looking, looks like this report is similar to the issue #31157
cortinico commentedon Dec 4, 2023
Closing as flavors support has been completely rewritten in React Native 0.71
Please migrate to that version and try again. If the issue persists open a new bug report