react native bundle读取assets_react-native 初始化的坑

问题一:

在通过官方的一系列流程安装完毕之后

react-native init FirstApp
cd FirstApp

项目目录下只有以下两个文件:

v2-e446b21a539d4dba68fba05b02f46ed3_b.jpg


这个是什么原因呢?
因为近期rn更新,某些东西不适配,然后暂时能找到的方法就是指定较低版本的rn。

解决方案:

react-native init FirstApp --verbose --version 0.53.0

运行完之后的项目目录

v2-6a8ff706e9292ecfa03cecb1a25b423a_b.jpg

问题二:

在新建项目完毕之后:
运行:

react-native run-ios

出现:

v2-4bddfeb9c3bdaf4dc2d398f0ce43fea5_b.jpg

查找资料后发现原来是升级后watchman不可用了,需要重装watchman。
解决方案:

brew link autoconf automake
brew install watchman

然后在运行:

react-native run-ios

成功:

v2-aef3abf3c83e32d18784643cc1fb736c_b.jpg

问题三:

运行:

react-native run-android

❌出现以下错误:

Could not get BatchedBridge, make sure your bundle is packaged correctly

解决方案:执行以下命令

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/

如果报错在android/app/src/main/目录新建文件夹叫 assets ,在执行一遍上面的代码,
然后在启动 react-native run-android 就可以啦
成功(真机测试):

v2-e964c5e360a4013eead2ec78dfbb4520_b.jpg

问题四:

运行react-native run-android 出现

❌Could not install the app on the device, read the error above for details.

Make sure you have an Android emulator running or a device connected and have

set up your Android development environment.

Go to https://facebook.github.io/react-native/docs/getting-started.html

and check the Android tab for setup instructions.

解决方案:
在android 文件夹下 build.gradle中

repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'//修改过后
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

在android/app 文件夹下 build.gradle中

compileSdkVersion 23
buildToolsVersion "23.0.1"//修改过后

然后再运行就没有问题啦

简书地址: https://www.jianshu.com/p/3a09ad4e28f2
更新日期: 2018.09.06 15:25

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值