我试图根据react-native-code-push docs的this section配置我的RN android项目
我的build.gradle文件具有以下配置:
buildTypes {
debug {
}
releaseStaging {
buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING
}
release {
buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_PRODUCTION
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
但是当我跑步时:react-native run-android --variant releaseStaging
我收到错误:Task 'installReleaseStagingDebug' not found in root project 'MyAppName'.
还尝试了react-native run-android --configuration releaseStaging
这给了我一个稍好的错误:
Task 'installReleaseStaging' not found in root project 'MyAppName'. Some candidates are: 'uninstallReleaseStaging'.
知道我错过了什么吗?
谢谢!
URI
答案 0 :(得分:13)
您必须将signingConfig添加到releaseStaging。
releaseStaging {
signingConfig signingConfigs.release
buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING
}
然后您可以将其安装到您的设备上。我有反应原生版本0.38所以我用react-native run-android --variant=releaseStaging
安装它,但这可能与其他反应原生版本不同。如果您有更新版本的react-native,则可以改为react-native run-android --configuration=releaseStaging
。
答案 1 :(得分:-1)
Android Gradle插件允许您为每个"构建类型定义自定义配置设置" (例如,调试,发布)
要设置它, 在标准的React Native项目中修改android / app / build.gradle
android {
...
buildTypes {
debug {
...
// Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
buildConfigField "String", "CODEPUSH_KEY", '""'
...
}
releaseStaging {
...
buildConfigField "String", "CODEPUSH_KEY", '"<INSERT_STAGING_KEY>"'
signingConfig signingConfigs.release
...
}
release {
...
buildConfigField "String", "CODEPUSH_KEY", '"<INSERT_PRODUCTION_KEY>"'
signingConfig signingConfigs.release
...
}
}
...
}
注意:不应在调试模式下测试CodePush更新,因为它们会被RN打包器覆盖。但是,由于CodePush会检查所有模式下的更新,因此我们必须提供密钥。
buildConfigField "String", "CODEPUSH_KEY", '""'
最新反应原生;你可以用
构建`react-native run-android --variant releaseStaging`