NOTE
Complete demo configured with "multi-deployment testing" feature is here.
The Android Gradle plugin allows you to define custom config settings for each "build type" (like debug, release). This mechanism allows you to easily configure your debug builds to use your CodePush staging deployment key and your release builds to use your CodePush production deployment key.
NOTE: As a reminder, you can retrieve these keys by running appcenter codepush deployment list -a <ownerName>/<appName> -k
from your terminal.
To set this up, perform the following steps:
For React Native >= v0.76
-
Open the project's app level
build.gradle
file (for exampleandroid/app/build.gradle
in standard React Native projects) -
Find the
android { buildTypes {} }
section and defineresValue
entries for both yourdebug
andrelease
build types, which reference yourStaging
andProduction
deployment keys respectively.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. resValue "string", "CodePushDeploymentKey", '""' ... } releaseStaging { ... resValue "string", "CodePushDeploymentKey", '"<INSERT_STAGING_KEY>"' // Note: It is a good idea to provide matchingFallbacks for the new buildType you create to prevent build issues // Add the following line if not already there matchingFallbacks = ['release'] ... } release { ... resValue "string", "CodePushDeploymentKey", '"<INSERT_PRODUCTION_KEY>"' ... } } ... }
NOTE: Remember to remove the key from
strings.xml
if you are configuring the deployment key in the build processNOTE: The naming convention for
releaseStaging
is significant due to this line.
And that's it! View here for more details on how resource merging works in Android.