参考文章
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:\AwsomeProject
react-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.jks
2.把生成的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=123456
4.在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
打包生成app
C:\AwsomeProject\android>gradlew assembleRelease
重装app
C:\AwsomeProject\android\app\build\outputs\apk>C:\Android\sdk\platform-tools\adb install -r app-release.apk