react-native 最新版本爬坑经历(unable to load script from assets 和could not connect to development server.)

转载地址:https://blog.csdn.net/jasonzds/article/details/78747524

 

新建项目

react-native init TestApp
1
运行项目

react-native run-android
1
不好意思,错误马上就到了

错误1:unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager server

解决办法 
1,在 android/app/src/main 目录下创建一个 assets空文件夹

mkdir android/app/src/main/assets
1
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/
1
注意了,是编译index.js而不是index.android.js,因为react-native新版本已经没有index.android.js和index.ios.js两个文件了,只有一个index.js文件,所以要编译index.js 
会发现 assets文件夹下多出两个文件

index.android.bundle      index.android.bundle.meta
1
3,重新react-native run-android

*错误2:could not connect to development server. 
Try the follwing to fix the issue:* 


解决办法: 
重新编译index.js文件(走一遍错误一中的第2部),在重新运行react-native run-android

双击R键刷新android模拟器

另外运行ios时,如果想指定某个模拟器 
react-native run-ios –simulator “iPhone X”

查看iOS设备:在终端中输入 
xcrun simctl list devices

 

使用ADB查看设备,输入命令后会显示电脑连接的设备

adb devices
如果没有显示任何信息,检查自己的设备是否连接成功。

如果手机始终无法连接电脑,可以尝试安装豌豆荚等软件。如果不想安装多余软件,可以尝试物理解决方案

物理解决方案(亲测有效):

1.尝试另一个USB 接口

2.换另一根数据线
 ———————————————— 
版权声明:本文为CSDN博主「Sophie.Yuan」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/y443950058/article/details/83348197


--------------------- 
作者:_摩西_ 
来源:CSDN 
原文:https://blog.csdn.net/jasonzds/article/details/78747524 
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值