Open palkerecsenyi opened 4 years ago
Update
I solved this issue by doing this before each build:
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
and then run
cd android
./gradlew assembleRelease
Adding the --assets-dest
option to the command then gave a duplicate assets error when building, so I skipped that and it works perfectly.
Also, I tried experimenting with the version of hermes-engine
, but that had no effect. This issue doesn't seem to be anything to do with Hermes.
@palkerecsenyi that's more like a workaround as the bundle is already generated when you run assembleRelease
.
Have you tried removing this line: https://gist.github.com/palkerecsenyi/6c09728996c4f982dc3bd11ad757c45b#file-app-build-gradle-L81? just a shot in the dark here as this dictates where the bundle will be stored before being added to the .apk
.
Thanks for the reply @lucasbento! I tried commenting that line out, and once again the build finished perfectly. However, when launching the app I got a different fatal error:
com.facebook.jni.CppException: Could not get BatchedBridge, make sure your bundle is packaged correctly
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
at android.os.Looper.loop(Looper.java:237)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
at java.lang.Thread.run(Thread.java:919)
I tried running with both npx react-native run-android --variant=release
and ./gradlew assembleRelease
but both of them give the same error.
Update
Commenting out these lines fixed it, and my app runs successfully (with Hermes enabled):
if (useIntlJsc) {
implementation 'org.webkit:android-jsc-intl:+'
} else {
implementation 'org.webkit:android-jsc:+'
}
Beginner in React Native :-
For me, I am getting this error because it seems like the build script is looking assets
folder inside the Android project.
So, I just created the folder:
mkdir android/app/src/main/assets
and ran the command: (Found here)
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 --verbose
And then when I run
npx react-native run-android
:
I can see my app.js content on android emulator. Woohoo! However, now I am trying to figure out, why are the changes not live! I can see the changes in App.js reflect immediately on iOS simulator, but not on Android emulator. But that should be a seperate thread altogether. ✌️
@Ayyanchira I'm not completely sure, but I think it might have something to do with the fact that you've set --dev false
in the bundle command.
Try using this instead:
npx react-native bundle --platform android --dev true --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res --verbose
Again, I'm not too sure about this. In debug mode, I usually do this:
cd android
./gradlew assembleDebug
adb install app/build/outputs/apk/debug/app-debug.apk
cd ..
npx react-native start
and then launch the app on the phone/emulator. This seems to work fine and was unaffected by the update to 0.62.x
The ./gradlew assembleDebug
is completely fine to me.
However the ./gradlew assembleRelease
fails with error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
And a bunch of error like:
android/app/build/generated/res/react/release/raw/node_modules_reactnativevectoricons_glyphmaps_ionicons.json: Error: Duplicate resources
Then it works if I go to android/app/src/res/ and delete all drawable-hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi and raw folders.
Does anyone knows any ticket to fix this? I didn't find.
Thank you
Pessoal, essa solução funcionou para mim:
Unable to load script from assets 'index.android.bundle'. Make sure... Esse erro geralmente acontece porque o sistema não conseguiu criar o bundle inicial que contém todo o código Javascript da aplicação.
1- Para resolver comece criando uma pasta assets dentro da pasta android/app/src/main.
2- Logo após, execute o comando:
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/
3- Agora, feche as abas do terminal e execute novamente o comando:
npx react-native run-android ou yarn run react-native run-android ou yarn android
Facing this issue even in debug build. Any solid solution yet?
Currently facing this issue on 0.62.2, the bundle created from gradlew bundleRelease
wants to connect to the metro server somehow
@duncte123 Did you find a solution to this?
@duncte123 Did you find a solution to this?
Yes I did, I compiled on java 11 for some reason. Switching to java 8 solved the issue.
Still seeing the issue and confirmed we're using Java 8 to compile
I had this issue last week and the root cause was that it was using node 13 (the system version on my Mac - Big Sur) to bundle rather than node 10. Once I forced it to use node 10, it finally stopped crashing for release bundles. For some reason nvm stopped working 🤷♂️.
@lfalkner Still seeing the issue and confirmed we're using Java 8 to compile
You did not find a solution?
@duncte123 Currently facing this issue on 0.62.2, the bundle created from
gradlew bundleRelease
wants to connect to the metro server somehow
Same problem, java 8 version
@duncte123 Currently facing this issue on 0.62.2, the bundle created from
gradlew bundleRelease
wants to connect to the metro server somehowSame problem, java 8 version
Which node version are you using when you put node -v
in the command line in your project directory?
@ duncte123 В настоящее время сталкивается с этой проблемой на 0.62.2, пакет, созданный из
gradlew bundleRelease
хочет как-то подключиться к серверу метроТа же проблема, версия Java 8
Какую версию узла вы используете, когда помещаете
node -v
в командную строку в каталоге вашего проекта?
v13.11.0
That’s the same issue I had. It doesn’t work.
If you change it to use 10.16.3, does it work? That was my issue and it resolved once I used that older node version.
Это та же проблема, что и у меня. Не работает
Если вы измените его на использование 10.16.3, это работает? Это была моя проблема, и она разрешилась, когда я использовал ту старую версию узла.
Switch to v10.21.0, nothing has changed
I did have one other thing that might be required as well. I set the metro preset to exactly 0.58.
I have a similar problem. i'm upgrading from 61.5 to 63.00. i changed com.android.tools.build:gradle:3.4.2 -> com.android.tools.build:gradle:3.5.3 and https\://services.gradle.org/distributions/gradle-5.5-all.zip -> https\://services.gradle.org/distributions/gradle-6.2-all.zip
When i launch ./gradlew bundleDevRelease i don't find into the app.bundle the index.android.bundle. If i discard the previous changes it works. Do other people have the same mistake?
Has something changed with the new gradle?
I solved the problem when changing the build tools version from 4.0.1 to 3.5.3
After creating the next bundle, everything repeated
Not working yet, Only works with assembleDebug
and assembleRelease
, with the bundleRelease
fails when it's deployed in the play store.
It's hard to test for this to fail when the bundleRelease
cannot be installed for testing, or is there a way to know it will fail before deploying?
package.json: "react": "16.13.1", "react-native": "^0.63.0" "@react-native-community/async-storage": "^1.11.0", "@react-native-community/datetimepicker": "^2.6.1", "@react-native-community/google-signin": "^4.0.3", (recently added) "react-native-calendars": "^1.403.0", (recently added) "@react-native-community/hooks": "^2.6.0", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/netinfo": "^5.9.5", "@react-native-community/picker": "^1.6.6",
node v10.16.3 java version "1.8.0_261" com.android.tools.build:gradle:3.5.3
Crashlytics Report
Fatal Exception: java.lang.RuntimeException: 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. at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(CatalystInstanceImpl.java) at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:2) at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:10) at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:18) at com.facebook.react.ReactInstanceManager.a(ReactInstanceManager.java:264) at com.facebook.react.ReactInstanceManager.access$000(ReactInstanceManager.java) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:68) at java.lang.Thread.run(Thread.java:919)
This issue appears to crop up when using classpath 'com.android.tools.build:gradle:4.1.0'
(4.0 or greater). Changing back to 3.6.4
works but I'd like to use 4.1.0 for other reasons. As a workaround you can manually bundle as people above have said before running ./gradlew :app:assembleRelease
After banging my head off this all day I believe I've found a lead in this bug https://github.com/facebook/react-native/issues/29398
Check your android/app/build/generated/assets/react/release
folder. For me index.android.bundle
is sitting there, correctly compiled and ready to go. What seems to be happening is that the build process just never adds it to the APK. This appears to be some sort of non-deterministic or gradle task ordering issue. On the other thread some people report that running bundleRelease
twice picks up the js bundle the second time and correctly includes it. For me using assembleRelease
running twice did not fix it.
This certainly seems to be an issue with the react-native gradle scripts. Digging in I haven't been able to find much. I think maybe the copy${targetName}BundledJs
(copyReleaseBundledJs
in this case) task in node_modules/react-native/react.gradle
should be the thing that adds the file but I'm not sure.
I have no real experience with gradle and the Android build system so I don't know what actually does the final step of copying the file into the APK. Wherever that happens I think we'll find the root of this issue. I'd guess that the copy-bundle-to-apk step somehow happens before the bundle is finished or copied to its final output location. Can anyone point me toward where the actual "add stuff to the apk" step happens?
OK I've found a workaround for now. This probably isn't a great solution since it doesn't take into account build variants and whatnot but it works for a basic :app:assembleRelease
.
I added the following to android/app/build.gradle
//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+
//Seems like there's a task ordering issue and the assets get computed before the bundle is copied
//This forces the copy task to run before merge resources
project.afterEvaluate {
tasks.findAll { task ->
task.name.startsWith('merge') && task.name.endsWith('Resources')
}.each { t -> t.dependsOn "copyReleaseBundledJs" }
}
This forces gradle to run the "copy the js bundle to assets" task before the "merge assets into the apk" task. It seems that for whatever reason with gradle 4+ the task ordering can be wrong and the bundle gets moved to intermediate dir after gradle has already picked up all the assets so it never gets included in the APK.
Hopefully someone with more knowledge of gradle than I can chime in with a better solution.
I am experiencing this issue on react-native: 0.63.2
after upgrading from a lower version. As some other users have also mentioned, I am running a classpath 'com.android.tools.build:gradle:4.1.0'
which might be causing the problem.
When running ./gradlew assembleRelease
the APK might or might not work. This is happening kind of randomly.
I also tried running the command:
npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle
and it does work. However, I noticed the startup time of the app is 3 TIMES LONGER than it usually is! Something unnecessary is getting bundled and making the initial parsing VERY slow.
@wmonecke I think that's probably a separate issue -- it seems there are two issues with similar symptoms here.
If you don't have usesCleartextTraffic
then I think your app can fail to run in development mode but IIRC react native has defaulted to API 29 for awhile now. I don't remember if the default template has usesCleartextTraffic
or not.
The JS bundle doesn't get included in the production apk or aab because the gradle tasks run out of order. If you're still running into the "sometimes the production bundle is missing but not always" it's probably this one. There's a PR to fix it https://github.com/facebook/react-native/pull/30177 and I posted a workaround above.
@AndrewMorsillo
I am targeting API 29 and I am experiencing the issue (even if it says API 28 in the SO post). I will try out your solution first then!
Edit: The bug is still happening after adding usesCleartextTraffic
Damn isn't solved yet?
IDK it works quite well locally in debug and even sign a release, but on CI it builds and when users tried to launch it on their devices it unexpectedly failed.
//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+ //Seems like there's a task ordering issue and the assets get computed before the bundle is copied //This forces the copy task to run before merge resources project.afterEvaluate { tasks.findAll { task -> task.name.startsWith('merge') && task.name.endsWith('Resources') }.each { t -> t.dependsOn "copyReleaseBundledJs" } }
I have:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
and this seems to be the only solution that works very well in my pipeline :)
Thanks @AndrewMorsillo
As a workaround, patch https://github.com/facebook/react-native/pull/30177 locally.
curl https://github.com/facebook/react-native/commit/a6c7049f39f87885cf4d3fc486ec8a8782cf5450.diff > react-native-task-order-fix.patch
patch -d node_modules/react-native < react-native-task-order-fix.patch
yarn patch-package react-native
(if using npx) npx patch-package react-native
In my case, app release crashes on "react-native": "0.63.2" when generating .aab files. ./gradlew clean && ./gradlew bundleRelease && ./gradlew bundleRelease
.
Dual running ./gradlew bundleRelease
solved my problem
I upgraded to 0.63.4 which supposedly had a fix for this error (https://github.com/HyreAS/react-native/commit/b93cf8677a2ee0730e43c99c5312b3c8e2ae586f) (changelog: https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#v0634)
However the issue is still occurring.
How to reproduce:
NOTE: I am trying to build a staging
variant, this is my signing config setup:
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
matchingFallbacks = ['debug', 'release']
}
staging {
applicationIdSuffix ".staging"
matchingFallbacks = ['release', 'debug']
}
stagingdebug {
initWith debug
applicationIdSuffix ".staging"
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
// signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
This resolved the issue: https://github.com/lottie-react-native/lottie-react-native/issues/269#issuecomment-437603077
Solving this headache after some workaround there in android/app/src/main , I am getting this error because it seems like the build script is looking assets folder inside the Android project.
So, I just created the folder: mkdir android/app/src/main/assets
and ran the command: (Found here) 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 --verbose
And then when I run npx react-native run-android: I can see my app.js content on android emulator. Woohoo! However, now I am trying to figure out, why are the changes not live! I can see the changes in App.js reflect immediately on iOS simulator, but not on Android emulator. But that should be a seperate thread altogether. v
+1
I just found a solution if you're using proguard in release
https://github.com/facebook/react-native/issues/24361#issuecomment-546275780
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.
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.
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.
I'm getting this issue on 0.64 RN. The app doesn't throw the red screen, just closed the app. I double checked in logs on Android Studio and show that error
I'm getting this as well in a fresh project https://github.com/facebook/react-native/issues/30140#issuecomment-832482674
OK I've found a workaround for now. This probably isn't a great solution since it doesn't take into account build variants and whatnot but it works for a basic
:app:assembleRelease
.I added the following to
android/app/build.gradle
//Fix for bundle not getting included in APK or AAB with android gradle plugin 4+ //Seems like there's a task ordering issue and the assets get computed before the bundle is copied //This forces the copy task to run before merge resources project.afterEvaluate { tasks.findAll { task -> task.name.startsWith('merge') && task.name.endsWith('Resources') }.each { t -> t.dependsOn "copyReleaseBundledJs" } }
This forces gradle to run the "copy the js bundle to assets" task before the "merge assets into the apk" task. It seems that for whatever reason with gradle 4+ the task ordering can be wrong and the bundle gets moved to intermediate dir after gradle has already picked up all the assets so it never gets included in the APK.
Hopefully someone with more knowledge of gradle than I can chime in with a better solution.
@AndrewMorsillo Thanks! It's worked for me.
@palkerecsenyi , Need to Change your Gradle Version in Main => Build.gradle in Dependencies => classpath 'com.android.tools.build:gradle:4.0.2' <= Working for Me Try This
@palkerecsenyi , Need to Change your Gradle Version in Main => Build.gradle in Dependencies => classpath 'com.android.tools.build:gradle:4.0.2' <= Working for Me Try This
I have solved this for RN 0.60.5 when change gradle 3.4.x to 4.1.x, this solved my problem with downgrade to 4.0.2
I've tried many suggestions but only downgrading from gradle:4.2.1 to gradle:4.0.2 fixed the issue. I'm also on RN 0.60.5
Environment
Upgrading version
0.61.5->0.62.1
Description
I built my app for debug on Android, and everything works perfectly. However, when I build it for release, the build succeeds but upon launching the app it creates the following error:
I used this command to build my app:
Here is my
build.gradle
: https://gist.github.com/palkerecsenyi/1434ce9340c167b80847ea2dcee30528app/build.gradle
: https://gist.github.com/palkerecsenyi/6c09728996c4f982dc3bd11ad757c45bpackage.json
: https://gist.github.com/palkerecsenyi/d42eb7f1af6a6d3a83db9e271e720aecindex.js
(not sure if that's fully relevant): https://gist.github.com/palkerecsenyi/90274eadedb9ca9c8f4ebb0ec42f10caReproducible demo
I'm not sure if this happens with all upgrades, and I'm not sure how to reproduce it. I know at least one other person has experienced this issue: https://github.com/facebook/react-native/issues/25348#issuecomment-606182604.
Thanks in advance!