Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0+/gradle 6.5#30177

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@tomoima525
Copy link
Contributor

@tomoima525tomoima525 commentedOct 14, 2020
edited
Loading

Summary

  • This fixresolvesFlavors & App Bundle missing index.android.bundle #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 containindex.android.bundle in Apk/AAB. It will be included when the command executed twice.

Screen Shot 2020-10-17 at 11 32 43 PM

  • This is caused by the task ordering update introduced in gradle plugin 4.1.0+/gradle 6.5.mergeResources task runs beforecurrentAssetsCopyTask(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

Test Plan

  • Reproducible repositoryhttps://github.com/tomoima525/android_build_test_rn

    • This project is generated withcreate-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 plugin3.5.3 andgradle 6.2(the default value ofcreate-react-native-app)

mikehardy, gut4, todorone, mrousavy, dmc1985, nhjuhoang, tehtea, vanydeasy, and friederbluemle reacted with thumbs up emojimikehardy, mrousavy, and tehtea reacted with heart emoji
@facebook-github-botfacebook-github-bot added the CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labelOct 14, 2020
@react-native-botreact-native-bot added Bug Platform: AndroidAndroid applications. labelsOct 14, 2020
@analysis-bot
Copy link

analysis-bot commentedOct 14, 2020
edited
Loading

PlatformEngineArchSize (bytes)Diff
ios-universaln/a--

Base commit:fb14fd4

@analysis-bot
Copy link

analysis-bot commentedOct 14, 2020
edited
Loading

PlatformEngineArchSize (bytes)Diff
androidhermesarm64-v8a7,389,8970
androidhermesarmeabi-v7a7,017,2130
androidhermesx867,832,1090
androidhermesx86_647,721,5950
androidjscarm64-v8a9,536,1980
androidjscarmeabi-v7a9,151,2260
androidjscx869,400,8740
androidjscx86_649,982,5840

Base commit:fb14fd4

@emeraldsanto
Copy link

I've also been experiencing this since updating this morning, reverting to 4.0.1 and 6.3 works until this PR is merged :)

tomoima525, todorone, and Ashwin-Mothilal reacted with thumbs up emoji

@tomoima525tomoima525 changed the titleEnsure mergeResources task runs after currentAssetsCopyTask on App Bundle/Release buildFix App Bundle/Release build missing index.android.bundle with gradle plugin 4.1.0+/gradle 6.5Oct 14, 2020
Ensure mergeResources task runs after currentAssetsCopyTask
@tomoima525tomoima525force-pushed theandroid-gradle-plugin-4_1-build branch fromc752304 toa6c7049CompareOctober 14, 2020 20:54
@tomoima525
Copy link
ContributorAuthor

Just rebased so that the commit message is more descriptive

@tomoima525
Copy link
ContributorAuthor

I have the reproducible case and fixed case with this patch

https://github.com/tomoima525/android_build_test_rn

Reproducible case

To reproduce the issue, run the command below

$ cd android$ ./gradlew clean :app:assembleRelease // or ./gradlew clean :app:releaseBundle

app-release.apk will be generated but it does not have index.android.bundle build

Fixed case

I added the fix in#30177 . Running the command below will apply the patch toreact.gradle and you can see the issue is resolved

$ yarn add_patch$ cd android$ ./gradlew clean :app:assembleRelease // or ./gradlew clean :app:releaseBundle

(The script is tested on Mac. If the copying does not work on Linux, try directly copying thereact-patch.gradle tonode_modules/react-native/react.gradle)

@mikehardy
Copy link
Contributor

mikehardy commentedOct 21, 2020
edited
Loading

Confirmed for me this fixes the error it says it fixes for RN0.63.3 and android gradle plugin 4.1.0

Here's a patch-package compatible thing you can cut-and-paste

catpatches/react-native+0.63.3.patch

diff --git a/node_modules/react-native/react.gradle b/node_modules/react-native/react.gradleindex 6441d93..c28cbd4 100644--- a/node_modules/react-native/react.gradle+++ b/node_modules/react-native/react.gradle@@ -302,6 +302,11 @@ afterEvaluate {             enabled(currentBundleTask.enabled)         } +        // mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+.+        // This ensures to copy the bundle file before mergeResources task starts+        def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")+        mergeResourcesTask.dependsOn(currentAssetsCopyTask)+         packageTask.dependsOn(currentAssetsCopyTask)         if (buildPreBundleTask != null) {             buildPreBundleTask.dependsOn(currentAssetsCopyTask)
tomoima525, Theofilos-Chamalis, mrousavy, mysport12, todorone, peternoordijk, kyo504, yberstad, Ashwin-Mothilal, pixelknitter, and 3 more reacted with thumbs up emojipeternoordijk, kyo504, kristijantomic, and pixelknitter reacted with rocket emoji

Copy link
Contributor

@cpojercpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for your contribution! 👍

Copy link
Contributor

@facebook-github-botfacebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@cpojer has imported this pull request. If you are a Facebook employee, you can view this diffon Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by@tomoima525 in53f5500.

When will my fix make it into a release? |Upcoming Releases

@react-native-botreact-native-bot added the MergedThis PR has been merged. labelOct 26, 2020
kelset pushed a commit that referenced this pull requestNov 27, 2020
… plugin 4.1.0+/gradle 6.5 (#30177)Summary:- This fixresolves#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.5Pull Requestresolved:#30177Test Plan:- Reproducible repositoryhttps://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: fkgozaliDifferential Revision: D24551605Pulled By: cpojerfbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
@John-Konordo
Copy link

John-Konordo commentedDec 12, 2020
edited
Loading

Development machine OS: MacOS X
IDE: Ms VSCODE
"react": "^17.0.1",
"react-native": "^0.63.4",
gradle plugin 4.1.1+ / gradle 6.5-all (distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip)

I had also aply the patch from here#29398 (comment)

I found a workarround to publish my apk to play console and don' t get the error index.android.bundle missing

In root directory of your project run the following commands
cd ./android/
./gradlew clean
rm -rf ~/.gradle/caches/*
cd ..
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
rm -rf ./android/app/src/main/res/drawable-*
rm -rf ./android/app/src/main/res/raw
cd ./android/
./gradlew assembleRelease

Install my apk to any device and works well and upload the apk to play console and the error dissapear too!

cristeahub pushed a commit to HyreAS/react-native that referenced this pull requestDec 21, 2020
… plugin 4.1.0+/gradle 6.5 (facebook#30177)Summary:- This fixresolvesfacebook#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.5Pull Requestresolved:facebook#30177Test Plan:- Reproducible repositoryhttps://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: fkgozaliDifferential Revision: D24551605Pulled By: cpojerfbshipit-source-id: b0effe2c6ea682748af185061af951e2f2bce722
@pixelknitter
Copy link

Confirmed for me this fixes the error it says it fixes for RN0.63.3 and android gradle plugin 4.1.0

Here's a patch-package compatible thing you can cut-and-paste

catpatches/react-native+0.63.3.patch

diff --git a/node_modules/react-native/react.gradle b/node_modules/react-native/react.gradleindex 6441d93..c28cbd4 100644--- a/node_modules/react-native/react.gradle+++ b/node_modules/react-native/react.gradle@@ -302,6 +302,11 @@ afterEvaluate {             enabled(currentBundleTask.enabled)         } +        // mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+.+        // This ensures to copy the bundle file before mergeResources task starts+        def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")+        mergeResourcesTask.dependsOn(currentAssetsCopyTask)+         packageTask.dependsOn(currentAssetsCopyTask)         if (buildPreBundleTask != null) {             buildPreBundleTask.dependsOn(currentAssetsCopyTask)

@mikehardy For those discovering this solution, I thought I'd figure out exact instructions to patch from 0.63.3 as my project is not ready to migrate to 0.64; this seems like a good option. I've not usedpatch-package before, runningpatch-package patches/react-native+0.63.3.patch would require me to make the changes to thenode_modules myself first, correct?

@mikehardy
Copy link
Contributor

@pixelknitter - nope,yarn add patch-package && mkdir patches drop the patch file into there (named correctly! that's how patch-package figures out what package etc) thenyarn patch-package should do it. Or all the equivalent-different-but-same npm commands.

If you are making anew patch (like how I generated this file) to fix some bug where you are the first person to find+fix, then you hack around in node_modules by hand yes, and runyarn patch-package <package name> and it will create a new patch for you with your new change in it for distribution like this patch here

pixelknitter reacted with heart emoji

@pixelknitter
Copy link

@pixelknitter - nope,yarn add patch-package && mkdir patches drop the patch file into there (named correctly! that's how patch-package figures out what package etc) thenyarn patch-package should do it. Or all the equivalent-different-but-same npm commands.

If you are making anew patch (like how I generated this file) to fix some bug where you are the first person to find+fix, then you hack around in node_modules by hand yes, and runyarn patch-package <package name> and it will create a new patch for you with your new change in it for distribution like this patch here

Thanks for the detailed response!

@mouhsnimohamed
Copy link

if you'r using proguard add an exception to android/app/proguard-rules.pro:

-keep class com.mypackage.BuildConfig { *; }

com.mypackage should match the package value in your app/src/main/AndroidManifest.xml file.

@xczaixian
Copy link

xczaixian commentedMay 12, 2021
edited
Loading

Confirmed for me this fixes the error it says it fixes for RN0.63.3 and android gradle plugin 4.1.0

Here's a patch-package compatible thing you can cut-and-paste

catpatches/react-native+0.63.3.patch

diff --git a/node_modules/react-native/react.gradle b/node_modules/react-native/react.gradleindex 6441d93..c28cbd4 100644--- a/node_modules/react-native/react.gradle+++ b/node_modules/react-native/react.gradle@@ -302,6 +302,11 @@ afterEvaluate {             enabled(currentBundleTask.enabled)         } +        // mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+.+        // This ensures to copy the bundle file before mergeResources task starts+        def mergeResourcesTask = tasks.findByName("merge${targetName}Resources")+        mergeResourcesTask.dependsOn(currentAssetsCopyTask)+         packageTask.dependsOn(currentAssetsCopyTask)         if (buildPreBundleTask != null) {             buildPreBundleTask.dependsOn(currentAssetsCopyTask)

thank you, but it's not work for me.
i supplement code below to make it work.

def compressAssetsTask = tasks.findByName("compress${targetName}Assets")compressAssetsTask.dependsOn(currentAssetsCopyTask)

@mikehardy
Copy link
Contributor

@xczaixian this is no longer a problem with current versions (0.64.1) - I'm not carrying this patch any longer as it has been integrated and released. Better to update and get the real fix

@9christian9
Copy link

9christian9 commentedFeb 9, 2023
edited
Loading

Ciao,
I'm writing for all the people who, like me, have experienced this problem.

Affected Versions

  • React Native: 0.67.x
  • Gradle 7.2.x - 7.3.x

The common error

Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

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 calledcurrentAssetsCopyTask located inreact.gradlefile.
As I understand, this "task" is responsible for copying theassets and in particularindex.android.bundle and 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

Elf2707 reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@facebook-github-botfacebook-github-botfacebook-github-bot left review comments

+1 more reviewer

@cpojercpojercpojer approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

BugCLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.MergedThis PR has been merged.Platform: AndroidAndroid applications.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Flavors & App Bundle missing index.android.bundle

12 participants

@tomoima525@analysis-bot@emeraldsanto@mikehardy@react-native-bot@John-Konordo@pixelknitter@mouhsnimohamed@xczaixian@9christian9@cpojer@facebook-github-bot

[8]ページ先頭

©2009-2025 Movatter.jp