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

后端 未结 30 3517
鱼传尺愫
鱼传尺愫 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 06:57

    I've had this same issue for a number of months now. I initially used @Jerry's solution however, this was a false resolution as it didn't fully fix the problem. Instead, what it did was take every build as a production build meaning that any slight change you made in the app would mean that rebuilding the entire app is necessary.

    While this is a temporal solution, it works horribly in the long term as you are no longer able to avail of React Native's amazing development tools such as hot reloading etc.

    A proper solution is a shown:

    In your MainApplication.java file, replace the following:

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

    with

    @Override
    public boolean getUseDeveloperSupport() {
        return true;
    }
    

    as for some reason BuildConfig.DEBUG always returned false and resulted in a bundle file in the assets directory.

    By manually setting this to true, you're forcing the app to use the packager. This WON't work in production so be sure to change it to false or the default value.

    Don't forget also to run

    $ adb reverse tcp:8081 tcp:8081
    

提交回复
热议问题