question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JS bundle isn't included in Android production build with Gradle 3.4

See original GitHub issue

React Native version: 0.59.8

Steps To Reproduce

  1. Open Android-Studio and update com.android.tools.build:gradle to 3.4.1 in the main Gradle file
  2. Sync Gradle
  3. Try to build an APK and install it on an Android Simulator (adb install)
  4. See the app crash
  5. Run adb logcat to get the logs of the Android Simulator
  6. See the exception saying Unable to load script from assets 'index.android.bundle'

I encountered the issue and it was fixed by downgrading to 3.3 (see this reply).

Reason of the issue

The explanation in this comment:

Apparently, Gradle 3.2.0 changed the location to which it generates asset bundles. RN expects its JS asset bundle to be in a specific path, which is the path used by Gradle 3.1.4. Because G3.2.0 puts them in a different spot, RN cannot find the JS asset bundle, and thus the files with the Javascript to run. Ergo, the crash in release mode.

Possible fix

I think it would be a good idea to change the default JS bundle path in react.gradle.

WDYT? If this is a good fix, I’d be happy to try and implement it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
wildseansycommented, May 20, 2019

My workaround for this was to move the index.android.bundle from app/build/generated to app/src/main/assets, and then run gradle again to bundle this in.

Do this at your own risk, it definitely took some pain to figure this out, and may have unforeseen consequences

I run this to generate a release:

# Run in android directory:
rm -rf ./app/build/outputs/apk/production
rm -rf ./app/build/generated/assets
./gradlew assembleRelease
cp ./app/build/generated/assets/react/production/release/index.android.bundle ./app/src/main/assets/index.android.bundle
./gradlew assembleRelease
1reaction
guhungrycommented, Sep 15, 2019

It was fixed in 0.59 so you have to upgrade React Native or search for workaround which i can’t remember where i found it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-native android bundle is not loading the assets for release
I've tried updating gradle and updating react-native, but neither seems to help. I'm not sure what to try at this point. com.android.tools.build ......
Read more >
Android Gradle plugin release notes - Android Developers
If the specified plugin version has not been downloaded, Gradle downloads it the next time you build your project or click File >...
Read more >
Installation - Gradle
Install the Gradle build tool on Linux, macOS or Windows, either manually or using a package manager like SDKMAN! or Homebrew.
Read more >
Bundling React Native during Android release builds
Looking into the react-native directory reveals a Gradle file that defines a bundling task. This is the react.gradle file that is mentioned in...
Read more >
Android Platform Guide - Apache Cordova
Android Platform Guide. This guide shows how to set up your SDK environment to deploy Cordova apps for Android devices, and how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found