From c2804da9210580206cbe4dcd38942b87f3f124da Mon Sep 17 00:00:00 2001 From: Geoffrey Goh Date: Fri, 25 Mar 2016 13:59:54 -0700 Subject: [PATCH] Update README.md --- README.md | 123 ++++++++++++++++++++++++++---------------------------- 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 95848ce..68a3de6 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,7 @@ This plugin provides client-side integration for the [CodePush service](http://c * [Plugin Configuration](#plugin-configuration-ios) * [Android Setup](#android-setup) * [Plugin Installation](#plugin-installation-android) - * [Plugin Configuration (React Native < v0.18.0)](#plugin-configuration-android---react-native--v0180) - * [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-android---react-native-v0180) + * [Plugin Configuration](#plugin-configuration-android) * [Plugin Usage](#plugin-usage) * [Releasing Updates (JavaScript-only)](#releasing-updates-javascript-only) * [Releasing Updates (JavaScript + images)](#releasing-updates-javascript--images) @@ -199,9 +198,63 @@ To let the CodePush runtime know which deployment it should query for updates ag ## Android Setup -In order to integrate CodePush into your Android project, perform the following steps: +In order to accomodate as many developer preferences as possible, the CodePush plugin supports Android setup via two mechanisms: -### Plugin Installation (Android) +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. + +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. + +#### Plugin Installation and Configuration (Android - RNPM) + +1. Run `rnpm link react-native-code-push` + + *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.* + +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: + + ```java + ... + + public class MainActivity extends ReactActivity { + // 1. Override the getJSBundleFile method in order to let + // the CodePush runtime determine where to get the JS + // bundle location from on each app start + @Override + protected String getJSBundleFile() { + return CodePush.getBundleUrl("index.android.bundle"); + } + + @Override + protected List getPackages() { + // 2. Specify the right deployment key during construction of the CodePush class. + // If you don't already have it, you can run "code-push deployment ls -k" + // to retrieve your key. + return Arrays.asList( + new MainReactPackage(), + // new CodePush() <-- Replace this with the line below + new CodePush("deployment-key-here", this, BuildConfig.DEBUG) + ); + } + + ... + } + ``` + +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`. + + ```gradle + android { + ... + defaultConfig { + ... + versionName "1.0.0" + ... + } + ... + } + ``` + +#### Plugin Installation (Android - Manual) 1. In your `android/settings.gradle` file, make the following additions: @@ -227,65 +280,7 @@ In order to integrate CodePush into your Android project, perform the following ... ``` -### Plugin Configuration (Android - React Native < v0.18.0) - -*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.* - -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: - -1. Update the `MainActivity.java` file to use CodePush via the following changes: - - ```java - ... - // 1. Import the plugin class - import com.microsoft.codepush.react.CodePush; - - // 2. Optional: extend FragmentActivity if you intend to show a dialog prompting users about updates. - // If you do this, make sure to also add "import android.support.v4.app.FragmentActivity" below #1. - public class MainActivity extends FragmentActivity implements DefaultHardwareBackBtnHandler { - ... - - @Override - protected void onCreate(Bundle savedInstanceState) { - ... - // 3. Initialize CodePush with your deployment key and an instance of your MainActivity. If you don't - // already have it, you can run "code-push deployment ls -k" in order to retrieve your key. - CodePush codePush = new CodePush("d73bf5d8-4fbd-4e55-a837-accd328a21ba", this, BuildConfig.DEBUG); - ... - mReactInstanceManager = ReactInstanceManager.builder() - .setApplication(getApplication()) - ... - // 4. DELETE THIS LINE --> .setBundleAssetName("index.android.bundle") - - // 5. Let CodePush determine which location to load the most updated bundle from. - // If there is no updated bundle from CodePush, the location will be the assets - // folder with the name of the bundle passed in, e.g. index.android.bundle - .setJSBundleFile(codePush.getBundleUrl("index.android.bundle")) - - // 6. Expose the CodePush module to JavaScript. - .addPackage(codePush.getReactPackage()) - ... - } - } - ``` - -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`. - - ```gradle - android { - ... - defaultConfig { - ... - versionName "1.0.0" - ... - } - ... - } - ``` - -### Plugin Configuration (Android - React Native v0.18.0+) - -*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.* +### Plugin Configuration (Android - Manual) 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: @@ -302,7 +297,7 @@ After installing the plugin and syncing your Android Studio project with Gradle, // bundle location from on each app start @Override protected String getJSBundleFile() { - return this._codePush.getBundleUrl("index.android.bundle"); + return CodePush.getBundleUrl("index.android.bundle"); } @Override