Merge pull request #156 from Microsoft/android_doc

Preliminary Android 0.18.0 support
This commit is contained in:
Jonathan Carter
2016-01-22 08:54:19 -08:00
2 changed files with 61 additions and 13 deletions

View File

@@ -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---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)
@@ -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<ReactPackage> 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.<ReactPackage>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:

View File

@@ -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;
@@ -22,16 +21,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);