React Native 之遇坑填坑系列(长期更新)

一、react-native run-android

Unable to load script from assets ‘index.android.bundle’. Make sure your bundle is packaged correctly or you’re running a packager server
具体错误:

java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
                                                       at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:32)
                                                       at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:243)
                                                       at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1116)
                                                       at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:117)
                                                       at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:916)
                                                       at java.lang.Thread.run(Thread.java:818)

网上查相关异常,都是这种的

1.在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

都不是我想要的答案,因为我要“摇一摇”可以进行重新加载JS以及调试的。最后功夫不负有心人,终于被我找到原因了,就是:
React Native 之遇坑填坑系列(长期更新)

React Native 之遇坑填坑系列(长期更新)

明白了没有,我就是导入了 com.facebook.react,所以导致一直报这个异常,真坑啊。

二、Git bash Error: Could not fork child process: There are no available terminals (-1)

在使用Git时出现如下错误

1, 在dos窗口中输入tasklist 查看 git-bash.exe进程,找到对应的进程号PID,如图:git-bash.exe的进程号为:6444

2,tasklist|findstr 6444是找到进程号对应的进程

3,taskkill /pid 6444 -t -f 是终止相应进程号为6444的命令,终止后,即可打开git bash 终端

React Native 之遇坑填坑系列(长期更新)

三、React Native 横竖屏监听问题(react-native-orientation)

设置了监听,却不起作用的问题

 componentDidMount() {
    Orientation.addOrientationListener(this._orientationDidChange);
  },

  _orientationDidChange = (orientation) => {
    if (orientation === 'LANDSCAPE') {
      // do something with landscape layout
    } else {
      // do something with portrait layout
    }
  },

记得在我们的MainActivity中重写横竖屏监听的方法,发送广播

  import android.content.Intent; // <--- import
    import android.content.res.Configuration; // <--- import

    public class MainActivity extends ReactActivity {
      ......
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Intent intent = new Intent("onConfigurationChanged");
        intent.putExtra("newConfig", newConfig);
        this.sendBroadcast(intent);
    }

      ......

    }