|
4 | 4 | >
|
5 | 5 | > Complete demo configured with "multi-deployment testing" feature is [here](https://github.com/Microsoft/react-native-code-push/files/1314118/rncp1004.zip).
|
6 | 6 |
|
7 |
| -The [Android Gradle plugin](http://google.github.io/android-gradle-dsl/current/index.html) allows you to define custom config settings for each "build type" (like debug, release), which in turn are generated as properties on the `BuildConfig` class that you can reference from your Java code. 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. |
| 7 | +The [Android Gradle plugin](https://google.github.io/android-gradle-dsl/current/index.html) 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. |
| 8 | + |
| 9 | +*NOTE: As a reminder, you can retrieve these keys by running `code-push deployment ls <APP_NAME> -k` from your terminal.* |
8 | 10 |
|
9 | 11 | To set this up, perform the following steps:
|
10 | 12 |
|
11 |
| -1. Open your app's `build.gradle` file (for example `android/app/build.gradle` in standard React Native projects) |
| 13 | +**For React Native >= v0.60** |
| 14 | + |
| 15 | +1. Open the project's app level `build.gradle` file (for example `android/app/build.gradle` in standard React Native projects) |
| 16 | + |
| 17 | +2. Find the `android { buildTypes {} }` section and define `resValue` entries for both your `debug` and `release` build types, which reference your `Staging` and `Production` deployment keys respectively. |
| 18 | + |
| 19 | + ```groovy |
| 20 | + android { |
| 21 | + ... |
| 22 | + buildTypes { |
| 23 | + debug { |
| 24 | + ... |
| 25 | + // 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. |
| 26 | + resValue "string", "reactNativeCodePush_androidDeploymentKey", '""' |
| 27 | + ... |
| 28 | + } |
| 29 | +
|
| 30 | + releaseStaging { |
| 31 | + ... |
| 32 | + resValue "string", "reactNativeCodePush_androidDeploymentKey", '"<INSERT_STAGING_KEY>"' |
| 33 | +
|
| 34 | + // Note: It is a good idea to provide matchingFallbacks for the new buildType you create to prevent build issues |
| 35 | + // Add the following line if not already there |
| 36 | + matchingFallbacks = ['release'] |
| 37 | + ... |
| 38 | + } |
| 39 | +
|
| 40 | + release { |
| 41 | + ... |
| 42 | + resValue "string", "reactNativeCodePush_androidDeploymentKey", '"<INSERT_PRODUCTION_KEY>"' |
| 43 | + ... |
| 44 | + } |
| 45 | + } |
| 46 | + ... |
| 47 | + } |
| 48 | + ``` |
| 49 | + |
| 50 | + *NOTE: Remember to remove the key from `strings.xml` if you are configuring the deployment key in the build process* |
| 51 | +
|
| 52 | + *NOTE: The naming convention for `releaseStaging` is significant due to [this line](https://github.com/facebook/react-native/blob/e083f9a139b3f8c5552528f8f8018529ef3193b9/react.gradle#L79).* |
| 53 | +
|
| 54 | +**For React Native v0.29 - v0.59** |
| 55 | +
|
| 56 | +1. Open up your `MainApplication.java` file and make the following changes: |
| 57 | +
|
| 58 | + ```java |
| 59 | + @Override |
| 60 | + protected List<ReactPackage> getPackages() { |
| 61 | + return Arrays.<ReactPackage>asList( |
| 62 | + ... |
| 63 | + new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG), // Add/change this line. |
| 64 | + ... |
| 65 | + ); |
| 66 | + } |
| 67 | + ``` |
12 | 68 |
|
13 |
| -2. Find the `android { buildTypes {} }` section and define `buildConfigField` entries for both your `debug` and `release` build types, which reference your `Staging` and `Production` deployment keys respectively. If you prefer, you can define the key literals in your `gradle.properties` file, and then reference them here. Either way will work, and it's just a matter of personal preference. |
| 69 | +2. Open your app's `build.gradle` file (for example `android/app/build.gradle` in standard React Native projects) |
| 70 | +
|
| 71 | +3. Find the `android { buildTypes {} }` section and define `buildConfigField` entries for both your `debug` and `release` build types, which reference your `Staging` and `Production` deployment keys respectively. If you prefer, you can define the key literals in your `gradle.properties` file, and then reference them here. Either way will work, and it's just a matter of personal preference. |
14 | 72 |
|
15 | 73 | ```groovy
|
16 | 74 | android {
|
@@ -42,27 +100,10 @@ To set this up, perform the following steps:
|
42 | 100 | }
|
43 | 101 | ```
|
44 | 102 |
|
45 |
| - *NOTE: As a reminder, you can retrieve these keys by running `code-push deployment ls <APP_NAME> -k` from your terminal.* |
46 |
| -
|
47 | 103 | *NOTE: The naming convention for `releaseStaging` is significant due to [this line](https://github.com/facebook/react-native/blob/e083f9a139b3f8c5552528f8f8018529ef3193b9/react.gradle#L79).*
|
48 | 104 |
|
49 | 105 | 4. Pass the deployment key to the `CodePush` constructor via the build config you defined, as opposed to a string literal.
|
50 | 106 |
|
51 |
| -**For React Native >= v0.29** |
52 |
| -
|
53 |
| -Open up your `MainApplication.java` file and make the following changes: |
54 |
| -
|
55 |
| - ```java |
56 |
| -@Override |
57 |
| -protected List<ReactPackage> getPackages() { |
58 |
| - return Arrays.<ReactPackage>asList( |
59 |
| - ... |
60 |
| - new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG), // Add/change this line. |
61 |
| - ... |
62 |
| - ); |
63 |
| -} |
64 |
| - ``` |
65 |
| - |
66 | 107 | **For React Native v0.19 - v0.28**
|
67 | 108 |
|
68 | 109 | Open up your `MainActivity.java` file and make the following changes:
|
@@ -104,4 +145,4 @@ buildTypes {
|
104 | 145 |
|
105 | 146 | 5. Optionally, create "mirrored" directories in the `app/src/debug/res` directory for all of your app's icons that you want to change for your debug build. This part isn't technically critical, but it can make it easier to quickly spot your debug builds on a device if its icon is noticeable different.
|
106 | 147 |
|
107 |
| -And that's it! View [here](http://tools.android.com/tech-docs/new-build-system/resource-merging) for more details on how resource merging works in Android. |
| 148 | +And that's it! View [here](http://tools.android.com/tech-docs/new-build-system/resource-merging) for more details on how resource merging works in Android. |
0 commit comments