React-Native 踩过的坑

React Native运行的时候,经常碰到React Native unable to load script from assets index.android.bundle on windows解决方法有2种:

方法一:设置IP和端口

具体步骤:报错页面晃动手机,显示菜单 =》 点击Dev Settings =》 点击Debug server host & port for device =》 设置IP和端口(ex:192.168.0.20:8081)=》 点击返回 =》 页面是空白,再次点击摇一摇,选择Reload JS程序就显示出来了。

如果这种方法还是不行继续往下看。

方法二:原因没有找到assets下文件,需要手动创建并设置

1.首先手动在main下建立一个assets文件夹
2.然后cmd 进入项目的根目录下执行:

1

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.js 不存在,改为index.js(react-native 0.49 之后的版本 已经整合了)

执行语句后 并未产生 index.android.bundle,报 xxx\index.js: Plugin 0 specified in "xxx\\node_modules\\babel-preset-react-native\\index.js" provided an invalid property of "default" (While processing preset: "xxx\\node_modules\\babel-preset-react-native\\index.js") 错,降级babel 版本执行一下两句 解决

执行:

npm unstall babel-preset-react-native

扫描二维码关注公众号,回复: 4906001 查看本文章

npm install --save-dev [email protected]

参考:http://blog.codingplayboy.com/2018/05/19/react_native_babel_error/

https://blog.csdn.net/jasonzds/article/details/78747524

https://www.jianshu.com/p/f0d79bd22e38

有时执行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/ 报下面的错,可能是platform Android 写错,platform android 必须小写。

UnableToResolveError: Unable to resolve module `AccessibilityInfo` 错误

解决:最终解决我困境的方案是

  • 0 准备: 关闭所有dev过程的console 窗口和IDE,Emulator也关了吧
  • 1 删除你的依赖文件夹 node_modules
  • 2 清除npm缓存 $ npm cache clean --force
  • 3 重新安装npm依赖 $ npm install
  • 4 Clean RN 环境并重启试试 $ npm start -- --reset-cache

上面的方法都不行的话,将 react-native 降版本(0.55.4) 解决 

参考:https://www.jianshu.com/p/4c7915812acb

react-native mainapplication.java 错误: 找不到符号

写原生Android java类和React Package时,必须带上 项目package 包名称 package com.awesomeproject;

项目package 包名称目录

xxx\ReactNativApp\项目\android\app\build\generated\source\buildConfig\debug\com\awesomeproject

猜你喜欢

转载自blog.csdn.net/foreverhot1019/article/details/81362455