我正在尝试根据反应原生代码推送文档的这一部分配置我的 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
您必须将 signingConfig 添加到 releaseStaging。
releaseStaging {
signingConfig signingConfigs.release
buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING
}
然后,您可以将其安装到设备上。我有 react-native 版本 0.38,所以我用 react-native run-android --variant=releaseStaging
安装了它,但对于其他 react-native 版本来说,这可能会有所不同。如果你有较新版本的 react-native,你可以改为react-native run-android --configuration=releaseStaging
。
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;您可以使用
`react-native run-android --variant releaseStaging`