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

Commit 6cd9dea

Browse files
committed
RN Android 0.18.0 support:
1 parent 818f73b commit 6cd9dea

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

README.md

Lines changed: 60 additions & 2 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)
14+
* [Plugin Configuration (React Native 0.18.0+)](#plugin-configuration-android)
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:

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@ public CodePushDialog(ReactApplicationContext reactContext, Activity mainActivit
2222
@ReactMethod
2323
public void showDialog(String title, String message, String button1Text, String button2Text,
2424
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);
25+
AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity);
3526

3627
builder.setCancelable(false);
3728

0 commit comments

Comments
 (0)