项目配置

  • 项目package.json 如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
{
"name": "news",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"react": "^0.14.8",
"react-native": "^0.25.1",
"react-native-umeng-push": "^1.0.3",
"react-native-xtabbar": "^0.1.8"
}
}
1
2
3
4
 # 需先安装rnpm 
npm install rnpm -g
再安装依赖
rnpm install react-native-umeng-push
  • 项目 settings.gradle如下
1
2
3
4
5
6
7
rootProject.name = 'XXX'
include ':app'
# 这里引入了两个工程
include ':react-native-umeng-push'
project(':react-native-umeng-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-umeng-push/android')
include ':PushSDK'
project(':PushSDK').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-umeng-sdk/android/PushSDK')
  • 在项目build.gradle中添加
1
2
3
4
5
6
7
8
dependencies {
compile project(':react-native-umeng-push')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.umeng.analytics:analytics:latest.integration'
compile project(':PushSDK')
}
  • 生成keystore
    keytool -genkey -v -keystore xxx.keystore -alias xxx -keyalg RSA -keysize 2048 -validity 10000
  • 将生成的keystore放入项目目录中
    • build.gradle中添加签名配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//签名配置
signingConfigs {
release {
storeFile file("xxx.keystore")
keyAlias "xxx"
storePassword "xxx"
keyPassword "xxx"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
  • 利用react-native 打包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/

    这里将index.android.bundle 放入src/main/assets/中 并将所用到的资源放入src/main/res/目录中

  • Gradle 生成 Relase API cd android && ./gradlew installRelease

参考引用