Unable to load script from assets index.android.bundle on windows

后端 未结 30 3561
鱼传尺愫
鱼传尺愫 2020-11-22 06:33

I\'m trying to run my first React Native project for first time on my device (Android 4.2.2).

And I get:

unable to load script from assets in

相关标签:
30条回答
  • 2020-11-22 07:07

    I was also facing this problem because when I run projects on the emulator its working fine but on a real device it gives this error. So I resolve this problem by the following solution

    1st step: First of all open cmd and go to your SDK manager Platform-tools folder

    cd C:Development\Android\Sdk\Platform-tools
    

    2nd step: now run this command :

    adb devices
    

    after this command check your device listed in command prompt

    3rd step: now run this

    adb reverse tcp:8081 tcp:8081
    

    Now your setup is done

    4th step: Go to your project directory and run this command

    react-native run-android
    
    0 讨论(0)
  • 2020-11-22 07:07

    Make sure that you have added /path/to/sdk/platform-tools to your path variable.

    When you run react-native run-android, it runs adb reverse tcp:< device-port > tcp:< local-port > command to forward the request from your device to the server running locally on your computer. You will see something like this if adb is not found.

    /bin/sh: 1: adb: not found
    Starting the app (.../platform-tools/adb shell am start -n 
    com.first_app/com.first_app.MainActivity...
    Starting: Intent { cmp=com.first_app/.MainActivity }
    
    0 讨论(0)
  • 2020-11-22 07:08

    For IOS:

    In a terminal:

    cd ios
    

    Remove the build folder with: rm -r build

    Run again: react-native run-ios

    Alternatively, you could open Finder, navigate to YOUR_PROJECT/ios and delete the build folder.

    Then run again: react-native run-ios

    For ANDROID:

    In a terminal:

    cd android/app
    

    Remove the build folder with: rm -r build

    Run again: react-native run-android

    Alternatively, you could open Finder, navigate to YOUR_PROJECT/android/app and delete the build folder.

    Then run again: react-native run-android

    0 讨论(0)
  • 2020-11-22 07:08

    This is a general error message, you may have encountered during the react native application development. So In this tutorial we are going to provide solution to this issue.

    Issue Description : Unable to load script from assets index.android.bundle on windows Unable to load script from assets index.android.bundle on windows

    Follow the below steps to solve above issue :

    Step-1 : Create "assets" folder inside your project directory Now create assets folder inside the project directory that is "MobileApp\android\app\src\main". You can manually create assets folder :

    < OR >

    you can create folder by using command as well. Command : mkdir android/app/src/main/assets

    Step-2 : Running your React Native application Lets run the below command to run the react native application in emulator or physical device.

    Switch to project directory. cd MobileApp

    Run the below command that helps to bundle you android application project.

    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

    Run the Final step to run react native application in emulator or physical device. react-native run-android

    < OR >

    Also you can combine last two command in one, In this case case you have to execute command only once.

    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

    < OR >

    You can automate the above steps by placing them in scripts part of package.json like this:

    "android-android": "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"

    If everything is set up correctly, you should see your new app running in your Android emulator shortly.

    0 讨论(0)
  • 2020-11-22 07:08

    I have just encounterred exactly the same problem and solved it. So hope to be helpful.

    Suppose you are assemblling a release application package (.apk)

    1. Check if your assets folder exist?: \android\app\src\main\assets If not, create one.

    2. After executing "Assemble Release", check if there is anything in that folder(\android\app\src\main\assets) If not, find js bundle file(index.android.bundle), which should be in more than one of the following paths:

      *a)\android\app\build\intermediates\merged_assets\release\out\index.android.bundle

      b)\android\app\build\intermediates\merged_assets\release\mergeReleaseAssets\out\index.android.bundle

      c)\android\app\build\intermediates\assets\release\index.android.bundle

      d)\android\app\build\generated\assets\react\release\index.android.bundle*

    A better way is to use "Everything" to search the file name: index.android.bundle.

    1. Then copy this file into your assets folder(\android\app\src\main\assets\index.android.bundle)

    2. Go back to powershell or command console, execute:

    react-native run-android --variant=release

    It should work.

    Good luck!

    0 讨论(0)
  • 2020-11-22 07:08

    I am facing this issue, lot of search and I resolved that issue.

    c:\ProjectFolder\ProjectName> 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

    Than Run the react native :

    c:\ProjectFolder\ProjectName>react-native run-android

    0 讨论(0)
提交回复
热议问题