Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thib92 opened this issue May 20, 2019 · 10 comments
Closed

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

thib92 opened this issue May 20, 2019 · 10 comments
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@thib92
Copy link
Contributor

thib92 commented May 20, 2019

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.

@thib92 thib92 added the Bug label May 20, 2019
@react-native-bot react-native-bot added Platform: Android Android applications. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. labels May 20, 2019
@wildseansy
Copy link
Contributor

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

@thib92
Copy link
Contributor Author

thib92 commented May 20, 2019

@wildseansy I’ve seen this workaround as well, but I’m not a big fan as you’re adding a bundle to the src directory, which is in source control, which mean you have to modify your gitignore file etc.

@wildseansy
Copy link
Contributor

wildseansy commented May 20, 2019

@thib92 - for sure. I just haven't found a better way yet, and downgrading will come at a cost to me after having integrated some React Hooks. Hope this can be resolved 👍

@thib92
Copy link
Contributor Author

thib92 commented May 20, 2019

I use hooks in my app and downgrading to Gradle 3.1.4 didn't cause any problem 😊
But anyway I think it would be great if this could be fixed on the RN side!

@wildseansy
Copy link
Contributor

Ah, I see - I had assumed downgrading Gradle would mean also bumping RN down, which would cascade to React being bumped down.

@thib92
Copy link
Contributor Author

thib92 commented May 20, 2019

Fortunately it doesn't look like it 😄

@guhungry
Copy link
Contributor

guhungry commented May 22, 2019

Duplicated with #24854
As #24854 (comment) said it was fixed in master.

@thib92
Copy link
Contributor Author

thib92 commented May 22, 2019

@guhungry I didn’t see it had been fixed on master! Thanks!

@anmol-appzoy
Copy link

Hi folks, having the same issue with react-native - 0.58.6 and Gradle version - 4.7. Can someone please look into the issue and help me out in this.

@guhungry
Copy link
Contributor

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.

@facebook facebook locked as resolved and limited conversation to collaborators May 22, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests

5 participants