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

assembleRelease generates a functional apk only if index.android.bundle is located in main/assets directory #30140

Closed
sammysium opened this issue Oct 8, 2020 · 6 comments
Labels
Needs: Triage 🔍 Platform: Android Android applications. Platform: Linux Building on Linux. Stale There has been a lack of activity on this issue and it may be closed soon. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.

Comments

@sammysium
Copy link

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

I have been at this for hours now and not getting anywhere. when I do ./gradlew assembleRelease and install the apk in my device, it crushes on load with the error "run metro or make sure index.android.bundle is packaged".

During the build process, I can see the bundle in generated and intermedite directories but not sure if they have any effect. If I copy either of the bundle to my main/assets/ directory and run assembleRelease again, the apk works fine.

Sure, if i do react-native bundle command before hand, it will also work. But I am curios what is the point of the bundle files in the build directory if they don't get included in the apk?

Looking at react.gradle file, I did notice jsBundleDirRelease is not used and the bundles are hard coded to be generated in generated and intermediate directories.

Is there away to copy the bundle into the apk without running react-native apk first? There must be a reason the bundle files are created when assembleRelease is run.

React Native version:

System:
OS: Linux 5.4 Ubuntu 18.04.5 LTS (Bionic Beaver)
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Memory: 1.85 GB / 15.52 GB
Shell: 4.4.20 - /bin/bash
Binaries:
Node: 14.5.0 - ~/.nvm/versions/node/v14.5.0/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.6 - ~/.nvm/versions/node/v14.5.0/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 11.0.8 - /usr/bin/javac
Python: 2.7.17 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: ^0.63.1 => 0.63.1
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. create a new react-native app
  2. generate keystore and configure your release build
  3. run ./gradlew assembleRelease
  4. run the app in a device

Expected Results

I expected assembleRelease to package the index.android.bundle it creates and package it in the apk

Snack, code example, screenshot, or link to a repository:

Please provide a Snack (https://snack.expo.io/), a link to a repository on GitHub, or provide a minimal code example that reproduces the problem.
You may provide a screenshot of the application if you think it is relevant to your bug report.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

@react-native-bot react-native-bot added Platform: Android Android applications. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used. Platform: Linux Building on Linux. labels Oct 8, 2020
@dlarrain
Copy link

dlarrain commented Dec 2, 2020

Same issue here, have you solved it?

@liamyu
Copy link

liamyu commented Mar 7, 2021

Same here, I started experiencing this problem after upgrading android gradle plugin to 4.1.2. It only happens when it's a clean build, after that it seems to be working again. According to the documentation:

Note: Make sure gradle.properties does not include org.gradle.configureondemand=true as that will make the release build skip bundling JS and assets into the app binary.

But even if I set org.gradle.configureondemand=false, this problem persists. It would be a lifesaver if anyone could provide any insights.

@liamyu
Copy link

liamyu commented Mar 7, 2021

For anyone encountering the same problem, this issue has been fixed: #30177

@mrbrentkelly
Copy link
Contributor

Is this supposed to be fixed in React Native 0.64? I see that #30177 is merged and I believe I can see the fix in my local react.gradle, but I'm still experiencing the issue even with a fresh project:

Steps to reproduce:

  • npx react-native init SomeProject
  • Open project in Android Studio
  • Choose "Build > Generate Signed Bundle / APK"
  • Choose "APK" and generate an APK for release variant using the debug.keystore
  • Drag generated APK on to a running emulator
  • App crashes on launch (error below)
java.lang.RuntimeException: Unable to load script. Make sure you're either running Metro (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)

Here's my output from react-native info

info Fetching system and libraries information...
System:
    OS: macOS 11.1
    CPU: (8) x64 Apple M1
    Memory: 48.61 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.1 - ~/.nvm/versions/node/v14.16.1/bin/node
    Yarn: Not Found
    npm: 6.14.12 - ~/.nvm/versions/node/v14.16.1/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK:
      API Levels: 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.3
      System Images: android-30 | Google APIs ARM 64 v8a, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.7199119
    Xcode: 12.4/12D4e - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.0 => 0.64.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 16, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Platform: Android Android applications. Platform: Linux Building on Linux. Stale There has been a lack of activity on this issue and it may be closed soon. Tech: Bundler 📦 This issue is related to the bundler (Metro, Haul, etc) used.
Projects
None yet
Development

No branches or pull requests

5 participants