0% found this document useful (0 votes)
212 views11 pages

Release Mode Bundle Error

The document discusses issues encountered when building an Android release bundle for a React Native app. Setting --dev to false in the bundle command caused errors. Creating an assets folder and running the bundle command with --dev set to true resolved the issue. Upgrading build tools and Gradle versions also caused bundle generation to fail, requiring a downgrade.

Uploaded by

Raman deep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views11 pages

Release Mode Bundle Error

The document discusses issues encountered when building an Android release bundle for a React Native app. Setting --dev to false in the bundle command caused errors. Creating an assets folder and running the bundle command with --dev set to true resolved the issue. Upgrading build tools and Gradle versions also caused bundle generation to fail, requiring a downgrade.

Uploaded by

Raman deep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 11

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.

zaferbozkurt, leogildo10, kevin-guzman, montsepb, sjsakib, wmonecke, wildseansy,


scottjferguson, calderaro, Joshmatjjen, and 30 more reacted with thumbs up emoji
nathanguigui, coling-git, sawaYch, and rahmanharoon reacted with thumbs down emoji
nathanguigui and jackviatick reacted with confused emoji
sjsakib, sasanrk, wildseansy, Joshmatjjen, hanifmhd, brunoPertini, Prutii35,
jojemapa, jackviatick, AndreaGProg, and 3 more reacted with heart emoji
Ashafix, Joshmatjjen, hanifmhd, AndreaGProg, nachoSource, and hirensakhiya reacted
with rocket emoji
@lucasbento lucasbento added 0.62.1 and removed 0.61.5 labels on Apr 6, 2020
@lucasbento
Member
lucasbento commented on Apr 6, 2020
@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.

kevin-guzman and whoisdevd reacted with thumbs up emoji


@palkerecsenyi
Author
palkerecsenyi commented on Apr 6, 2020
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.

@palkerecsenyi
Author
palkerecsenyi commented on Apr 6, 2020
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:+'
}
@Ayyanchira
Ayyanchira commented on Apr 6, 2020
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. ✌️

smallswan399 and anassbenayed reacted with thumbs down emoji


uzairleo, unicornlab-brylleg, rtmruczek, kXyuamrutia, and MikeyAlmighty reacted
with heart emoji
@palkerecsenyi
Author
palkerecsenyi commented on Apr 6, 2020
@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

@wilsolutions
wilsolutions commented on Apr 8, 2020 •
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

akshgods and realramin reacted with thumbs up emoji


@Taynan-Vieira
Taynan-Vieira commented on Apr 23, 2020 •
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

Fonte: https://react-native.rocketseat.dev/erros/android/

meirinaldojunior and denisk20 reacted with thumbs down emoji


@Relax594
Relax594 commented on May 11, 2020
Facing this issue even in debug build. Any solid solution yet?

@duncte123
duncte123 commented on May 28, 2020
Currently facing this issue on 0.62.2, the bundle created from gradlew
bundleRelease wants to connect to the metro server somehow

lucastryhorn, lfalkner, singhvivek2503, jstheoriginal, wmonecke, lucianomlima,


mmarquezv, palkerecsenyi, edilsalvador, Asinox, and 8 more reacted with thumbs up
emoji
@singhvivek2503
singhvivek2503 commented on Jun 18, 2020
@duncte123 Did you find a solution to this?
@duncte123
duncte123 commented on Jun 18, 2020
@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.

@lfalkner
lfalkner commented on Jun 24, 2020
Still seeing the issue and confirmed we're using Java 8 to compile

jstheoriginal and wmonecke reacted with thumbs up emoji


@jstheoriginal
jstheoriginal commented on Jul 8, 2020
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 ‍♂️ .

@Imperyall
Imperyall commented on Jul 8, 2020
@lfalkner Still seeing the issue and confirmed we're using Java 8 to compile

You did not find a solution?

@Imperyall
Imperyall commented on Jul 8, 2020 •
@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

@jstheoriginal
jstheoriginal commented on Jul 9, 2020
@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

Which node version are you using when you put node -v in the command line in your
project directory?

@Imperyall
Imperyall commented on Jul 9, 2020
@ duncte123 В настоящее время сталкивается с этой проблемой на 0.62.2, пакет,
созданный из gradlew bundleReleaseхочет как-то подключиться к серверу метро

Та же проблема, версия Java 8

Какую версию узла вы используете, когда помещаете node -vв командную строку в
каталоге вашего проекта?

v13.11.0

@jstheoriginal
jstheoriginal commented on Jul 9, 2020
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.

@Imperyall
Imperyall commented on Jul 9, 2020
Это та же проблема, что и у меня. Не работает

Если вы измените его на использование 10.16.3, это работает? Это была моя проблема,
и она разрешилась, когда я использовал ту старую версию узла.

Switch to v10.21.0, nothing has changed

@jstheoriginal
jstheoriginal commented on Jul 9, 2020
I did have one other thing that might be required as well. I set the metro preset
to exactly 0.58.

@lorenzoangelini
lorenzoangelini commented on Jul 9, 2020
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?

wmonecke, dgupta-oanda, and edilsalvador reacted with thumbs up emoji


@Imperyall
Imperyall commented on Aug 10, 2020
I solved the problem when changing the build tools version from 4.0.1 to 3.5.3

@Imperyall
Imperyall commented on Aug 12, 2020
After creating the next bundle, everything repeated

Monte9 reacted with eyes emoji


@fabianmedina09
fabianmedina09 commented on Sep 8, 2020 •
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(CatalystInst
anceImpl.java)
at
com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanc
eImpl.java:2)
at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:10)
at
com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.jav
a: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)

nes123, Imperyall, vyrruss, nyzszn, dgupta-oanda, mross1337, enniel, smartameer,


VasylenkoStanislav, and lekeCoder reacted with thumbs up emoji
@evelant
evelant commented on Oct 14, 2020
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

reza-madani reacted with thumbs up emoji


13 hidden items
Load more…
@jamesone
jamesone commented on Jan 12, 2021
This resolved the issue: lottie-react-native/lottie-react-native#269 (comment)

@uzairleo
uzairleo commented on Jan 18, 2021 •
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

kodozorro added a commit to kodozorro/my-small-exchange-stock-info that referenced


this issue on Mar 4, 2021
@kodozorro
Building issues. react-native-community/upgrade-support#38 (comment)
a2d0ad4
@nelsonchen5
nelsonchen5 commented on Mar 17, 2021
+1

chrisbobbe, ThierryVC, and anassbenayed reacted with thumbs down emoji


@hanifmhd
hanifmhd commented on Apr 8, 2021 •
I just found a solution if you're using proguard in release
facebook/react-native#24361 (comment)

@mouhsnimohamed
mouhsnimohamed commented on May 3, 2021
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.

@ithustle
ithustle commented on May 4, 2021
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

jesspurvis, badredaha, 349989153, and sabun123 reacted with thumbs up emoji


@mrbrentkelly
mrbrentkelly commented on May 5, 2021
I'm getting this as well in a fresh project facebook/react-native#30140 (comment)

@enniel
enniel commented on May 24, 2021 •
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.

@ErAmanDhiman
ErAmanDhiman commented on Jun 9, 2021
@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

code-by and Stas-Buzunko reacted with thumbs up emoji


hanifmhd, ramisalem, TheScriptan, and aungkpaing reacted with thumbs down emoji
@code-by
code-by commented on Nov 24, 2021
@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

Stas-Buzunko reacted with thumbs up emoji


@Stas-Buzunko
Stas-Buzunko commented on Dec 1, 2021
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

@felipezf
felipezf commented on Feb 18
Any solution to work with the last Gradle version (7.1.1)?

Rubon72 reacted with thumbs up emoji


@brownieboy
brownieboy commented on Feb 26 •
I'm on react-native 67.2 and I'm getting this error with Gradle 7.1.1. Should I
downgrade Gradle too?

Update
Downgrading Gradle did fix the error for me on RN 67.2. This change in file
android/build.gradle:

dependencies {
// classpath('com.android.tools.build:gradle:7.1.1')
classpath('com.android.tools.build:gradle:4.1.2')
Rubon72, ahmdmhd, and nidorx reacted with thumbs up emoji
@Rubon72
Rubon72 commented on Mar 5
same problem for com.android.tools.build:gradle:7.1.1.
"react-native": "0.67.3",

abouquet, isidoro98, nidorx, and VasylenkoStanislav reacted with thumbs up emoji


@abouquet
abouquet commented on Mar 10
Same issue here guys ...

@marandaneto marandaneto mentioned this issue on Mar 22


Bump Gradle and AGP samples getsentry/sentry-react-native#1980
Closed
8 tasks
@giacomosardo
giacomosardo commented on Mar 29
I found a temp solution

I tried to change
classpath('com.android.tools.build:gradle:7.1.x')
with
classpath('com.android.tools.build:gradle:7.0.3')

"react-native": "0.67.4"

brownieboy, kklobe, wiseqingyang, zoix, Willham12, edisonlao, brianephraim,


rafaelmaeuer, igor-ignatov, alexfov, and 9 more reacted with thumbs up emoji
matijagrcic and jaaywags reacted with hooray emoji
sjerratsch reacted with heart emoji
@AndreaGProg
AndreaGProg commented on May 18 •
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.

Work for me! But before i must Clean Project from Android Studio > Build.
After ./gradlew assembleRelease run ./gradlew bundleRelease

ffrega and aruppatel08 reacted with thumbs up emoji


@marandaneto marandaneto mentioned this issue on Jun 12
Bump RN sample to 0.67.4 getsentry/sentry-react-native#2280
Merged
8 tasks
@abouquet
abouquet commented on Jul 28
Got for a second time the same issue

"react-native": "0.69.3"
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-bin.zip

@foxbit19
foxbit19 commented on Aug 9
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.

This works for me!

React native
0.69.3

gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
android/build.gradle
dependencies {
classpath('com.android.tools.build:gradle:7.0.4')
}
This is the sequence of commands that I've used:

npx react-native bundle --platform android --dev false --entry-file index.js --


bundle-output android/app/src/main/assets/index.android.bundle
cd android && ./gradlew assembleRelease
adb install app/build/outputs/apk/release/app-release.apk
mikaelsn and anassbenayed reacted with thumbs up emoji
@foxbit19 foxbit19 mentioned this issue on Aug 9
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. facebook/react-native#27157
Open
@airowe
airowe commented on Aug 23
Any solid solution here that aren't hacks?

@zakharchenkoAndrii
zakharchenkoAndrii commented 29 days ago •
For me helped proper versioning according to RN changelog. to 0.69.4
in particular:

classpath('com.android.tools.build:gradle:7.1.1')
classpath("de.undercouch:gradle-download-task:5.0.1")
...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
@ThiBsc ThiBsc mentioned this issue 9 days ago
immediate crash on launch ThiBsc/UnitsTool#5
Open
@koploop
koploop commented 7 days ago
For me this problem appear with React Native 0.68 and JDK 11

i hava checked the jsBundleDirRelease (in build.gradle) and the bundle exist,so
why ?
im a little confused and depressed when my last project solved many build problems
finaly published to store but when create a new project use npx react-native init
xx,new problem appear...

@abouquet
abouquet commented 5 days ago
Got it working by launching gradlew assemble twice.

Yes... a bit hacky ...

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


Assignees
No one assigned
Labels
0.62.1
❓Question
Projects
None yet
Milestone
No milestone
Development
No branches or pull requests

40 participants
@airowe
@mikejurka
@wilsolutions
@evelant
@brownieboy
@abouquet
@code-by
@ithustle
@jstheoriginal
@mrbrentkelly
@samuthekid
@lucasbento
@mouhsnimohamed
@felipezf
@duncte123
@foxbit19
@koploop
@Stas-Buzunko
@jamesone
@hanifmhd

You might also like