根据Code Push教程中的多重部署测试,在Android上描述了如何在调试构建中设置分段键,在发布构建中设置生产键。然而,我发现这还不够,调试构建不会以发布构建相同的方式运行,所以应该为分期创建另一个Gradle buildType更好吗??我在任何地方都找不到谈论这个的人,我错过了什么吗?
下面是我如何将productFlavors
和buildTypes
设置为分级和实时环境,以及调试和发布构建:
...
defaultConfig {
applicationId "com.your.app.id"
minSdkVersion 16
targetSdkVersion 22
versionCode 5
versionName "1.5.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
applicationIdSuffix ".debug"
buildConfigField "boolean", "DEBUG", "true"
}
}
productFlavors {
live {
buildConfigField('String', 'BUILD_ENV', '"live"')
resValue "string", "app_name", "Your App"
resValue "string", "reactNativeCodePush_androidDeploymentKey", "___YOUR_LIVE/PROD_KEY___"
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher"
]
}
staging {
buildConfigField('String', 'BUILD_ENV', '"staging"')
applicationId "$defaultConfig.applicationId" + ".staging"
resValue "string", "app_name", "Your App (Staging)"
resValue "string", "reactNativeCodePush_androidDeploymentKey", "___YOUR_STAGING_KEY___"
manifestPlaceholders = [
appIcon: "@mipmap/ic_launcher_staging"
]
}
}
....
然后我们在package.json
中使用一些相应的脚本:
...
"dev-android": "node node_modules/react-native/local-cli/cli.js run-android --variant staging --configuration Debug",
"dev-android-live": "node node_modules/react-native/local-cli/cli.js run-android --variant live --configuration Debug",
"build-android": "cd android && ./gradlew assembleRelease",
"deploy-android": "code-push release-react your-code-push-app-name android -d staging --noDuplicateReleaseError",
...
希望对你有帮助。