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

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

    I had issue with McAfee on my mac blocking port 8081, had to change it to 8082.

    First run your package server:

    react-native start --port 8082
    

    Open another terminal, start the android app as usual:

    react-native run-android
    

    Once it finishes, now rewrite the tcp port that adb tunnels:

    adb reverse tcp:8081 tcp:8082
    

    See the list of adb tcp tunnels:

    adb reverse --list
    

    You should now see a heartwarming message:

    (reverse) tcp:8081 tcp:8082
    

    Go to your app and reload, done!

    PS: Don't change anything in the app Dev settings, if you added "localhost:8082", just remove it, leave it blank.

    EDIT: To all the McAfee victims out there, there's easier solution if you have root access, just temporarily kill the McAfee process sitting on port 8081 and no need for port change at all:

    sudo launchctl remove com.mcafee.agent.macmn
    
    0 讨论(0)
  • 2020-11-22 07:01

    It may be caused by unlinked assets in your React Native project code base, like when you renames your project application/bundle id or adds an external package without link it properly, for example.

    Simply try it in your project root directory:

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

    For all of you guys who are developing from a create-react-native-app and ejected, and have this issue in development, this is what worked for me just a little detail from the accepted answer

    (in project directory) mkdir android/app/src/main/assets

    here comes the part that changes cos you are in development get rid of the --dev: false part:

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

    after that close all terminals, erase the build folder from android/app/ to make sure you start clean to build your app, open a new terminal, and

    (in project directory) npm run android

    will prompt the packager console (in another terminal) and build successfully

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

    For this problem I just solve it by running:

    react-native start
    

    then

    adb reverse tcp:8081 tcp:8081
    

    on command line. And then i can run:

    react-native run-android
    

    So i will not waste my time to run:

    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
    

    every time.

    0 讨论(0)
  • Ubuntu

    first time, I created new app with react-native init project-name. I got the same error. so i do the following steps to resolve this in my case.

    1. Firstly run sudo chown user-name-of-pc /dev/kvm in my case.
    2. While debugging from your Android phone, select Use USB to Transfer photos (PTP).

    3. Create Folder assets in project-name/android/app/src/main

    4. make sure index.js be avaiable into your project root directory and then run below command from console after cd project-name directory.

    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

    or for index.android.js then

    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. run command ./studio.sh in android-studio/bin directory. It will opens up Android Studio.

    2. run command react-native run-android.

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

    In my case, I have removed below line from MainApplication.java. (Which is previously mistakenly added by me.):-

    import com.facebook.react.BuildConfig;

    After that Clean Project and hit command

    react-native run-android

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