最近想写个App,又觉得Native App 太无趣了Web App又没那么成熟然后发现了Facebook在9月发布的React Native比较新奇,所以决定捣鼓看看;

  React Native为Facebook开源的使用Javascript与React开发Android、IOS原生跨平台App,React也是Factbook开源的JS框架使用了虚拟DOM的概念,Factbook自己的应用如Groups也是基于React Native在国内也有淘宝iPad版本是哟个了React Native;

  React Native最早支持的是Mac,for Android windows的支持9月份才刚发布还存在不少坑;

基本环境安装

  开发Android App当然首先要安装:JDK、Android SDK配置好JDk、SDK环境变量;

  安装C++编译环境(可以选择Visual Studio 或mingw等),编译nodejs的C++模块会使用;

  安装git、安装Node.js环境;

React-Native 安装

  如果没有VPN最好设置npm镜像不然及其考验你的耐性

npm config set registry https://registry.npm.taobao.org

安装 React-Native

npm install -g react-native-cli

创建项目

进入你希望项目存放的工作目录,运行

react-native init HelloWorld



请耐性等待,第一次下载依赖会比较久;

运行packager

npm start或react-native start

  查看 http://localhost:8081/index.android.bundle?platform=android 是否能打开;

  启动模拟器,运行adb devices查看是否设备已连接上;

保持packager开启,另外打开一个命令行窗口,然后在工程目录下运行

运行React Native

react-native run-android

异常

A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.android.support:appcompat-v7:23.1.1.

解决方案:安装Android Support Repository与Android Support Library

如没有VPN要耐性等待,gradle下载一些依赖。

运行成功

生成APK

进入项目目录进入Android目录,在命令行运行:

gradlew assembleRelease

在React-native 0.14.2版本的时候会存在两个坑,应该算是Bug;

在https://github.com/danhanfry/react-native-windows-apk发现了解决方案;

坑 1:

> A problem occurred starting process 'command 'react-native''

解决方案:进入项目目录》android目录》app目录打开react.gradle文件

在文件头加入:import org.apache.tools.ant.taskdefs.condition.Os

找到

commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug

修改为:

 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "cmd", "/c", "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
} else {
commandLine "react-native", "bundle", "--platform", "android", "--dev", "true", "--entry-file",
entryFile, "--bundle-output", jsBundleFileDebug, "--assets-dest", resourcesDirDebug
}

找到:

commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease

修改为:

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "cmd","/c", "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
} else {
commandLine "react-native", "bundle", "--platform", "android", "--dev", "false", "--entry-file",
entryFile, "--bundle-output", jsBundleFileRelease, "--assets-dest", resourcesDirRelease
}

坑2:

Execution failed for task ':app:bundleReleaseJsAndAssets'.
> Process 'command 'cmd'' finished with non-zero exit value 1

解决方案:

在HelloWorld\node_modules\react-native\packager\react-packager\src\SocketInterface目录找到index.js文件在40行左右把:

const sockPath = path.join(
tmpdir,
'react-packager-' + hash.digest('hex')
);

修改为:

let sockPath = path.join(
tmpdir,
'react-packager-' + hash.digest('hex')
);
if (process.platform==='win32'){
sockPath = sockPath.replace(/^\//, '')
sockPath = sockPath.replace(/\//g, '-')
sockPath = '\\\\.\\pipe\\' + sockPath
}

生成成功后就可以在:android\app\build\outputs\apk目录下看到生成的apk;

文章首发地址:Solinx

http://www.solinx.co/archives/507

React Native初试:Windows下Andriod环境搭建的更多相关文章

  1. React Native在window下的环境搭建(二):创建新项目

    React Native创建一个新项目: react-native init TestAndroidApp 提示:你可以使用--version参数(注意是两个杠)创建指定版本的项目.例如react-n ...

  2. React Native在window下的环境搭建(一)

    React Native官方开发文档 以下是本人抄录的: 初次接触React Native感觉和React很像,却是有点类似,但不完全是,React Native有自己的组件对象,不过它也自定义的组件 ...

  3. React Native - 1 Windows下的环境配置(Windows+Android)

    参考:https://facebook.github.io/react-native/docs/getting-started.html(要FQ)     网站上建议使用Chocolatey去配环境, ...

  4. Windows下的环境搭建Erlang

    Windows下的环境搭建 Erlang 一.安装编译器 在http://www.erlang.org/download.html下载R16B01 Windows Binary File并安装. 二. ...

  5. Redis在windows下的环境搭建

    Redis在windows下的环境搭建 下载windows版本redis,,官方下载地址:http://redis.io/download, 不过官方没有Windows版本,官网只提供linux版本的 ...

  6. 2017.7.18 windows下ELK环境搭建

    参考来自:Windows环境下ELK平台的搭建 另一篇博文:2017.7.18 linux下ELK环境搭建 0 版本说明 因为ELK从5.0开始只支持jdk 1.8,但是项目中使用的是JDK 1.7, ...

  7. windows下React-native 环境搭建

    公司决定试水react-native,mac审批还没下来,没办法,先用windows硬着头皮上吧. 参考文章: React Native 中文网官方文档 史上最全Windows版本搭建安装React ...

  8. React Native入门教程 1 -- 开发环境搭建

    有人问我为啥很久不更新博客..我只能说在学校宿舍真的没有学习的环境..基本上在宿舍里面很颓废..不过要毕业找工作了,我要渐渐把这个心态调整过来,就从react-native第一篇博客开始.话说RN也出 ...

  9. windows下 react-native环境搭建

    跟着慕课网做案例,搭建rn环境遇到很大问题. 下面说一下: 首先看一下文档:http://reactnative.cn/docs/0.44/getting-started.html#content 注 ...

随机推荐

  1. ThinkPHP项目整合UCenter(一)

    一.准备文件 UCenter_1.6.0_SC_UTF8  二.项目文件位置 a. UCenter_1.6.0_SC_UTF8\upload\ 下 所有文件 复制到项目根目录,并安装UCenter b ...

  2. 容器--Map和AbstractMap

    一.前言 前面我们介绍了Collection接口的定义及一系列实现,并重点介绍了List体系下的一些实现,对于Collection来说,其实还有Set系列同样很重要,但由于Set是依赖于Map实现的, ...

  3. No.010:Regular Expression Matching

    问题: Implement regular expression matching with support for '.' and '*'.'.' Matches any single charac ...

  4. 在VS 2012 配置SDL

    一.链接:http://pan.baidu.com/s/1kVaWteR 密码:zt81 下载两个文件夹.(如果不行就到 SDL官网 https://www.libsdl.org/ 和 SDL2_im ...

  5. 用css 制作三角

    html代码: <div class="div"></div> css代码: .div{ border-top:40px solid #ff0077; bo ...

  6. 25款创新的 PSD 格式搜索框设计素材【免费下载】

    这一次,我们给大家带来的素材是25款很有吸引力的搜索框 PSD 设计,你可以免费下载使用.有时候,搜索框容易被访客忽视,因为其简单和没有吸引力的设计.如果这是你所面对的问题,那么我们会鼓励你去看看在这 ...

  7. MAC下利用Github 、hexo、 多说、百度统计 建立个人博客指南

    1.前期准备: (1)注册github账号 (2)安装xcode (3)安装node.js 2.创建repository: (1)开个github的个人主页,点击创建仓库按钮 New reposito ...

  8. css3选择器(上)

    1.给导航加分割线,左右 .nav li::before,.nav li::after{ content:""; position:absolute; top:14px; heig ...

  9. 给栅格数据添加RasterFunction--自定义渲染方法

    <script type="text/javascript"> /** dojo.require("esri.map"); dojo.require ...

  10. SharePoint 2013 通过HttpModule 管理视图权限

    HttpModule工作原理 HttpModule负责监听HttpRequest,当一个HTTP请求到达HttpModule时,整个ASP.NET Framework系统还并没有对这个HTTP请求做任 ...