Codepush React Native Android staging- 在根项目中找不到任务 installReleaseStagingDebug

Codepush React Native Android staging- Task installReleaseStagingDebug not found in root project

我正在尝试根据 react-native-code-push 文档

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'.

知道我错过了什么吗?
谢谢!
乌里

您必须将 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 插件允许您为每个 "build type"(例如调试、发布)定义自定义配置设置

要进行设置, 在标准 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`