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

"Unable to load script from assets 'index.android.bundle'..." #269

Closed
kpolley opened this issue Jan 20, 2018 · 42 comments
Closed

"Unable to load script from assets 'index.android.bundle'..." #269

kpolley opened this issue Jan 20, 2018 · 42 comments

Comments

@kpolley
Copy link

kpolley commented Jan 20, 2018

When I follow the instructions here for Android, I immediately receive the error "unable to load script from assets 'index.android.bundle' as shown in the screenshot. I have refreshed my project and followed the instructions closely several times. My project runs fine until I try to link Lottie. Any idea why I am getting this error?

screenshot_1516491511

@bluesea
Copy link

bluesea commented Jan 22, 2018

The name in the "package.json" is wrong. Change it into: "name": "example"

@deva11
Copy link

deva11 commented Feb 1, 2018

Do this For the first Time in your project root folder
Step 1 :
mkdir android/app/src/main/assets

Step 2:

react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

Step 3 :
react-native run-android

From next time on wards, need to follow the Step 2 in order to update the bundle before you run on device.

@vshalvaghasiya
Copy link

same error give me solution ?

@Bimantoro
Copy link

just edit "package.json" file, and add this code
"android-linux": "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 && react-native run-android"

@gpeal
Copy link
Collaborator

gpeal commented Feb 12, 2018

I don't think this is lottie specific.

@gpeal gpeal closed this as completed Feb 12, 2018
@sabbyt54
Copy link

sabbyt54 commented Mar 8, 2018

I think it is related to this module. App was working fine and installed this module following the specified instructions and now app crashes on android. No failures on building and installing the apk, but crash on app load.

Running lottie-react-native@2.2.7 on react-native@0.53.3

@akbarsha03
Copy link

akbarsha03 commented Mar 8, 2018

If anyone gets any errors on running react-native run-android do use yarn before the command @vkgraphics

@AzizUrRehman1
Copy link

you just install app-release.apk and it's work

@giancafigueroa
Copy link

giancafigueroa commented Jun 8, 2018

En linux ejecutar estas linea solucionado

sudo sysctl -w fs.inotify.max_user_instances=1024
sudo sysctl -w fs.inotify.max_user_watches=12288

@Seffah
Copy link

Seffah commented Jun 10, 2018

I was able to resolve this error by firstt disabling my LAN setings from proxy then running the app.
Thus Disable use proxy server for your LAN and now run the app

@morfsys
Copy link

morfsys commented Jul 9, 2018

This post fixes the issue: https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff

@ogechik
Copy link

ogechik commented Jul 20, 2018

@morfsys .... this is perfect thanks(in step one, one has to swap the directories main and src; src first then main)

@morfsys
Copy link

morfsys commented Jul 21, 2018

@Kevin-Ogechi , right. Thank you for pointing out.

@rafaelpadovani
Copy link

Thank you @morfsys this worked perfectly!

@reytum
Copy link

reytum commented Jul 31, 2018

@morfsys you are a lifesaver. Kudos..

@digrase008
Copy link

I was also facing same issue but after upgrading buildToolsVersion = "25.0.3" to buildToolsVersion = "27.0.3" it's working now .

So many time I face the issue just because of buildToolsVersion If I haven't got any proper solution I just start playing with buildToolsVersion and after some time it works fine.
Mostly the app scratching and other related issues are countered by buildToolsVersion but for now the buildToolsVersion = "27.0.3" is working fine for me

@kjjam
Copy link

kjjam commented Aug 23, 2018

in android manifest (/android/app/src/main/AndroidManifest.xml) there must be permission for internet (if you had deleted it) . it worked for me

    <uses-permission android:name="android.permission.INTERNET" />

@LucasShaffer
Copy link

@morfsys

From your root project directory do
cd android && ./gradlew clean

When I do this, I get " '.' is not recognized as an internal or external command, operable program or batch file"

Please advise.

@tobioyelekan
Copy link

@LucasShaffer you can try cd android gradlew clean
what worked for me is cd android and later gradlew clean

@mahendramahi
Copy link

For window user only:-
1>if you are using window then copy the path of adb location and set into Path in your system variable
2> open project structure and delete node module folder.
3> now edit your project package.JSON file
change react-native version "react-native": "0.55.2", and
babel "babel-preset-react-native": "4", after that run "npm install"

4> now re start cmd and js server and run your react native project by "react-native run-android"

@shahbazshoukat
Copy link

Follow this

  1. Go to your project directory and check if this folder exists android/app/src/main/assets
    i) If it exists then delete two files viz index.android.bundle and index.android.bundle.meta
    ii) If the folder assets doesn't exist then create the assets directory there.
  2. From your root project directory do
    cd android && ./gradlew clean
  3. Finally, navigate back to the root directory and check if there is one single entry file called index.js
    i) If there is only one file i.e. index.js then run following command
    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
    ii) If there are two files i.e index.android.js and index.ios.js then run this
    react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  4. Now run react-native run-android

Thanks a lot @morfsys.

@proof-of-reality
Copy link

in android manifest (/android/app/src/main/AndroidManifest.xml) there must be permission for internet (if you had deleted it) . it worked for me

    <uses-permission android:name="android.permission.INTERNET" />

worked for me too

@Jeyasee
Copy link

Jeyasee commented Nov 10, 2018

This error showing due to the missing of below files in project
index.android.bundle
index.android.bundle.meta
We need to create this files using command prompt first.

1)Select project folder in command prompt.
2)make sure , npm is installed.
3)Then check android/app/src/main has assets folder.
4)If does not have asset folder.Then create assets folder in like -->\android\app\src\main\assets
5)Then run below code
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
6)After that successful completion , these two files created in assets folder.

Then debug app normally..

Check screen shots for command prompt reference..
image

@sryze
Copy link

sryze commented Nov 10, 2018

How is it a solution if you have to manually run a command each time? It's just a workaround... a real solution would be making react-native's build script/whatever generate this bundle file automatically when running on Android, like it does for iOS presumably (for iOS I don't have to run any additional commands).

Update:

I found a way to automatically run the bundle script: add this to your app/build.grandle:

project.ext.react = [
    entryFile: "index.js",
    bundleAssetName: "index.android.bundle",
    bundleInDebug: true,
    bundleInRelease: true
]

...

// This has to go AFTER you set project.ext.react properties:
apply from: "../../node_modules/react-native/react.gradle"

Apparently the bundleInDebug: true option tells React Native to build bundle files in debug (development) builds.

But this is still not a solution... ideally the app should connect to the packager server running on localhost, but for at least it doesn't do that, sadly I haven't figured out why 😞

Final update:

For some reason I had import com.facebook.react.BuildConfig; in my MainAplication file (I guess due to some smart ass auto import fixing feature of IntelliJ), and therefore BuildConfig.DEBUG was set to false. Because of this:

    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

React Native was always trying to load index.android.bundle from the app pacakge, not from the dev server. Removing the import com.facebook.react.BuildConfig line fixed the issue for me 🎆 🍺 👍

@HemantSharmaVB
Copy link

To resolve Unable to load script from assets index.android.bundle - React Native follow below process :

You have to create dir assets manually in your android project or make Directory by Terminal/CMD enter mkdir android/app/src/main/assets

Go at the created Directory if that is successfully created then

run step 3 Command:

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
you have your missed files in the folder now you can Run your React Native project npm run android.
i have found working solution from Qna

@ttdat2510
Copy link

enable wifi on emulator devices . it's work for me

@DiegoAron
Copy link

DiegoAron commented Feb 13, 2019

enable wifi on emulator devices . it's work for me

seems stupid but, It works for me

@joseph-perez
Copy link

I was running into the same error when trying to build a release version on a device. I was running react native 0.57.1 and was able to fix my issue by changing the gradle version. More info here facebook/react-native#23739 (comment). Hopefully, the fix I used can fix someone else's build also 😄

@IjzerenHein
Copy link

IjzerenHein commented Mar 15, 2019

For those that are running into this on Android 9 specifically (and don't want any dirty workarounds..), this was fixed in RN59 and requires additional network config to be added to your project.

To solve, add the following files to the android/app/src/debug folder

image

android/app/src/debug/res/xml/react_native_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
  <domain-config cleartextTrafficPermitted="true">
    <domain includeSubdomains="false">localhost</domain>
    <domain includeSubdomains="false">10.0.2.2</domain>
    <domain includeSubdomains="false">10.0.3.2</domain>
  </domain-config>
</network-security-config>

android/app/src/debug/AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools">

  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

  <application tools:targetApi="28"
      tools:ignore="GoogleAppIndexingWarning" 
      android:networkSecurityConfig="@xml/react_native_config" />
</manifest>

Source: https://stackoverflow.com/a/55147267/3785358

@thinklinux
Copy link

@IjzerenHein that's the correct thing to do... while I was updating I probably didn't created that files...

@renishdeveloper
Copy link

http://www.learnandroidcodeonline.com/Blogs/blogs_listing/unable-to-load-script.html
This blog helps to solve this issue.

@evert-smit
Copy link

The network config referred to here is no longer there since 0.59.2
https://github.com/react-native-community/rn-diff-purge/compare/release/0.59.0..release/0.59.2

@suwu150
Copy link

suwu150 commented Sep 22, 2019

@yatendubey
Copy link

When you install the NodeJS using the choco command(choco install -y nodejs.install python2 jdk8), it will install the latest version of node which is 12.12.0 at the time of writing this answer. You have to downgrade it to 10.16.3 and run the react-native run-android command and it should work fine

@Moh3enDev
Copy link

When you install the NodeJS using the choco command(choco install -y nodejs.install python2 jdk8), it will install the latest version of node which is 12.12.0 at the time of writing this answer. You have to downgrade it to 10.16.3 and run the react-native run-android command and it should work fine

worked for me.

@CoSNaYe
Copy link

CoSNaYe commented Apr 11, 2020

enable wifi on emulator devices . it's work for me

God, I can't believe I've stuck at this for hours. Enable Wifi fixes the problem.

@alina-beck
Copy link

alina-beck commented Aug 12, 2020

@sryze even two years later your solution still saved my day! This was the missing hint:

I found a way to automatically run the bundle script: add this to your app/build.grandle:

project.ext.react = [
    entryFile: "index.js",
    bundleAssetName: "index.android.bundle",
    bundleInDebug: true,
    bundleInRelease: true
]

I had a working debug and release build after upgrading to react-native 0.63.2 but my staging build was broken. Adding bundleInStaging: true did the trick! Thank you! 💚 😉

@abbasmoosavi
Copy link

@sryze even two years later your solution still saved my day! This was the missing hint:

I found a way to automatically run the bundle script: add this to your app/build.grandle:

project.ext.react = [
    entryFile: "index.js",
    bundleAssetName: "index.android.bundle",
    bundleInDebug: true,
    bundleInRelease: true
]

I had a working debug and release build after upgrading to react-native 0.63.2 but my staging build was broken. Adding bundleInStaging: true did the trick! Thank you! 💚 😉

Very thank you, Safe my life, it is worked for me

@bernica
Copy link

bernica commented Oct 6, 2020

What if one wants to debug staging? How should I make it work like debug?

@mouhsnimohamed
Copy link

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.

@khiemnoob
Copy link

You have to create dir assets m

seem stupid but it works for me

@9christian9
Copy link

Ciao,
I'm writing for all the people who, like me, have experienced this problem.

Affected Versions

  • React Native: 0.67.x
  • Gradle 7.2.x - 7.3.x

The common error

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.

In short, index.android.bundle is missing
Common problem when trying to use productFlavors

The problem
I found that the problem is in a native react gradle task, to be precise in the copy task called currentAssetsCopyTask located in react.gradlefile.
As I understand, this "task" is responsible for copying the assets and in particular index.android.bundle and pasting them into the temporary directories used to generate the APK.

The solution
I created a repo that with a js script solves the problem before building the android app
https://github.com/9christian9/FIX-Android-productFlavors-RN0.67-gradle7.2-7.3

I hope this will help.
With ♥ by Christian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests