参考文章
http://reactnative.cn/docs/getting-started.html
http://www.lcode.org/react-native/
https://github.com/tmallfe/tmallfe.github.io/issues
选定window 2012 x64作为测试os
安装jdk1.8 for window x64 设置window环境变量JAVA_HOME安装android sdk ,设置window的ANDROID_HOME环境变量安装android studio2.0安装node.js5.0使用avd启动android模拟器
创建测试项目
初始化npm install -g react-native-cli创建项目react-native init AwesomeProject手工启动测试服务
react-native start进入项目并编译apk,安装到模拟器
cd C:\AwsomeProjectreact-native run-android修改android的入口文件C:\AwsomeProject\index.android.js, 使用模拟器的右键菜单,点击reload js
提示
Building and installing the app on the device (cd android && gradlew.bat installDebug)...C:\Android\sdk\/platform-tools/adb shell am start -n com.awsomeproject/.MainActivity 发布.发布打包了js等文件打包生成前key文件准备
1.使用android studio generate signed apk生成key文件my-release-key.keystore.jks2.把生成的key文件放在C:\AwsomeProject\android\app下3.在gradle.properties文件添加如下配置 MYAPP_RELEASE_STORE_FILE=my-release-key.keystore.jks MYAPP_RELEASE_KEY_ALIAS=my-key-alias MYAPP_RELEASE_STORE_PASSWORD=123456 MYAPP_RELEASE_KEY_PASSWORD=1234564.在C:\AwsomeProject\android\app\build.gradle文件添加如下 signingConfigs { release { storeFile file(MYAPP_RELEASE_STORE_FILE) storePassword MYAPP_RELEASE_STORE_PASSWORD keyAlias MYAPP_RELEASE_KEY_ALIAS keyPassword MYAPP_RELEASE_KEY_PASSWORD } }buildTypes {
release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" signingConfig signingConfigs.release } } 并把enableProguardInReleaseBuilds设置为true ,如下 def enableProguardInReleaseBuilds = true打包生成appC:\AwsomeProject\android>gradlew assembleRelease重装app
C:\AwsomeProject\android\app\build\outputs\apk>C:\Android\sdk\platform-tools\adb install -r app-release.apk