From 6cd9dea8e1190d1a62a07ae3bd10b6732384bfd0 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Thu, 21 Jan 2016 22:31:05 -0800 Subject: [PATCH 1/4] RN Android 0.18.0 support: --- README.md | 62 ++++++++++++++++++- .../codepush/react/CodePushDialog.java | 11 +--- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0b5de52..a209a8d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ 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](#plugin-configuration-android) + * [Plugin Configuration (React Native < v0.18.0)](#plugin-configuration-android) + * [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-android) * [Plugin Usage](#plugin-usage) * [Releasing Updates (JavaScript-only)](#releasing-updates-javascript-only) * [Releasing Updates (JavaScript + images)](#releasing-updates-javascript--images) @@ -143,7 +144,9 @@ In order to integrate CodePush into your Android project, perform the following } ``` -### Plugin Configuration (Android) +### 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: @@ -196,6 +199,61 @@ After installing the plugin and syncing your Android Studio project with Gradle, } ``` +### 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.* + +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; + + public class MainActivity extends ReactActivity { + // 2. Define a private field to hold the CodePush runtime instance + private CodePush _codePush; + + ... + + // 3. 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 this._codePush.getBundleUrl("index.android.bundle"); + } + + @Override + protected List getPackages() { + // 4. Instantiate an instance of the CodePush runtime, using the right deployment key + this._codePush = new CodePush("0dsIDongIcoH0mqAmoR0CYb5FhBZNy1w4Bf-l", this, BuildConfig.DEBUG); + + // 5. Add the CodePush package to the list of existing packages + return Arrays.asList( + new MainReactPackage(), this._codePush.getReactPackage()); + } + + ... + } + ``` + +2. Ensure that the `android.defaultConfig.versionName` property in your `android/app/build.gradle` file is set to a semver compliant value (i.e. "1.0.0" not "1.0") + + ```gradle + android { + ... + defaultConfig { + ... + versionName "1.0.0" + ... + } + ... + } + ``` + ## Plugin Usage With the CodePush plugin downloaded and linked, and your app asking CodePush where to get the right JS bundle from, the only thing left is to add the necessary code to your app to control the following policies: diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java index 6261934..649ba31 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java @@ -22,16 +22,7 @@ public class CodePushDialog extends ReactContextBaseJavaModule{ @ReactMethod public void showDialog(String title, String message, String button1Text, String button2Text, final Callback successCallback, Callback errorCallback) { - - FragmentActivity fragmentActivity = null; - try { - fragmentActivity = (FragmentActivity) mainActivity; - } catch (ClassCastException e) { - errorCallback.invoke("Unable to show dialog, main activity is not a FragmentActivity"); - return; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(fragmentActivity); + AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity); builder.setCancelable(false); From 5f48cc9a72e793f6fc9367dc8d70ac0e1739d912 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Thu, 21 Jan 2016 22:33:59 -0800 Subject: [PATCH 2/4] Fixing links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a209a8d..28c38f9 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ 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) - * [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-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 Usage](#plugin-usage) * [Releasing Updates (JavaScript-only)](#releasing-updates-javascript-only) * [Releasing Updates (JavaScript + images)](#releasing-updates-javascript--images) From d9bc8924c5bcda86a7f3ad9eb452e435c3b124f0 Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 22 Jan 2016 08:48:15 -0800 Subject: [PATCH 3/4] Removing unneccessary import --- .../main/java/com/microsoft/codepush/react/CodePushDialog.java | 1 - 1 file changed, 1 deletion(-) diff --git a/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java b/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java index 649ba31..6c4ac87 100644 --- a/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java +++ b/android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java @@ -3,7 +3,6 @@ package com.microsoft.codepush.react; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; -import android.support.v4.app.FragmentActivity; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; From 92d82c5c8cd09bd8622671d20f059d99dd749a5f Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 22 Jan 2016 09:04:35 -0800 Subject: [PATCH 4/4] Adding support for .js extension --- CodePushPackage.m | 3 ++- README.md | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CodePushPackage.m b/CodePushPackage.m index f30f862..a31f51a 100644 --- a/CodePushPackage.m +++ b/CodePushPackage.m @@ -386,7 +386,8 @@ NSString * const UnzippedFolderName = @"unzipped"; return [fileName stringByAppendingPathComponent:mainBundlePathInFolder]; } } else if ([[fileName pathExtension] isEqualToString:@"bundle"] || - [[fileName pathExtension] isEqualToString:@"jsbundle"]) { + [[fileName pathExtension] isEqualToString:@"jsbundle"] || + [[fileName pathExtension] isEqualToString:@"js"]) { return fileName; } } diff --git a/README.md b/README.md index 28c38f9..b6247af 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ And that's it! for more information regarding the CLI and how the release (or pr ## Releasing Updates (JavaScript + images) -*Note: Android doesn't currently support deploying assets, so you must use the previous release strategy instead.* +*Note: Android doesn't currently support deploying assets, so you must use the previous release strategy instead for that platform. We will release Android support as soon as React Native 0.19.0 is released.* If you are using the new React Native [assets system](https://facebook.github.io/react-native/docs/images.html#content), as opposed to loading your images from the network and/or platform-specific mechanisms (e.g. iOS asset catalogs), then you can't simply pass your jsbundle to CodePush as demonstrated above. You **MUST** provide your images as well. To do this, simply use the following workflow: @@ -317,6 +317,8 @@ If you are using the new React Native [assets system](https://facebook.github.io --dev false ``` + *NOTE: The file name that you specify as the value for the `--bundle-output` parameter must have one of the following extensions in order to be detected by the plugin: `.js`, `.jsbundle`, `.bundle` (e.g. `main.jsbundle`, `ios.js`). The name of the file isn't relevant, but the extension is used for detectining the bundle within the update contents, and therefore, using any other extension will result in the update failing.* + 3. Execute `code-push release`, passing the path to the directory you created in #1 as the ["package"](http://codepush.tools/docs/cli.html#package-parameter) parameter, and the [**exact app version**](http://codepush.tools/docs/cli.html#app-store-version-parameter) that this update is targetting as the ["appStoreVersion"](http://codepush.tools/docs/cli.html#app-store-version-parameter) parameter (e.g. `code-push release Foo ./release 1.0.0`). The code-push CLI will automatically handle zipping up the contents for you, so don't worry about handling that yourself. For more info regarding the `release` command and its parameters, refer to the [CLI documentation](http://codepush.tools/docs/cli.html#releasing-app-updates).