gradle - Code-Push Multiple Deployment 的 Android 暂存构建类型

标签 gradle android-gradle-plugin code-push

根据 Code Push 教程中的 Multiple Deployment testing,描述了在 Android 上,如何在 Debug 构建中设置 Staging 键,在 Release 构建中设置 Production 键。但是我发现这还不够,Debug 构建不会以与 Release 构建相同的方式运行,所以为 Staging 创建另一个 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",
...

希望有帮助。

关于gradle - Code-Push Multiple Deployment 的 Android 暂存构建类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39820698/

相关文章:

android - 在android中实现codepush时出错: reactNativeCodePush_androidDeploymentKey

使用 AppCompat v23 和 API21 构建应用程序时 Android Studio 不工作

android - Unity Android Build错误:无法读取PNG签名:文件不是以PNG签名开头

android - Facebook 字符串没有默认翻译

Android Studio list 合并失败 minSdkVersion 错误

android - Codepush 不适用于所有 Android 用户

Android Studio 不执行 build.gradle

gradle - 如何在 gradle 的应用程序默认 jvm 参数中获取 $ 未转义?

android - Android Studio Gradle项目同步已完成,但出现错误

android - 如何在一个应用程序中使用多个 ReactNativeHosts 进行 CodePush?