react native运行程序错误解决办法集合

1.cd 到项目目录里面
2、连接模拟器 adb connect 127.0.0.1:7555,7555是端口号,不同的模拟器端口号不一样
3、运行程序 ,输入命令: react-native run-android,如果报错无法识别这个命令,则需要npm


报错问题集合
问题1: unable to load script from assets 'index.android.bundle'.Make sure your bund is packaged correctiy or you're running a packager server.

解决办法1:
第一步:在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/
运行完毕后assets文件夹下会多出index.android.bundle和index.android.bundle.meta两个文件
第三步:重新运行程序完美解决。
总结: 
index.android.bundle是用来调用原生控件的js脚本,每次当改变了 index.android.js,都需要使用上面的代码片段,来及时的更新index.android.bundle,然后打包才可以把新的index.android.js应用上,所以当没有index.android.bundle文件时,React-Native 项目是无法运行的。

解决办法二:设置虚拟机连接的服务ip

1.点击虚拟机的“menu”键,

2.选择“Dev Setting”
点击上图中的,设置为本机的ip地址和端口
然后执行“react-native run-android”命令。


问题2:
解决办法:换node_moudle文件夹

问题3:

命令: npm cache clean -- force
rm -rf node_modules
删除android\app文件夹下的build文件夹。

问题4:cannot add a child that doesn't have a YogaNode to a parent without a measure function!

检查</>是否有不配对的。


问题5:react-native run-android运行报错“Could not expand ZIP”
解决办法:
cd android
gradlew clean
cd ..
react-native run-android

问题6:app:transformClassesWithDexForDebug

解决办法:观察在运行react-native run-android 时,停在app:transformClassesWithDexForDebug时提示信息,表示gradle内存不够,我遇到时提示是设置 org.gradle.jvmargs=-Xmx1536m。(修改gradle.properties文件)

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值