Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit c2804da

Browse files
committed
Update README.md
1 parent 39132b0 commit c2804da

File tree

1 file changed

+58
-63
lines changed

1 file changed

+58
-63
lines changed

README.md

Lines changed: 58 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ This plugin provides client-side integration for the [CodePush service](http://c
1414
* [Plugin Configuration](#plugin-configuration-ios)
1515
* [Android Setup](#android-setup)
1616
* [Plugin Installation](#plugin-installation-android)
17-
* [Plugin Configuration (React Native < v0.18.0)](#plugin-configuration-android---react-native--v0180)
18-
* [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-android---react-native-v0180)
17+
* [Plugin Configuration](#plugin-configuration-android)
1918
* [Plugin Usage](#plugin-usage)
2019
* [Releasing Updates (JavaScript-only)](#releasing-updates-javascript-only)
2120
* [Releasing Updates (JavaScript + images)](#releasing-updates-javascript--images)
@@ -199,77 +198,49 @@ To let the CodePush runtime know which deployment it should query for updates ag
199198

200199
## Android Setup
201200

202-
In order to integrate CodePush into your Android project, perform the following steps:
201+
In order to accomodate as many developer preferences as possible, the CodePush plugin supports Android setup via two mechanisms:
203202

204-
### Plugin Installation (Android)
203+
1. [**RNPM**](#plugin-installation-and-configuration-android---rnpm) - [React Native Package Manager (RNPM)](https://github.com/rnpm/rnpm) is an awesome tool that provides the simplest installation experience possible for React Native plugins. If you're already using it, or you want to use it, then we recommend this approach.
205204

206-
1. In your `android/settings.gradle` file, make the following additions:
207-
208-
```gradle
209-
include ':app', ':react-native-code-push'
210-
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
211-
```
212-
2. In your `android/app/build.gradle` file, add the `:react-native-code-push` project as a compile-time dependency:
213-
214-
```gradle
215-
...
216-
dependencies {
217-
...
218-
compile project(':react-native-code-push')
219-
}
220-
```
221-
3. (Only needed in v1.8.0+ of the plugin) In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
222-
223-
```gradle
224-
...
225-
apply from: "react.gradle"
226-
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
227-
...
228-
```
229-
230-
### Plugin Configuration (Android - React Native < v0.18.0)
205+
2. [**"Manual"**](#plugin-installation-android---manual) - If you don't want to depend on any additional tools or are fine with a few extra installation steps (it's a one-time thing), then go with this approach.
231206

232-
*NOTE: These instructions are specific to apps that are using React Native v0.15.0-v0.17.0. If you are using v0.18.0+, then skip ahead to the next section.*
207+
#### Plugin Installation and Configuration (Android - RNPM)
233208

234-
After installing the plugin and syncing your Android Studio project with Gradle, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this, perform the following steps:
209+
1. Run `rnpm link react-native-code-push`
235210

236-
1. Update the `MainActivity.java` file to use CodePush via the following changes:
211+
*Note: If you don't already have RNPM installed, you can do so by simply running `npm i -g rnpm` and then executing the above command.*
237212
213+
2. For Android, RNPM will also attempt to edit your MainActivity.java file to automate adding the CodePush `ReactPackage` to the runtime. However, there are a few tweaks you need to make, as follows:
214+
238215
```java
239216
...
240-
// 1. Import the plugin class
241-
import com.microsoft.codepush.react.CodePush;
242-
243-
// 2. Optional: extend FragmentActivity if you intend to show a dialog prompting users about updates.
244-
// If you do this, make sure to also add "import android.support.v4.app.FragmentActivity" below #1.
245-
public class MainActivity extends FragmentActivity implements DefaultHardwareBackBtnHandler {
246-
...
247-
217+
218+
public class MainActivity extends ReactActivity {
219+
// 1. Override the getJSBundleFile method in order to let
220+
// the CodePush runtime determine where to get the JS
221+
// bundle location from on each app start
248222
@Override
249-
protected void onCreate(Bundle savedInstanceState) {
250-
...
251-
// 3. Initialize CodePush with your deployment key and an instance of your MainActivity. If you don't
252-
// already have it, you can run "code-push deployment ls <appName> -k" in order to retrieve your key.
253-
CodePush codePush = new CodePush("d73bf5d8-4fbd-4e55-a837-accd328a21ba", this, BuildConfig.DEBUG);
254-
...
255-
mReactInstanceManager = ReactInstanceManager.builder()
256-
.setApplication(getApplication())
257-
...
258-
// 4. DELETE THIS LINE --> .setBundleAssetName("index.android.bundle")
259-
260-
// 5. Let CodePush determine which location to load the most updated bundle from.
261-
// If there is no updated bundle from CodePush, the location will be the assets
262-
// folder with the name of the bundle passed in, e.g. index.android.bundle
263-
.setJSBundleFile(codePush.getBundleUrl("index.android.bundle"))
264-
265-
// 6. Expose the CodePush module to JavaScript.
266-
.addPackage(codePush.getReactPackage())
267-
...
223+
protected String getJSBundleFile() {
224+
return CodePush.getBundleUrl("index.android.bundle");
225+
}
226+
227+
@Override
228+
protected List<ReactPackage> getPackages() {
229+
// 2. Specify the right deployment key during construction of the CodePush class.
230+
// If you don't already have it, you can run "code-push deployment ls <appName> -k"
231+
// to retrieve your key.
232+
return Arrays.<ReactPackage>asList(
233+
new MainReactPackage(),
234+
// new CodePush() <-- Replace this with the line below
235+
new CodePush("deployment-key-here", this, BuildConfig.DEBUG)
236+
);
268237
}
238+
239+
...
269240
}
270241
```
271242

272-
2. Ensure that the `android.defaultConfig.versionName` property in your `android/app/build.gradle` file is set to a semver-compliant value. Note that if the value provided is missing a patch version, the CodePush server will assume it is `0`, i.e. `1.0` will be treated as `1.0.0`.
243+
3. Ensure that the `android.defaultConfig.versionName` property in your `android/app/build.gradle` file is set to a semver-compliant value. Note that if the value provided is missing a patch version, the CodePush server will assume it is `0`, i.e. `1.0` will be treated as `1.0.0`.
273244

274245
```gradle
275246
android {
@@ -282,10 +253,34 @@ After installing the plugin and syncing your Android Studio project with Gradle,
282253
...
283254
}
284255
```
256+
257+
#### Plugin Installation (Android - Manual)
258+
259+
1. In your `android/settings.gradle` file, make the following additions:
285260

286-
### Plugin Configuration (Android - React Native v0.18.0+)
261+
```gradle
262+
include ':app', ':react-native-code-push'
263+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
264+
```
265+
2. In your `android/app/build.gradle` file, add the `:react-native-code-push` project as a compile-time dependency:
266+
267+
```gradle
268+
...
269+
dependencies {
270+
...
271+
compile project(':react-native-code-push')
272+
}
273+
```
274+
3. (Only needed in v1.8.0+ of the plugin) In your `android/app/build.gradle` file, add the `codepush.gradle` file as an additional build task definition underneath `react.gradle`:
275+
276+
```gradle
277+
...
278+
apply from: "react.gradle"
279+
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
280+
...
281+
```
287282

288-
*NOTE: These instructions are specific to apps that are using React Native v0.18.0+. If you are using v0.15.0-v0.17.0, then refer to the previous section.*
283+
### Plugin Configuration (Android - Manual)
289284

290285
After installing the plugin and syncing your Android Studio project with Gradle, you need to configure your app to consult CodePush for the location of your JS bundle, since it will "take control" of managing the current and all future versions. To do this, perform the following steps:
291286

@@ -302,7 +297,7 @@ After installing the plugin and syncing your Android Studio project with Gradle,
302297
// bundle location from on each app start
303298
@Override
304299
protected String getJSBundleFile() {
305-
return this._codePush.getBundleUrl("index.android.bundle");
300+
return CodePush.getBundleUrl("index.android.bundle");
306301
}
307302
308303
@Override

0 commit comments

Comments
 (0)