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

后端 未结 30 3563
鱼传尺愫
鱼传尺愫 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:09

    If you are using Windows run the commands in the following way, or if you get an error "Cannot find entry file index.android.js"

    1. mkdir android\app\src\main\assets
    2. 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

    3. react-native run-android

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

    1 Go to your project directory and check if this folder exists android/app/src/main/assets

    1. If it exists then delete two files viz index.android.bundle and index.android.bundle.meta
    2. If the folder assets don'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 calledindex.js

    • 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

    • 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

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

    You can follow the instruction mentioned on the official page to fix this issue. This issue occur on real device because the JS bundle is located on your development system and the app inside your real device is not aware of it's location.

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

    I think you don't have yarn installed try installing it with chocolatey or something. It should be installed before creating your project (react-native init command).

    No need of creating assets directory.

    Reply if it doesn't work.

    Edit: In the recent version of react-native they have fixed it. If you want complete freedom from this just uninstall node (For complete uninstallation Completely remove node refer this link) and reinstall node, react-native-cli then create your new project.

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

    when I update react-native to 0.49.5, this problem appears and when I followed this Breaking changes and deprecations

    it disappeared.

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

    I have faced the same problem with a real android device.

    Solution: Based on this answer by Niltoid

    1. Find your local IP
    2. Open app and shake your Android device
    3. Go Dev Setting and>Debug Server...
    4. Paste your IP and port; X.X.X.X:8088" (where X's are your local IP)

    for Mac user: open your network preference, here you will get your local IP.

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