-
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
Flavors & App Bundle missing index.android.bundle #29398
Comments
One more clue here, I find that we have to run |
Thanks for the issue @lorenzoangelini!
Hmm are you saying after the second run of |
In a sense, yes. Below is what I have in my release script for Android side. It works well so far.
Otherwise, "index.android.bundle" won't be included in the generated AAB. I saw that "index.android.bundle" generation step is invoked but it is simply not included in AAB. |
@safaiyeh @thanakij yes it seems that the first time the folder assets with "index.android.bundle" is not present. |
I would like to provide my setting below:
Hopefully, this would help maintainers fix the issue. |
With this i have the issue: With this version the issue is not present |
I have a build with the same problem. The bundle is missing but the images are copied correctly it seems. |
I can confirm that running a double-build (ie. react-native: 0.63.2 |
@thanakij with the same gradle configuration and with
the index.android.js is correctly injected in the aab archive without the need to run a double-build. I haven't reproduce the same behaviour with a new react-native project. I think that the main problem is when there are multiple dex files as in my project. |
The same issue happened to me when Seeing from reports from others looks like the issue is related to Gradle Running |
I'm running into this as well. In my case I'm attempting to Everything is correct in the APK (all assets present) except it's missing the bundle! The bundle gets generated without issue, it's sitting in the correct directory, it just never gets added to the APK for unknown reasons. I've been tearing my hair out all day trying to figure out how/why this is happening. Unfortunately running It's definitely caused by the upgrade to android gradle plugin 4.1. Reverting to 3.6.4 fixes the issue however I need to use 4.1 for other reasons. @safaiyeh Did you ever get to take a look at this? I think it can be reproduced on any app with multidex by upgrading gradle to 6.5+ and android gradle plugin to 4.1.0+. Do a clean and then |
I have a reproducible project here => https://github.com/tomoima525/android_build_test_rn |
@tomoima525 thanks, I'll look into it in next few days |
Are you running |
@tomoima525 @dulmandakh I found a workaround. It seems to be a gradle task ordering issue. It appears that assets get merged before the bundle gets copied to the intermediate output directory. Adding the following to
I have little knowledge of gradle so this isn't a great workaround, it doesn't account for different build variants etc but at least it works for basic |
@AndrewMorsillo Amazing, thank you for your input! Your idea does make sense and solves the issue. I dug into |
@tomoima525 @AndrewMorsillo In my case with Proguard enabled doesn't work. The |
@alessioemireni interesting. I'll check with my reproducible repository https://github.com/tomoima525/android_build_test_rn in my spare time( I turned off proguard in that project because |
@tomoima525 yes, I have applied a patch with your fix, but the result is the same. react-native: 0.62.2 I have also increased the gradle plugin version to 4.1+ but the bundle is missing in aab. |
@alessioemireni your case seems something different. This is reproducible when android gradle plugin is 4.1 and gradle is 6.5. In fact the issue did not happen with android gradle plugin 3.5.3/ gradle 6.2 on my environment somehow. (which strangely contradict with the original issue, but if you create an app with |
I have the reproducible case and fixed case with the fix I made in #30177. Repository: https://github.com/tomoima525/android_build_test_rn Reproducible caseTo reproduce the issue, run the command below
app-release.apk will be generated but it does not have index.android.bundle build Fixed caseI added the fix in #30177 . Running the command below will apply the patch to
(The script is tested on Mac. If the copying does not work on Linux, try directly copying the |
Huge thanks to @tomoima525 and @AndrewMorsillo for all of your work finding a solution! I was having a nearly identical issue where doing For people who don't want to manually patch the // This forces the copy task to run before merge resources. This should be removable starting with RN 0.63.4.
project.afterEvaluate {
def isAndroidLibrary = plugins.hasPlugin("com.android.library")
def variants = isAndroidLibrary ? android.libraryVariants : android.applicationVariants
variants.all { def variant ->
def targetName = variant.name.capitalize()
def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
def assetsCopyTask = tasks.findByName("copy${targetName}BundledJs")
mergeResourcesTask.dependsOn(assetsCopyTask)
logger.warn("Making task ${mergeResourcesTask} depend on ${assetsCopyTask}")
}
} |
Sorry to comment on this issue again. But the patch by @plowman works only for assemble builds not but bundling aab unfortunately. |
In my project assetsCopyTask is null |
@nilavassg what command are you running and what error are you seeing?
@FelipeLimaDeSouza you can add a line so that |
I did this but it comes null in all commands. |
@FelipeLimaDeSouza I see. I'm not an expert at any of this. My only guess is that If you do this you can find the steps which should be candidates:
|
Even with the task in the task list, it returns null. |
Me too, the solution from @tomoima525 only solves some part of the problem. It is still not working in case of AAB. I have gone through react.gradle file and investigated the output when running bundleRelease. The remaining issue is because the task copyReleaseBundleJs is executed before bundleReleaseJsAndAssets. In short, the copy task is executed before the actual JS generation task. Below line will make it works with "bundleRelease" (in addition to "assembleRelease"):
|
Also confirmed the same by @thanakij |
Did you change for that? currentAssetsCopyTask.dependsOn(currentBundleTask) |
… plugin 4.1.0+/gradle 6.5 (#30177) Summary: - This fix resolves #29398 - After updating gradle to 6.5+ and android gradle plugin to 4.1.0+(which is recommended in the latest Android Studio 4.1), Running `:app:assembleRelease` or `:app:bundleRelease` will not contain `index.android.bundle` in Apk/AAB. It will be included when the command executed twice. <img width="949" alt="Screen Shot 2020-10-17 at 11 32 43 PM" src="https://user-images.githubusercontent.com/6277118/96360808-38165c00-10d5-11eb-8b6e-f098517a24c7.png"> - This is caused by the task ordering update introduced in gradle plugin 4.1.0+/gradle 6.5. `mergeResources` task runs before `currentAssetsCopyTask`(copying the bundle asset file to intermediate output directory) which causes generated Apk/AAB not including the bundle file. - The fix ensures mergeResources task runs after currentAssetsCopyTask ## Changelog [Android] [Fixed] - Fix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0/gradle 6.5 Pull Request resolved: #30177 Test Plan: - Reproducible repository https://github.com/tomoima525/android_build_test_rn - This project is generated with `create-react-native-app` and updated Gradle version to 6.5 and com.android.tools.build:gradle plugin to 4.1 - Run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => reproduces the issue - After adding the fix above and run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => The issue is resolved - Also confirmed the build works properly with android gradle plugin `3.5.3` and `gradle 6.2`(the default value of `create-react-native-app`) Reviewed By: fkgozali Differential Revision: D24551605 Pulled By: cpojer fbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
@thanakij This works!🔥. Thank you. |
… plugin 4.1.0+/gradle 6.5 (facebook#30177) Summary: - This fix resolves facebook#29398 - After updating gradle to 6.5+ and android gradle plugin to 4.1.0+(which is recommended in the latest Android Studio 4.1), Running `:app:assembleRelease` or `:app:bundleRelease` will not contain `index.android.bundle` in Apk/AAB. It will be included when the command executed twice. <img width="949" alt="Screen Shot 2020-10-17 at 11 32 43 PM" src="https://user-images.githubusercontent.com/6277118/96360808-38165c00-10d5-11eb-8b6e-f098517a24c7.png"> - This is caused by the task ordering update introduced in gradle plugin 4.1.0+/gradle 6.5. `mergeResources` task runs before `currentAssetsCopyTask`(copying the bundle asset file to intermediate output directory) which causes generated Apk/AAB not including the bundle file. - The fix ensures mergeResources task runs after currentAssetsCopyTask ## Changelog [Android] [Fixed] - Fix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0/gradle 6.5 Pull Request resolved: facebook#30177 Test Plan: - Reproducible repository https://github.com/tomoima525/android_build_test_rn - This project is generated with `create-react-native-app` and updated Gradle version to 6.5 and com.android.tools.build:gradle plugin to 4.1 - Run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => reproduces the issue - After adding the fix above and run `./gradlew clean :app:assembleRelease` and `./gradlew clean :app:bundleRelease` => The issue is resolved - Also confirmed the build works properly with android gradle plugin `3.5.3` and `gradle 6.2`(the default value of `create-react-native-app`) Reviewed By: fkgozali Differential Revision: D24551605 Pulled By: cpojer fbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
I can't make the .aab work. I just updated my RN version to 0.63.4 which contains the fix but it seems the issue comes from Bitrise (Assemble Release, Export Universal APK, Android Sign, Deploy to Google Play steps) which handle artefacts in an unexpected way but can't be sure... Tried with Gradle 3.5.3/6.2 and 4.1.2/6.5. |
Experiencing the same issue after migrating gradle from 3.5.3 to 4.1.0 and wrapper from 6.2 to 6.7. Very annoying issue. Running |
work for me, thanks |
I was struggling with this after adding a new build type to gradle. Everything was built properly on the release type, regardless of the flavor. I finally gave up and removed my Staging build type completely. Instead, I created two productFlavors. One for my release app and the other one for the "staging" one. Both of them are using the default release build type. So my commands are as follow :
This way, it works without having to find work around or writing weird scripts that handle the bundling part. Moreover, you're able to set up your signing configuration, different app_name and bundle id at the flavor level. So in my case, I'm not missing on features that the buildTypes would bring. That said, it looks weird to me that it's still that hard to find a gradle setup that lets you build react native applications when adding a new build type. |
Description
We use the flavors into our apps to use different version. We have dev, test and prod. When we have upgraded to 0.63, to classpath("com.android.tools.build:gradle:3.5.3") and distributionUrl=https://services.gradle.org/distributions/gradle-6.2-all.zip, we cannot use the appbundle.
when we run ./gradlew bundleDevRelease -> we cannot find into the app-dev-release.aab the index.android.bundle. This cause a crash when open the app.
If we run this command : ./gradlew bundleRelease -> it build all variants
app-dev-release.aab -> missing
app-test-release.aab -> index.android.bundle present
app-prod-release.aab -> index.android.bundle present
it seems that the first time not set the index.android.bundle into assets
React Native version:
System:
OS: macOS 10.15.2
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 382.96 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 11.10.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.9.2 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 23, 27, 28, 29
Build Tools: 26.0.2, 27.0.3, 28.0.3, 29.0.2
System Images: android-19 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-27 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 11.3/11C29 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_201 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.0 => 0.63.0
npmGlobalPackages:
react-native: Not Found
Steps To Reproduce
1.Create a new project: npx react-native init AppName --template react-native-template-typescript
2. Add to gradle.build :
productFlavors {
prod {
}
dev {
applicationId 'com.appname.dev'
resValue "string", "build_config_package", "com.appname"
}
test {
applicationId 'com.appname.test'
resValue "string", "build_config_package", "com.appname"
}
}
3. run into android folder : ./gradlew clean && ./gradlew bundleDevRelease
Expected Results
Obtain an .aab file into android/build/outputs/bundle/devRelease. when i open the .aab i expect to find the folder base and into the base the folder assets that contain the index.android.bundle.
The text was updated successfully, but these errors were encountered: