Skip to content

Commit 53f5500

Browse files
tomoima525facebook-github-bot
authored andcommitted
Fix App Bundle/Release build missing index.android.bundle with gradle 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
1 parent 41c788a commit 53f5500

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

react.gradle

+5
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ afterEvaluate {
302302
enabled(currentBundleTask.enabled)
303303
}
304304

305+
// mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+.
306+
// This ensures to copy the bundle file before mergeResources task starts
307+
def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")
308+
mergeResourcesTask.dependsOn(currentAssetsCopyTask)
309+
305310
packageTask.dependsOn(currentAssetsCopyTask)
306311
if (buildPreBundleTask != null) {
307312
buildPreBundleTask.dependsOn(currentAssetsCopyTask)

0 commit comments

Comments
 (0)