11

我正在尝试根据react-native-code-push 文档的这一部分配置我的 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'.

知道我缺少什么吗?
谢谢!
乌里

4

2 回答 2

23

您必须将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

于 2017-02-17T02:15:46.090 回答
-2

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`
于 2017-06-06T09:08:27.257 回答