我们在开发RN过程中难免会遇到一些错误,下面是本人遇到过的一些,记录下来,方便大家尽快解决问题:
1.The development server returned response error code:404http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false
检查手机是否联网
打开调试模式,Dev Setting,点击Debug server host & port for device,添加localhost:8081
- unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager server
第一步:在Android/app/src/main目录下创建一个空的assets文件夹,
第二步:进入项目根目录执行下面代码:
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/
注:
index.android.bundle是用来调用原生控件的js脚本,每次当改变了 index.android.js,都需要使用上面的代码片段,来及时的更新index.android.bundle,然后打包才可以把新的index.android.js应用上,所以当没有index.android.bundle文件时,React-Native 项目是无法运行的。 新版本目录下没有index.android.js和index.ios.js,所以会出现Cannot find entry file index.android.js 使用index.js替换即可
3.
Error:Execution failed for task ‘:app:transformNativeLibsWithStripDebugSymbolForDebug’.
A problem occurred starting process ‘command ‘/Users/sunhangxing/Library/Android/sdk/ndk-bundle/toolchains/mips64el-linux-android-4.9/prebuilt/darwin-x86_64/bin/mips64el-linux-android-strip”
新版NDK更改了文件目录导致找不到,在Androidstudio中关掉ndk的路径即可
4.Packager can’t listen on port 8081
Most likely another process is already using this port
已经起了一个服务,不需要重新启动或者该端口被占用
5.RN项目中调用view的layout方法无效或者页面不刷新问题
RN重写了Android的onLayout等方法,导致原生的直接调用无效,需要重写该方法