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 Source Push staging deployment key and your release builds to use your Source Push production deployment key.
NOTE: As a reminder, you can retrieve these keys by running srcpush deployment ls <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.gradlefile (for exampleandroid/app/build.gradlein standard React Native projects) -
Find the
android { buildTypes {} }section and defineresValueentries for both yourdebugandreleasebuild types, which reference yourStagingandProductiondeployment keys respectively.android { ... buildTypes { debug { ... // Note: Source Push updates should not be tested in Debug mode as they are overriden by the RN packager. However, because Source Push 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.xmlif you are configuring the deployment key in the build processNOTE: The naming convention for
releaseStagingis significant due to this line.
And that's it! View here for more details on how resource merging works in Android.