基础安装

安装Homebrew

Homebrew是Mac OSX的包管理器,我们需要通过Homebrew安装开发React Native的相关软件包。 如果不知道怎样安装Homebrew可以点这里:官网。根据官网的介绍安装即可。

安装Node.js

$ brew install node

安装watchman

watchman是Facebook用于监视JavaScript文件改动的开源项目。

$ brew install watchman

安装flow

flow是Facebook开源的一个JavaScript静态类型检查器,用于发现JavaScript程序中的类型错误。

$ brew install flow

安装react-native-cli

react-native-cli是React Native的命令行工具,安装react-native-cli后我们就能够通过react-native相关命令管理ReactNative工程。

$ npm install -g react-native-cli

iOS环境安装

相对于Android环境搭建,iOS简单太多了,太easy了!在基础环境安装成功之后,只需去Mac App Store下载Xcode,并安装Xcode即可,首次安装需要打开Xcode初始化。在初始化项目好之后,只需在项目根目录运行下面命令即可:

$ react-native run-ios`

Android环境安装

在Android环境,比较难搞,按照步骤安装即可,不要放过任何步骤哦。

基础软件安装

  1. 安装JDK jdk-8u101-macosx-x64.dmg
  • 查看版本,命令行中运行javac -version
  1. 安装Android Studio
  • 勾选PerformanceAndroid Virtual Device
  • 安装相关SDK Platforms,记得勾选Show Package Details
  • 安装SDK Tools 必须是这个版本 Android SDK Build-Tools 23.0.1,记得勾选Show Package Details
  • ANDROID_HOME环境变量设置。(见下面 环境变量配置)方法
  1. 安装 免费VirtualBox虚拟机
  2. 安装模拟器Genymotion
  • 注册帐号
  • 下载Genymotion
  • 安装Genymotion

环境变量配置

你可以把Android SDKtoolsplatform-tools目录添加到PATH变量中,以便在终端中运行一些Android工具,例如android avd或是adb logcat等。

~/.bash_profile中添加(如果你安装的 ZSH 则在 ~/.zshrc中添加):

PATH="~/Library/Android/sdk/tools:~/Library/Android/sdk/platform-tools:${PATH}"
export PATH=$HOME/bin:/usr/local/bin:$PATH
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:${ANDROID_HOME}/tools

改完需要运行source ~/.bash_profile (注意:你的SDK的具体路径可能不同)

测试服务端

这时候可以用浏览器访问
http://localhost:8081/index.android.bundle?platform=android
如果可以访问表示服务器端已经可以了。

启动步骤

启动 Genymotion 设置

在应用中登录,点击按钮Add下载模拟器设备,在Setting中设置ADB选择User custom Android SDK tools.填写地址,一般在目录/Users/用户名/Library/Android/sdk中,点击按钮Start启动模拟器

 

在启动前需要设置ADB SDK,否则会报错 error: could not install smartsocket listener: Address already in use,解决方法:genymotion的adb设置Android sdk。如下图:

 

运行命令启动项目

进入项目的根目录,也就是有package.json文件的目录,运行react-native run-android启动项目,如下动图:

各种报错

1. error: no devices/emulators found

Could not run adb reverse: Command failed: ~/Library/Android/sdk/platform-tools/adb reverse tcp:8081 tcp:8081

在Android环境下运行,会报下面错误,原因是没有连接手机会报如下错,开发阶段可忽视

2. react-native run-android时出现Could not download imagepipeline.aar

解决方法:修改build.gradle的版本,com.android.tools.build:gradle:2.1.0,改为更高的,然后更改gradle/wrapper/gradle-wrapper.properties中相应的gradle-2.10-all.zip。

3. Undefined symbols for architecture x86_64: “std::terminate()”

解决方法:I ran in to this issue as well, and the solution @charpeni proposed solved the issue. To be clear for others, if you are upgrading to 0.26+ then you need to make the following changes.

In ios/YourProject.xcodeproj/project.pbxproj, look for the two lines like OTHER_LDFLAGS = "-ObjC";. Replace them with the following:

OTHER_LDFLAGS = (
"-ObjC",
"-lc++",
);

4. react-native run-android时出现Could not download imagepipeline.aar

解决方法:修改build.gradle的版本,com.android.tools.build:gradle:2.1.0,改为更高的,然后更改gradle/wrapper/gradle-wrapper.properties中相应的gradle-2.10-all.zip。

5. error: unable to find utility "instruments", not a developer tool or in PATH

 ~/Learning/ReactNative/AwesomeProject:  react-native run-ios
Found Xcode project AwesomeProject.xcodeproj
xcrun: error: unable to find utility "instruments", not a developer tool or in PATH Command failed: xcrun instruments -s
xcrun: error: unable to find utility "instruments", not a developer tool or in PATH

输入sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/然后就可以运行react-native run-ios了。

6. Property 'force' not found on object of type 'UITouch'

出现这种类似错误,只能升级Xcode咯。

7. Ignoring return value of function declared with warn_unused_result attribute

这个报错在此文件中有两处,代码

SecRandomCopyBytes(kSecRandomDefault, sizeof(uint32_t), (uint8_t *)mask_key);

修改为

(void)SecRandomCopyBytes(kSecRandomDefault, sizeof(uint32_t), (uint8_t *)mask_key);

前面加上(void)

8. Use of undeclared identifier '_refreshControl'; did you mean 'refreshControl'?

@implementation RCTCustomScrollView{
__weak UIView *_dockedHeaderView;
RCTRefreshControl *_refreshControl; // 加入此行
}

9. Execution failed for task ':react-native-update:compileReleaseNdk'.NDK not configured.

错误信息

* What went wrong:
Execution failed for task ':react-native-update:compileReleaseNdk'.
> NDK not configured.
Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties.
(On Windows, make sure you escape backslashes, e.g. C:\\ndk rather than C:\ndk)

解决方法:下载安装NDK和相关工具,菜单进入 Tools > Android > SDK Manager 在选项卡中选择 SDK Tools,选择 LLDB, CMake, 和 NDK 勾选,点击 Apply 进行下载安装。

参考资料

原文地址:https://github.com/jaywcjlove/handbook/blob/master/Android/React-native%20Android环境搭建.md

React-native Android环境搭建的更多相关文章

  1. React Native Android 环境搭建

    因为工作需要,最近正在学习React Native Android.温故而知新,把学习的内容记录下来巩固一下知识,也给有需要的人一些帮助. 需要说明的是,我刚接触React Native也不久,对它的 ...

  2. React Native的环境搭建以及开发的IDE

    (一)前言 前面的课程我们已经对React Native的环境搭建以及开发的IDE做了相关的讲解,今天我们的主要讲解的是应用设备运行(Running)以及调试方法(Debugging).本节的前提条件 ...

  3. React Native iOS环境搭建

    前段时间React Native for Android发布,感觉React Native会越来越多的公司开始研究.使用.所以周六也抽空搭建了iOS的开发环境,以便以后利用空闲的时间能够学习一下. 废 ...

  4. Android React Native 开发环境搭建---windows下

    环境搭建 环境搭建可以参考RN官网,也可以参考中文版本:http://reactnative.cn/docs/0.45/getting-started.html 如果你希望可以看到原版的安装流程,可以 ...

  5. win10的react native 开发环境搭建,使用Android模拟器

    1.打开cmd的管理员模式,win+X,选择命令提示符(管理员)即可,运行如下命令: @"%SystemRoot%\System32\WindowsPowerShell\v1.0\power ...

  6. react native的环境搭建中常见问题

    搭建完成android的环境,我们就可以继续我们的react native环境的搭建了. 当然,按照fb的安装流程来完成rn的搭建. http://facebook.github.io/react-n ...

  7. React Native开发环境搭建

    安装Xcode 安装Homebrew 安装Android SDK 安装flow和watchman 安装nodejs 安装react-native-cli 安装Genymotion 安装Webstorm ...

  8. React Native 开发环境搭建

    1.安装 Python 2,不知道是否已支持 Python 3 2.安装 node,npm... 修改 npm 镜像,不建议使用 cnpm,cnpm 安装模块的路径与 npm 有差别 npm conf ...

  9. Window平台下React Native 开发环境搭建

    1. 安装Node.js 2. 安装react-native-cli 命令行工具 npm install -g react-nativew-cli 3. 创建项目 $ react-native ini ...

  10. react-native —— 在Windows下搭建React Native Android开发环境

    在Windows下搭建React Native Android开发环境 前段时间在开发者头条收藏了 @天地之灵_邓鋆 分享的<在Windows下搭建React Native Android开发环 ...

随机推荐

  1. 【Raspberry Pi】修改时区

    Raspberry Pi没有时钟模块,所以每次断电都会丢失时间,但它有联网获取时间的预设.但要修改默认时区 http://outofmemory.cn/code-snippet/2899/shumei ...

  2. RelativeSource.TemplatedParent 属性wpf

    今天看到这一句代码时候,自己只是知道绑定了,可是不知道绑定了什么啊 就去查了一下,后来说的好像是绑定的TemplateParent返回的 一个值.可是这是为什么呢, 有的说是绑定的是一个资源. 下面有 ...

  3. CFontDialog学习

    void CMfcFontDlgDlg::OnBtnFont() { // Show the font dialog with all the default settings. CFontDialo ...

  4. Android中使用OnClickListener接口实现button点击的低级失误

    今天写了几行极为简单的代码,就是想implements  View.OnCLickListener.然后实现按钮点击操作.可是按钮却没有反应.找了五分钟还是没有结果. 下面是我的代码,希望大家不要嘲笑 ...

  5. Domino移动Web上传的附件到RichText域

    只是从网上拷贝下来,没有测试. 得到上传文件的路径http://searchdomino.techtarget.com/tip/Trap-an-attachment-path-via-the-Domi ...

  6. 【BZOJ4367】[IOI2014]holiday假期 分治+主席树

    [BZOJ4367][IOI2014]holiday假期 Description 健佳正在制定下个假期去台湾的游玩计划.在这个假期,健佳将会在城市之间奔波,并且参观这些城市的景点.在台湾共有n个城市, ...

  7. iOS xcode6.0使用7.1运行程序 iphone5上下有黑条

    转自:http://stackoverflow.com/questions/25817562/black-bars-appear-in-app-when-targeting-ios7-1-or-7-0 ...

  8. No transactional EntityManager available; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available

    参考地址:http://docs.spring.io/spring-data/jpa/docs/current/api/org/springframework/data/jpa/repository/ ...

  9. text-align:justify 使用参考

    对 text-align:justify 不大了解的,可以先看这里:从css text-align:justify 谈谈 text-align 文本对齐方式,讲的比较浅显易懂,本篇相对深入些,最好先看 ...

  10. IO流入门-第二章-FileOutputStream

    FileOutputStreamj基本用法和方法示例 /* java.io.OutputStream java.io.FileOutputStream 文件字节输出流 将计算机内存中的数据写入到硬盘文 ...