react-native 初始化的坑

问题一:

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

react-native init FirstApp
cd FirstApp

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



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

解决方案:

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

运行完之后的项目目录


问题二:

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

react-native run-ios

出现:

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

brew link autoconf automake
brew install watchman

然后在运行:

react-native run-ios

成功:


ios模拟器

问题三:

运行:

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 就可以啦
成功(真机测试):

三星note8真机测试

问题四:

运行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"//修改过后

然后再运行就没有问题啦

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,466评论 25 708
  • 原文地址:https://medium.com/airbnb-engineering/react-native-a...
    莫寂岚阅读 3,337评论 0 9
  • 质疑默认选项,才有可能所有作为。 在《离经叛道》这本书里,有一个很有趣的例子,经济学家迈克尔'豪斯曼,研究了3万余...
    情报师阅读 223评论 0 0
  • 赶雪 朱福宏 半年多没回的老屋也日见沧桑了:桌椅蒙尘,挂画歪斜,早已改变了往日的模样。但院子里的小竹林却日见...
    朱福宏阅读 612评论 0 1
  • 今天就是考研正式确认的日子 没有想象的多么不一只不过是在那张单子上 签个字而已 一如既往 还是那从小到大 签了无数...
    隐形的晴朗阅读 390评论 0 0