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

Commit 5fc5a0a

Browse files
committed
Merge branch 'master' of github.com:Microsoft/react-native-code-push into report-acquisition-status
2 parents 3e4ac61 + 1787f3f commit 5fc5a0a

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

CodePushPackage.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ + (NSString *)findMainBundleInFolder:(NSString *)folderPath
386386
return [fileName stringByAppendingPathComponent:mainBundlePathInFolder];
387387
}
388388
} else if ([[fileName pathExtension] isEqualToString:@"bundle"] ||
389-
[[fileName pathExtension] isEqualToString:@"jsbundle"]) {
389+
[[fileName pathExtension] isEqualToString:@"jsbundle"] ||
390+
[[fileName pathExtension] isEqualToString:@"js"]) {
390391
return fileName;
391392
}
392393
}

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This plugin provides client-side integration for the [CodePush service](http://c
1010
* [Plugin Configuration](#plugin-configuration-ios)
1111
* [Android Setup](#android-setup)
1212
* [Plugin Installation](#plugin-installation-android)
13-
* [Plugin Configuration](#plugin-configuration-android)
13+
* [Plugin Configuration (React Native < v0.18.0)](#plugin-configuration-android---react-native--v0180)
14+
* [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-android---react-native-v0180)
1415
* [Plugin Usage](#plugin-usage)
1516
* [Releasing Updates (JavaScript-only)](#releasing-updates-javascript-only)
1617
* [Releasing Updates (JavaScript + images)](#releasing-updates-javascript--images)
@@ -143,7 +144,9 @@ In order to integrate CodePush into your Android project, perform the following
143144
}
144145
```
145146
146-
### Plugin Configuration (Android)
147+
### Plugin Configuration (Android - React Native < v0.18.0)
148+
149+
*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.*
147150
148151
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:
149152
@@ -196,6 +199,61 @@ After installing the plugin and syncing your Android Studio project with Gradle,
196199
}
197200
```
198201
202+
### Plugin Configuration (Android - React Native v0.18.0+)
203+
204+
*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.*
205+
206+
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:
207+
208+
1. Update the `MainActivity.java` file to use CodePush via the following changes:
209+
210+
```java
211+
...
212+
// 1. Import the plugin class
213+
import com.microsoft.codepush.react.CodePush;
214+
215+
public class MainActivity extends ReactActivity {
216+
// 2. Define a private field to hold the CodePush runtime instance
217+
private CodePush _codePush;
218+
219+
...
220+
221+
// 3. Override the getJSBundleFile method in order to let
222+
// the CodePush runtime determine where to get the JS
223+
// bundle location from on each app start
224+
@Override
225+
protected String getJSBundleFile() {
226+
return this._codePush.getBundleUrl("index.android.bundle");
227+
}
228+
229+
@Override
230+
protected List<ReactPackage> getPackages() {
231+
// 4. Instantiate an instance of the CodePush runtime, using the right deployment key
232+
this._codePush = new CodePush("0dsIDongIcoH0mqAmoR0CYb5FhBZNy1w4Bf-l", this, BuildConfig.DEBUG);
233+
234+
// 5. Add the CodePush package to the list of existing packages
235+
return Arrays.<ReactPackage>asList(
236+
new MainReactPackage(), this._codePush.getReactPackage());
237+
}
238+
239+
...
240+
}
241+
```
242+
243+
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")
244+
245+
```gradle
246+
android {
247+
...
248+
defaultConfig {
249+
...
250+
versionName "1.0.0"
251+
...
252+
}
253+
...
254+
}
255+
```
256+
199257
## Plugin Usage
200258
201259
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:
@@ -242,7 +300,7 @@ And that's it! for more information regarding the CLI and how the release (or pr
242300

243301
## Releasing Updates (JavaScript + images)
244302

245-
*Note: Android doesn't currently support deploying assets, so you must use the previous release strategy instead.*
303+
*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.*
246304

247305
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:
248306

@@ -259,6 +317,8 @@ If you are using the new React Native [assets system](https://facebook.github.io
259317
--dev false
260318
```
261319

320+
*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.*
321+
262322
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.
263323

264324
For more info regarding the `release` command and its parameters, refer to the [CLI documentation](http://codepush.tools/docs/cli.html#releasing-app-updates).

android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.app.Activity;
44
import android.app.AlertDialog;
55
import android.content.DialogInterface;
6-
import android.support.v4.app.FragmentActivity;
76

87
import com.facebook.react.bridge.Callback;
98
import com.facebook.react.bridge.ReactApplicationContext;
@@ -22,16 +21,7 @@ public CodePushDialog(ReactApplicationContext reactContext, Activity mainActivit
2221
@ReactMethod
2322
public void showDialog(String title, String message, String button1Text, String button2Text,
2423
final Callback successCallback, Callback errorCallback) {
25-
26-
FragmentActivity fragmentActivity = null;
27-
try {
28-
fragmentActivity = (FragmentActivity) mainActivity;
29-
} catch (ClassCastException e) {
30-
errorCallback.invoke("Unable to show dialog, main activity is not a FragmentActivity");
31-
return;
32-
}
33-
34-
AlertDialog.Builder builder = new AlertDialog.Builder(fragmentActivity);
24+
AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity);
3525

3626
builder.setCancelable(false);
3727

0 commit comments

Comments
 (0)