@appcircle/react-native-code-push 0.0.2-alpha.3 → 0.0.2-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CONTRIBUTING.md CHANGED
@@ -132,3 +132,37 @@ NPM=true CORE=true npm run test:android
132
132
  ```
133
133
 
134
134
  ...and so on!
135
+
136
+ ## Publishing Guidelines
137
+
138
+ - After changes, run the command `yarn run postversion`. It will push a new tag to the repository.
139
+ - Jenkins will take care of the rest.
140
+
141
+ ### Publishing to NPM
142
+
143
+ To publish a new version on NPM, use the following command:
144
+
145
+ ```shell
146
+ npm version <version>
147
+ ```
148
+
149
+ #### Examples
150
+
151
+ ```shell
152
+ ## To publish a beta version
153
+ $ npm version 1.0.0-beta.1
154
+
155
+ $ npm version 1.0.0
156
+ ```
157
+
158
+ ## Jenkins Pipeline
159
+
160
+ - Jenkins will look for the tag that matches `v*`, `v*-beta*`, `v*-alpha*`.
161
+
162
+ - If a new tag is published, the pipeline will be triggered automatically and publish the application.
163
+
164
+ - If the tag is `v*`, the app will be published to the stable channel.
165
+
166
+ - If the tag is `v*-beta*`, the app will be published to the beta channel.
167
+
168
+ - If the tag is `v*-alpha*`, the app will be published to the alpha channel.
package/README.md CHANGED
@@ -1,459 +1,123 @@
1
- > ⚠️ **Notice**
2
- > This NPM package is a fork of the original GitHub repository.
3
- > The implementation has been modified and may differ from the original.
4
- > Documentation is currently being updated to reflect these changes.
1
+ # Appcircle React Native CodePush SDK
5
2
 
6
- ## About this fork
3
+ ## Overview
7
4
 
8
- This project is a fork of [react-native-code-push](https://github.com/microsoft/react-native-code-push),
9
- with additional custom modifications for specific use cases.
10
-
11
- -------
12
-
13
-
14
- [![appcenterbanner](https://user-images.githubusercontent.com/31293287/32969262-3cc5d48a-cb99-11e7-91bf-fa57c67a371c.png)](http://microsoft.github.io/code-push/)
5
+ Appcircle React Native CodePush SDK enables you to deploy mobile app updates directly to your users' devices through Appcircle's CI/CD platform. This integration allows you to automate your deployment process and manage your app updates efficiently.
15
6
 
16
- #### [Sign up With App Center](https://appcenter.ms/signup?utm_source=CodePush&utm_medium=Azure) to use CodePush
17
-
18
- # React Native Module for CodePush
19
- > [!WARNING]
20
- > ~~React Native CodePush won't support new Architecture. In order to use this plugin on React Native versions starting from 0.76 you will need to [opt out](https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here#opt-out) from new architecture.~~
21
- > React Native CodePush support for new architecture is in progress.
22
- >
23
- *Note: This README is only relevant to the latest version of our plugin. If you are using an older version, please switch to the relevant tag on [our GitHub repo](https://github.com/microsoft/react-native-code-push) to view the docs for that particular version.*
7
+ ## Features
24
8
 
25
- ![Switching tags](https://user-images.githubusercontent.com/42337914/57237511-0835de80-7030-11e9-88fa-64eb200478d0.png)
9
+ - **Appcircle Integration**: Seamless integration with Appcircle CI/CD platform
10
+ - **Automated Deployments**: Automatic deployment of updates through Appcircle workflows
11
+ - **Instant Updates**: Deploy updates to your users' devices instantly
12
+ - **Rollback Support**: Automatically rollback to previous versions if issues occur
13
+ - **Differential Updates**: Only download the files that have changed
14
+ - **Multi-Platform Support**: Works with iOS, Android, and Windows
15
+ - **TypeScript Support**: Full TypeScript definitions included
26
16
 
27
- This plugin provides client-side integration for the [CodePush service](https://microsoft.github.io/code-push/), allowing you to easily add a dynamic update experience to your React Native app(s).
28
17
 
29
- <!-- React Native Catalog -->
30
-
31
- * [How does it work?](#how-does-it-work)
32
- * [Supported React Native Platforms](#supported-react-native-platforms)
33
- * [Supported Components](#supported-components)
34
- * [Getting Started](#getting-started)
35
- * [iOS Setup](docs/setup-ios.md)
36
- * [Android Setup](docs/setup-android.md)
37
- * [Windows Setup](docs/setup-windows.md)
38
- * [Plugin Usage](#plugin-usage)
39
- * [Store Guideline Compliance](#store-guideline-compliance)
40
- * [Releasing Updates](#releasing-updates)
41
- * [Multi-Deployment Testing](#multi-deployment-testing)
42
- * [Android](docs/multi-deployment-testing-android.md)
43
- * [iOS](docs/multi-deployment-testing-ios.md)
44
- * [Dynamic Deployment Assignment](#dynamic-deployment-assignment)
45
- * [API Reference](#api-reference)
46
- * [JavaScript API](docs/api-js.md)
47
- * [Objective-C API Reference (iOS)](docs/api-ios.md)
48
- * [Java API Reference (Android)](docs/api-android.md)
49
- * [Debugging / Troubleshooting](#debugging--troubleshooting)
50
- * [Example Apps / Starters](#example-apps--starters)
51
- * [Continuous Integration / Delivery](#continuous-integration--delivery)
52
- * [TypeScript Consumption](#typescript-consumption)
53
-
54
- <!-- React Native Catalog -->
55
-
56
- ## How does it work?
57
-
58
- A React Native app is composed of JavaScript files and any accompanying [images](https://reactnative.dev/docs/image), which are bundled together by the [metro bundler](https://github.com/facebook/metro) and distributed as part of a platform-specific binary (i.e. an `.ipa` or `.apk` file). Once the app is released, updating either the JavaScript code (e.g. making bug fixes, adding new features) or image assets, requires you to recompile and redistribute the entire binary, which of course, includes any review time associated with the store(s) you are publishing to.
59
-
60
- The CodePush plugin helps get product improvements in front of your end users instantly, by keeping your JavaScript and images synchronized with updates you release to the CodePush server. This way, your app gets the benefits of an offline mobile experience, as well as the "web-like" agility of side-loading updates as soon as they are available. It's a win-win!
61
-
62
- In order to ensure that your end users always have a functioning version of your app, the CodePush plugin maintains a copy of the previous update, so that in the event that you accidentally push an update which includes a crash, it can automatically roll back. This way, you can rest assured that your newfound release agility won't result in users becoming blocked before you have a chance to [roll back](https://docs.microsoft.com/en-us/appcenter/distribution/codepush/cli#rolling-back-updates) on the server. It's a win-win-win!
63
-
64
- *Note: Any product changes which touch native code (e.g. modifying your `AppDelegate.m`/`MainActivity.java` file, adding a new plugin) cannot be distributed via CodePush, and therefore, must be updated via the appropriate store(s).*
65
-
66
- ## Supported React Native platforms
67
-
68
- - iOS (7+)
69
- - Android (4.1+) on TLS 1.2 compatible devices
70
- - Windows (UWP)
71
-
72
- We try our best to maintain backwards compatibility of our plugin with previous versions of React Native, but due to the nature of the platform, and the existence of breaking changes between releases, it is possible that you need to use a specific version of the CodePush plugin in order to support the exact version of React Native you are using. The following table outlines which CodePush plugin versions officially support the respective React Native versions:
73
-
74
- | React Native version(s) | Supporting CodePush version(s) |
75
- |-------------------------|-------------------------------------------------------|
76
- | <0.14 | **Unsupported** |
77
- | v0.14 | v1.3 *(introduced Android support)* |
78
- | v0.15-v0.18 | v1.4-v1.6 *(introduced iOS asset support)* |
79
- | v0.19-v0.28 | v1.7-v1.17 *(introduced Android asset support)* |
80
- | v0.29-v0.30 | v1.13-v1.17 *(RN refactored native hosting code)* |
81
- | v0.31-v0.33 | v1.14.6-v1.17 *(RN refactored native hosting code)* |
82
- | v0.34-v0.35 | v1.15-v1.17 *(RN refactored native hosting code)* |
83
- | v0.36-v0.39 | v1.16-v1.17 *(RN refactored resume handler)* |
84
- | v0.40-v0.42 | v1.17 *(RN refactored iOS header files)* |
85
- | v0.43-v0.44 | v2.0+ *(RN refactored uimanager dependencies)* |
86
- | v0.45 | v3.0+ *(RN refactored instance manager code)* |
87
- | v0.46 | v4.0+ *(RN refactored js bundle loader code)* |
88
- | v0.46-v0.53 | v5.1+ *(RN removed unused registration of JS modules)*|
89
- | v0.54-v0.55 | v5.3+ *(Android Gradle Plugin 3.x integration)* |
90
- | v0.56-v0.58 | v5.4+ *(RN upgraded versions for Android tools)* |
91
- | v0.59 | v5.6+ *(RN refactored js bundle loader code)* |
92
- | v0.60-v0.61 | v6.0+ *(RN migrated to Autolinking)* |
93
- | v0.62-v0.64 | v6.2+ *(RN removed LiveReload)* |
94
- | v0.65-v0.70 | v7.0+ *(RN updated iPhone-target-version)* |
95
- | v0.71 | v8.0+ *(RN moved to react-native-gradle-plugin)* |
96
-
97
- *NOTE: `react-native-code-push` versions lower than **[v5.7.0](https://github.com/microsoft/react-native-code-push/releases/tag/v5.7.0)** will stop working in the near future. You can find more information in our [documentation](https://github.com/microsoft/code-push/blob/master/migration-notice.md).*
98
-
99
- We work hard to respond to new RN releases, but they do occasionally break us. We will update this chart with each RN release, so that users can check to see what our "official" support is.
100
-
101
- ### Supported Components
102
-
103
- When using the React Native assets system (i.e. using the `require("./foo.png")` syntax), the following list represents the set of core components (and props) that support having their referenced images and videos updated via CodePush:
104
-
105
- | Component | Prop(s) |
106
- |-------------------------------------------------|------------------------------------------|
107
- | `Image` | `source` |
108
- | `MapView.Marker` <br />*(Requires [react-native-maps](https://github.com/lelandrichardson/react-native-maps) `>=O.3.2`)* | `image` |
109
- | `ProgressViewIOS` | `progressImage`, `trackImage` |
110
- | `TabBarIOS.Item` | `icon`, `selectedIcon` |
111
- | `ToolbarAndroid` <br />*(React Native 0.21.0+)* | `actions[].icon`, `logo`, `overflowIcon` |
112
- | `Video` | `source` |
113
-
114
- The following list represents the set of components (and props) that don't currently support their assets being updated via CodePush, due to their dependency on static images and videos (i.e. using the `{ uri: "foo" }` syntax):
115
-
116
- | Component | Prop(s) |
117
- |-------------|----------------------------------------------------------------------|
118
- | `SliderIOS` | `maximumTrackImage`, `minimumTrackImage`, `thumbImage`, `trackImage` |
119
- | `Video` | `source` |
120
-
121
- As new core components are released, which support referencing assets, we'll update this list to ensure users know what exactly they can expect to update using CodePush.
122
-
123
- *Note: CodePush only works with Video components when using `require` in the source prop. For example:*
124
-
125
- ```javascript
126
- <Video source={require("./foo.mp4")} />
127
- ```
128
-
129
- ## Getting Started
130
-
131
- Once you've followed the general-purpose ["getting started"](https://docs.microsoft.com/en-us/appcenter/distribution/codepush/index) instructions for setting up your CodePush account, you can start CodePush-ifying your React Native app by running the following command from within your app's root directory:
18
+ ## Installation
19
+ Run the following command to add the Appcircle CodePush SDK to your project.
132
20
 
133
21
  ```shell
134
- npm install --save react-native-code-push
22
+ npm install @appcircle/react-native-code-push
135
23
  ```
136
24
 
137
- As with all other React Native plugins, the integration experience is different for iOS and Android, so perform the following setup steps depending on which platform(s) you are targeting. Note, if you are targeting both platforms it is recommended to create separate CodePush applications for each platform.
138
-
139
- If you want to see how other projects have integrated with CodePush, you can check out the excellent [example apps](#example-apps--starters) provided by the community. Additionally, if you'd like to quickly familiarize yourself with CodePush + React Native, you can check out the awesome getting started videos produced by [Bilal Budhani](https://www.youtube.com/watch?v=uN0FRWk-YW8&feature=youtu.be) and/or [Deepak Sisodiya ](https://www.youtube.com/watch?v=f6I9y7V-Ibk).
140
-
141
- *NOTE: This guide assumes you have used the `react-native init` command to initialize your React Native project. As of March 2017, the command `create-react-native-app` can also be used to initialize a React Native project. If using this command, please run `npm run eject` in your project's home directory to get a project very similar to what `react-native init` would have created.*
142
-
143
- Then continue with installing the native module
144
- * [iOS Setup](docs/setup-ios.md)
145
- * [Android Setup](docs/setup-android.md)
146
- * [Windows Setup](docs/setup-windows.md)
147
-
148
-
149
- ## Plugin Usage
150
-
151
- 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:
152
-
153
- 1. When (and how often) to check for an update? (for example app start, in response to clicking a button in a settings page, periodically at some fixed interval)
154
-
155
- 2. When an update is available, how to present it to the end user?
156
-
157
- The simplest way to do this is to "CodePush-ify" your app's root component. To do so, you can choose one of the following two options:
158
-
159
- * **Option 1: Wrap your root component with the `codePush` higher-order component:**
160
-
161
- * For class component
25
+ ## Platform Setup
162
26
 
163
- ```javascript
164
- import codePush from "react-native-code-push";
27
+ ### iOS Setup
165
28
 
166
- class MyApp extends Component {
167
- }
168
-
169
- MyApp = codePush(MyApp);
170
- ```
171
-
172
- * For functional component
173
-
174
- ```javascript
175
- import codePush from "react-native-code-push";
176
-
177
- let MyApp: () => React$Node = () => {
178
- }
179
-
180
- MyApp = codePush(MyApp);
181
- ```
182
-
183
- * **Option 2: Use the [ES7 decorator](https://github.com/wycats/javascript-decorators) syntax:**
184
-
185
- *NOTE: Decorators are not yet supported in Babel 6.x pending proposal update.* You may need to enable it by installing and using [babel-preset-react-native-stage-0](https://github.com/skevy/babel-preset-react-native-stage-0#babel-preset-react-native-stage-0).
186
-
187
- * For class component
188
-
189
- ```javascript
190
- import codePush from "react-native-code-push";
191
-
192
- @codePush
193
- class MyApp extends Component {
194
- }
195
- ```
196
-
197
- * For functional component
198
-
199
- ```javascript
200
- import codePush from "react-native-code-push";
201
-
202
- const MyApp: () => React$Node = () => {
203
- }
204
-
205
- export default codePush(MyApp);
206
- ```
207
-
208
- By default, CodePush will check for updates on every app start. If an update is available, it will be silently downloaded, and installed the next time the app is restarted (either explicitly by the end user or by the OS), which ensures the least invasive experience for your end users. If an available update is mandatory, then it will be installed immediately, ensuring that the end user gets it as soon as possible.
209
-
210
- If you would like your app to discover updates more quickly, you can also choose to sync up with the CodePush server every time the app resumes from the background.
211
-
212
- * For class component
213
-
214
- ```javascript
215
- let codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
216
-
217
- class MyApp extends Component {
218
- }
29
+ 1. Add the following to your `Podfile`:
30
+ ```ruby
31
+ pod 'CodePush', :path => '../node_modules/@appcircle/react-native-code-push'
32
+ ```
219
33
 
220
- MyApp = codePush(codePushOptions)(MyApp);
221
- ```
34
+ 2. Run `pod install` in the iOS directory
222
35
 
223
- * For functional component
36
+ ### Android Setup
224
37
 
225
- ```javascript
226
- let codePushOptions = { checkFrequency: codePush.CheckFrequency.ON_APP_RESUME };
38
+ 1. Add the following to your `android/settings.gradle`:
39
+ ```gradle
40
+ include ':appcircle-react-native-code-push'
41
+ project(':appcircle-react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/@appcircle/react-native-code-push/android/app')
42
+ ```
227
43
 
228
- let MyApp: () => React$Node = () => {
229
- }
44
+ 2. Add the following to your `android/app/build.gradle`:
45
+ ```gradle
46
+ dependencies {
47
+ implementation project(':appcircle-react-native-code-push')
48
+ }
49
+ ```
230
50
 
231
- MyApp = codePush(codePushOptions)(MyApp);
232
- ```
51
+ ## Basic Usage
233
52
 
234
- Alternatively, if you want fine-grained control over when the check happens (like a button press or timer interval), you can call [`CodePush.sync()`](docs/api-js.md#codepushsync) at any time with your desired `SyncOptions`, and optionally turn off CodePush's automatic checking by specifying a manual `checkFrequency`:
53
+ ### JavaScript Integration
235
54
 
236
55
  ```javascript
237
- let codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };
56
+ import codePush from "@appcircle/react-native-code-push";
238
57
 
58
+ // For class components
239
59
  class MyApp extends Component {
240
- onButtonPress() {
241
- codePush.sync({
242
- updateDialog: true,
243
- installMode: codePush.InstallMode.IMMEDIATE
244
- });
245
- }
246
-
247
- render() {
248
- return (
249
- <View>
250
- <TouchableOpacity onPress={this.onButtonPress}>
251
- <Text>Check for updates</Text>
252
- </TouchableOpacity>
253
- </View>
254
- )
255
- }
60
+ // Your component code
256
61
  }
62
+ MyApp = codePush(MyApp);
257
63
 
258
- MyApp = codePush(codePushOptions)(MyApp);
64
+ // For functional components
65
+ const MyApp = () => {
66
+ // Your component code
67
+ }
68
+ export default codePush(MyApp);
259
69
  ```
260
70
 
261
- If you would like to display an update confirmation dialog (an "active install"), configure when an available update is installed (like force an immediate restart) or customize the update experience in any other way, refer to the [`codePush()`](docs/api-js.md#codepush) API reference for information on how to tweak this default behavior.
262
-
263
- *NOTE: If you are using [Redux](http://redux.js.org) and [Redux Saga](https://redux-saga.js.org/), you can alternatively use the [react-native-code-push-saga](http://github.com/lostintangent/react-native-code-push-saga) module, which allows you to customize when `sync` is called in a perhaps simpler/more idiomatic way.*
264
-
265
- ### Store Guideline Compliance
266
-
267
- Android Google Play and iOS App Store have corresponding guidelines that have rules you should be aware of before integrating the CodePush solution within your application.
268
-
269
- #### Google play
270
-
271
- Third paragraph of [Device and Network Abuse](https://support.google.com/googleplay/android-developer/answer/9888379?hl=en) topic describe that updating source code by any method other than Google Play's update mechanism is restricted. But this restriction does not apply to updating javascript bundles.
272
- > This restriction does not apply to code that runs in a virtual machine and has limited access to Android APIs (such as JavaScript in a webview or browser).
273
-
274
- That fully allow CodePush as it updates just JS bundles and can't update native code part.
275
-
276
- #### App Store
71
+ ### Configuration Options
277
72
 
278
- Paragraph **3.3.2**, since back in 2015's [Apple Developer Program License Agreement](https://developer.apple.com/programs/ios/information/) fully allowed performing over-the-air updates of JavaScript and assets - and in its latest version (20170605) [downloadable here](https://developer.apple.com/terms/) this ruling is even broader:
279
-
280
- > Interpreted code may be downloaded to an Application but only so long as such code: (a) does not change the primary purpose of the Application by providing features or functionality that are inconsistent with the intended and advertised purpose of the Application as submitted to the App Store, (b) does not create a store or storefront for other code or applications, and (c) does not bypass signing, sandbox, or other security features of the OS.
281
-
282
- CodePush allows you to follow these rules in full compliance so long as the update you push does not significantly deviate your product from its original App Store approved intent.
283
-
284
- To further remain in compliance with Apple's guidelines we suggest that App Store-distributed apps don't enable the `updateDialog` option when calling `sync`, since in the [App Store Review Guidelines](https://developer.apple.com/app-store/review/guidelines/) it is written that:
285
-
286
- > Apps must not force users to rate the app, review the app, download other apps, or other similar actions in order to access functionality, content, or use of the app.
73
+ ```javascript
74
+ let codePushOptions = {
75
+ checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
76
+ };
287
77
 
288
- This is not necessarily the case for `updateDialog`, since it won't force the user to download the new version, but at least you should be aware of that ruling if you decide to show it.
78
+ // Apply options
79
+ MyApp = codePush(codePushOptions)(MyApp);
80
+ ```
289
81
 
290
82
  ## Releasing Updates
291
83
 
292
- Once your app is configured and distributed to your users, and you have made some JS or asset changes, it's time to release them. The recommended way to release them is using the `release-react` command in the App Center CLI, which will bundle your JavaScript files, asset files, and release the update to the CodePush server.
293
-
294
- *NOTE: Before you can start releasing updates, please log into App Center by running the `appcenter login` command.*
84
+ ### Manual Release
295
85
 
296
- In its most basic form, this command only requires one parameter: your owner name + "/" + app name.
86
+ Use the Appcircle CLI to release updates:
297
87
 
298
88
  ```shell
299
- appcenter codepush release-react -a <ownerName>/<appName>
89
+ # Basic release
90
+ appcircle-code-push release-react -a <AppName>/<Deployment Name>
300
91
 
301
- appcenter codepush release-react -a <ownerName>/MyApp-iOS
302
- appcenter codepush release-react -a <ownerName>/MyApp-Android
92
+ # Release with specific options
93
+ appcircle-code-push release-react -a <AppName>/<DeplymentName> -m --description "Update description"
303
94
  ```
304
95
 
305
96
  The `release-react` command enables such a simple workflow because it provides many sensible defaults (like generating a release bundle, assuming your app's entry file on iOS is either `index.ios.js` or `index.js`). However, all of these defaults can be customized to allow incremental flexibility as necessary, which makes it a good fit for most scenarios.
306
97
 
307
- ```shell
308
- # Release a mandatory update with a changelog
309
- appcenter codepush release-react -a <ownerName>/MyApp-iOS -m --description "Modified the header color"
310
-
311
- # Release an update for an app that uses a non-standard entry file name, and also capture
312
- # the sourcemap file generated by react-native bundle
313
- appcenter codepush release-react -a <ownerName>/MyApp-iOS --entry-file MyApp.js --sourcemap-output ../maps/MyApp.map
314
-
315
- # Release a dev Android build to just 1/4 of your end users
316
- appcenter codepush release-react -a <ownerName>/MyApp-Android --rollout 25 --development true
317
-
318
- # Release an update that targets users running any 1.1.* binary, as opposed to
319
- # limiting the update to exact version name in the build.gradle file
320
- appcenter codepush release-react -a <ownerName>/MyApp-Android --target-binary-version "~1.1.0"
321
-
322
- ```
323
-
324
- The CodePush client supports differential updates, so even though you are releasing your JS bundle and assets on every update, your end users will only actually download the files they need. The service handles this automatically so that you can focus on creating awesome apps and we can worry about optimizing end user downloads.
325
-
326
- For more details about how the `release-react` command works, as well as the various parameters it exposes, refer to the [CLI docs](https://github.com/microsoft/code-push/tree/v3.0.1/cli#releasing-updates-react-native). Additionally, if you would prefer to handle running the `react-native bundle` command yourself, and therefore, want an even more flexible solution than `release-react`, refer to the [`release` command](https://github.com/microsoft/code-push/tree/v3.0.1/cli#releasing-updates-general) for more details.
327
-
328
- If you run into any issues, or have any questions/comments/feedback, you can ping us within the [#code-push](https://discord.gg/0ZcbPKXt5bWxFdFu) channel on Reactiflux, [e-mail us](mailto:codepushfeed@microsoft.com) and/or check out the [troubleshooting](#debugging--troubleshooting) details below.
329
-
330
- *NOTE: CodePush updates should be tested in modes other than Debug mode. In Debug mode, React Native app always downloads JS bundle generated by packager, so JS bundle downloaded by CodePush does not apply.*
331
-
332
- ### Multi-Deployment Testing
333
-
334
- In our [getting started](#getting-started) docs, we illustrated how to configure the CodePush plugin using a specific deployment key. However, in order to effectively test your releases, it is critical that you leverage the `Staging` and `Production` deployments that are auto-generated when you first created your CodePush app (or any custom deployments you may have created). This way, you never release an update to your end users that you haven't been able to validate yourself.
335
-
336
- *NOTE: Our client-side rollback feature can help unblock users after installing a release that resulted in a crash, and server-side rollbacks (i.e. `appcenter codepush rollback`) allow you to prevent additional users from installing a bad release once it's been identified. However, it's obviously better if you can prevent an erroneous update from being broadly released in the first place.*
337
-
338
- Taking advantage of the `Staging` and `Production` deployments allows you to achieve a workflow like the following (feel free to customize!):
339
-
340
- 1. Release a CodePush update to your `Staging` deployment using the `appcenter codepush release-react` command (or `appcenter codepush release` if you need more control)
341
-
342
- 2. Run your staging/beta build of your app, sync the update from the server, and verify it works as expected
343
-
344
- 3. Promote the tested release from `Staging` to `Production` using the `appcenter codepush promote` command
345
-
346
- 4. Run your production/release build of your app, sync the update from the server and verify it works as expected
347
-
348
- *NOTE: If you want to take a more cautious approach, you can even choose to perform a "staged rollout" as part of #3, which allows you to mitigate additional potential risk with the update (like did your testing in #2 touch all possible devices/conditions?) by only making the production update available to a percentage of your users (for example `appcenter codepush promote -a <ownerName>/<appName> -s Staging -d Production -r 20`). Then, after waiting for a reasonable amount of time to see if any crash reports or customer feedback comes in, you can expand it to your entire audience by running `appcenter codepush patch -a <ownerName>/<appName> Production -r 100`.*
349
-
350
- You'll notice that the above steps refer to a "staging build" and "production build" of your app. If your build process already generates distinct binaries per "environment", then you don't need to read any further, since swapping out CodePush deployment keys is just like handling environment-specific config for any other service your app uses (like Facebook). However, if you're looking for examples (**including demo projects**) on how to setup your build process to accommodate this, then refer to the following sections, depending on the platform(s) your app is targeting:
351
-
352
- * [Android](docs/multi-deployment-testing-android.md)
353
- * [iOS](docs/multi-deployment-testing-ios.md)
354
-
355
-
356
- ### Dynamic Deployment Assignment
357
-
358
- The above section illustrated how you can leverage multiple CodePush deployments in order to effectively test your updates before broadly releasing them to your end users. However, since that workflow statically embeds the deployment assignment into the actual binary, a staging or production build will only ever sync updates from that deployment. In many cases, this is sufficient, since you only want your team, customers, stakeholders, etc. to sync with your pre-production releases, and therefore, only they need a build that knows how to sync with staging. However, if you want to be able to perform A/B tests, or provide early access of your app to certain users, it can prove very useful to be able to dynamically place specific users (or audiences) into specific deployments at runtime.
359
-
360
- In order to achieve this kind of workflow, all you need to do is specify the deployment key you want the current user to syncronize with when calling the `codePush` method. When specified, this key will override the "default" one that was provided in your app's `Info.plist` (iOS) or `MainActivity.java` (Android) files. This allows you to produce a build for staging or production, that is also capable of being dynamically "redirected" as needed.
361
-
362
- ```javascript
363
- // Imagine that "userProfile" is a prop that this component received
364
- // which includes the deployment key that the current user should use.
365
- codePush.sync({ deploymentKey: userProfile.CODEPUSH_KEY });
366
- ```
367
-
368
- With that change in place, now it's just a matter of choosing how your app determines the right deployment key for the current user. In practice, there are typically two solutions for this:
369
-
370
- 1. Expose a user-visible mechanism for changing deployments at any time. For example, your settings page could have a toggle for enabling "beta" access. This model works well if you're not concerned with the privacy of your pre-production updates, and you have power users that may want to opt-in to earlier (and potentially buggy) updates at their own will (kind of like Chrome channels). However, this solution puts the decision in the hands of your users, which doesn't help you perform A/B tests transparently.
371
-
372
- 2. Annotate the server-side profile of your users with an additional piece of metadata that indicates the deployment they should sync with. By default, your app could just use the binary-embedded key, but after a user has authenticated, your server can choose to "redirect" them to a different deployment, which allows you to incrementally place certain users or groups in different deployments as needed. You could even choose to store the server-response in local storage so that it becomes the new default. How you store the key alongside your user's profiles is entirely up to your authentication solution (for example Auth0, Firebase, custom DB + REST API), but is generally pretty trivial to do.
373
-
374
- *NOTE: If needed, you could also implement a hybrid solution that allowed your end-users to toggle between different deployments, while also allowing your server to override that decision. This way, you have a hierarchy of "deployment resolution" that ensures your app has the ability to update itself out-of-the-box, your end users can feel rewarded by getting early access to bits, but you also have the ability to run A/B tests on your users as needed.*
375
-
376
- Since we recommend using the `Staging` deployment for pre-release testing of your updates (as explained in the previous section), it doesn't neccessarily make sense to use it for performing A/B tests on your users, as opposed to allowing early-access (as explained in option #1 above). Therefore, we recommend making full use of custom app deployments, so that you can segment your users however makes sense for your needs. For example, you could create long-term or even one-off deployments, release a variant of your app to it, and then place certain users into it in order to see how they engage.
377
-
378
- ```javascript
379
- // #1) Create your new deployment to hold releases of a specific app variant
380
- appcenter codepush deployment add -a <ownerName>/<appName> test-variant-one
381
-
382
- // #2) Target any new releases at that custom deployment
383
- appcenter codepush release-react -a <ownerName>/<appName> -d test-variant-one
384
- ```
385
-
386
- *NOTE: The total user count that is reported in your deployment's "Install Metrics" will take into account users that have "switched" from one deployment to another. For example, if your `Production` deployment currently reports having 1 total user, but you dynamically switch that user to `Staging`, then the `Production` deployment would report 0 total users, while `Staging` would report 1 (the user that just switched). This behavior allows you to accurately track your release adoption, even in the event of using a runtime-based deployment redirection solution.*
387
-
388
- ---
389
-
390
- ## API Reference
391
-
392
- * [JavaScript API](docs/api-js.md)
393
- * [Objective-C API Reference (iOS)](docs/api-ios.md)
394
- * [Java API Reference (Android)](docs/api-android.md)
395
-
396
- ### Example Apps / Starters
397
-
398
- The React Native community has graciously created some awesome open source apps that can serve as examples for developers that are getting started. The following is a list of OSS React Native apps that are also using CodePush, and can therefore be used to see how others are using the service:
399
-
400
- * [F8 App](https://github.com/fbsamples/f8app) - The official conference app for [F8 2016](https://www.fbf8.com/).
401
- * [Feline for Product Hunt](https://github.com/arjunkomath/Feline-for-Product-Hunt) - An Android client for Product Hunt.
402
- * [GeoEncoding](https://github.com/LynxITDigital/GeoEncoding) - An app by [Lynx IT Digital](https://digital.lynxit.com.au) which demonstrates how to use numerous React Native components and modules.
403
- * [Math Facts](https://github.com/Khan/math-facts) - An app by Khan Academy to help memorize math facts more easily.
404
-
405
- Additionally, if you're looking to get started with React Native + CodePush, and are looking for an awesome starter kit, you should check out the following:
406
-
407
- * [Pepperoni](http://getpepperoni.com/)
408
-
409
- *Note: If you've developed a React Native app using CodePush, that is also open-source, please let us know. We would love to add it to this list!*
410
-
411
- ### Debugging / Troubleshooting
412
-
413
- The `sync` method includes a lot of diagnostic logging out-of-the-box, so if you're encountering an issue when using it, the best thing to try first is examining the output logs of your app. This will tell you whether the app is configured correctly (like can the plugin find your deployment key?), if the app is able to reach the server, if an available update is being discovered, if the update is being successfully downloaded/installed, etc. We want to continue improving the logging to be as intuitive/comprehensive as possible, so please [let us know](mailto:codepushfeed@microsoft.com) if you find it to be confusing or missing anything.
414
-
415
- The simplest way to view these logs is to add the flag `--debug` for each command. This will output a log stream that is filtered to just CodePush messages. This makes it easy to identify issues, without needing to use a platform-specific tool, or wade through a potentially high volume of logs.
416
-
417
- <img width="540" alt="screen shot 2016-06-21 at 10 15 42 am" src="https://cloud.githubusercontent.com/assets/116461/16246973/838e2e98-37bc-11e6-9649-685f39e325a0.png">
418
-
419
- Additionally, you can also use any of the platform-specific tools to view the CodePush logs, if you are more comfortable with them. Simple start up the Chrome DevTools Console, the Xcode Console (iOS), the [OS X Console](https://en.wikipedia.org/wiki/Console_%28OS_X%29#.7E.2FLibrary.2FLogs) (iOS) and/or ADB logcat (Android), and look for messages which are prefixed with `[CodePush]`.
420
-
421
- Note that by default, React Native logs are disabled on iOS in release builds, so if you want to view them in a release build, you need to make the following changes to your `AppDelegate.m` file:
422
-
423
- 1. Add an `#import <React/RCTLog.h>` statement. For RN < v0.40 use: `#import "RCTLog.h"`
424
-
425
- 2. Add the following statement to the top of your `application:didFinishLaunchingWithOptions` method:
98
+ ### Automated Release
426
99
 
427
- ```objective-c
428
- RCTSetLogThreshold(RCTLogLevelInfo);
429
- ```
100
+ For Appcircle CodePush release automation, please visit the Appcircle CodePush workflow step [documentation](https://docs.appcircle.io/workflows/react-native-specific-workflow-steps/appcircle-codepush).
430
101
 
431
- Now you'll be able to see CodePush logs in either debug or release mode, on both iOS or Android. If examining the logs don't provide an indication of the issue, please refer to the following common issues for additional resolution ideas:
102
+ ## Multi-Deployment Testing
432
103
 
433
- | Issue / Symptom | Possible Solution |
434
- |-----------------|-------------------|
435
- | Compilation Error | Double-check that your version of React Native is [compatible](#supported-react-native-platforms) with the CodePush version you are using. |
436
- | Network timeout / hang when calling `sync` or `checkForUpdate` in the iOS Simulator | Try resetting the simulator by selecting the `Simulator -> Reset Content and Settings..` menu item, and then re-running your app. |
437
- | Server responds with a `404` when calling `sync` or `checkForUpdate` | Double-check that the deployment key you added to your `Info.plist` (iOS), `build.gradle` (Android) or that you're passing to `sync`/`checkForUpdate`, is in fact correct. You can run `appcenter codepush deployment list <ownerName>/<appName> --displayKeys` to view the correct keys for your app deployments. |
438
- | Update not being discovered | Double-check that the version of your running app (like `1.0.0`) matches the version you specified when releasing the update to CodePush. Additionally, make sure that you are releasing to the same deployment that your app is configured to sync with. |
439
- | Update not being displayed after restart | If you're not calling `sync` on app start (like within `componentDidMount` of your root component), then you need to explicitly call `notifyApplicationReady` on app start, otherwise, the plugin will think your update failed and roll it back. |
440
- | I've released an update for iOS but my Android app also shows an update and it breaks it | Be sure you have different deployment keys for each platform in order to receive updates correctly |
441
- | I've released new update but changes are not reflected | Be sure that you are running app in modes other than Debug. In Debug mode, React Native app always downloads JS bundle generated by packager, so JS bundle downloaded by CodePush does not apply.
442
- | No JS bundle is being found when running your app against the iOS simulator | By default, React Native doesn't generate your JS bundle when running against the simulator. Therefore, if you're using `[CodePush bundleURL]`, and targetting the iOS simulator, you may be getting a `nil` result. This issue will be fixed in RN 0.22.0, but only for release builds. You can unblock this scenario right now by making [this change](https://github.com/facebook/react-native/commit/9ae3714f4bebdd2bcab4d7fdbf23acebdc5ed2ba) locally.
104
+ The SDK supports multiple deployment environments through Appcircle:
443
105
 
444
- ### Continuous Integration / Delivery
106
+ - **Staging**: For testing updates before production
107
+ - **Production**: For end-user updates
108
+ - **Custom Deployments**: For A/B testing or specific user groups
445
109
 
446
- In addition to being able to use the CodePush CLI to "manually" release updates, we believe that it's important to create a repeatable and sustainable solution for contiously delivering updates to your app. That way, it's simple enough for you and/or your team to create and maintain the rhythm of performing agile deployments. In order to assist with setting up a CodePush-based CD pipeline, refer to the following integrations with various CI servers:
447
110
 
448
- * [Visual Studio Team Services](https://marketplace.visualstudio.com/items?itemName=ms-vsclient.code-push) - *NOTE: VSTS also has extensions for publishing to [HockeyApp](https://marketplace.visualstudio.com/items?itemName=ms.hockeyapp) and the [Google Play](https://github.com/microsoft/google-play-vsts-extension) store, so it provides a pretty great mobile CD solution in general.*
449
- * [Travis CI](https://github.com/mondora/code-push-travis-cli)
111
+ ## Contributing
450
112
 
451
- Additionally, if you'd like more details of what a complete mobile CI/CD workflow can look like, which includes CodePush, check out this [excellent article](https://medium.com/zeemee-engineering/zeemee-engineering-and-the-quest-for-the-holy-mobile-dev-grail-1310be4953d1) by the [ZeeMee engineering team](https://www.zeemee.com/).
113
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
452
114
 
453
- ### TypeScript Consumption
115
+ ## License
454
116
 
455
- This module ships its `*.d.ts` file as part of its NPM package, which allows you to simply `import` it, and receive intellisense in supporting editors (like Visual Studio Code), as well as compile-time type checking if you're using TypeScript. For the most part, this behavior should just work out of the box, however, if you've specified `es6` as the value for either the `target` or `module` [compiler option](http://www.typescriptlang.org/docs/handbook/compiler-options.html) in your [`tsconfig.json`](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) file, then just make sure that you also set the `moduleResolution` option to `node`. This ensures that the TypeScript compiler will look within the `node_modules` for the type definitions of imported modules. Otherwise, you'll get an error like the following when trying to import the `react-native-code-push` module: `error TS2307: Cannot find module 'react-native-code-push'`.
117
+ This project is licensed under the MIT License - see the LICENSE file for details.
456
118
 
457
- ---
119
+ ## Support
458
120
 
459
- This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
121
+ For support with Appcircle integration:
122
+ - Visit [Appcircle Documentation](https://docs.appcircle.io)
123
+ - Contact [Appcircle Support](https://appcircle.io/contact)
@@ -21,5 +21,13 @@
21
21
  private final ** mBundleLoader;
22
22
  }
23
23
 
24
+ -keepclassmembers class com.facebook.react.runtime.ReactHostImpl {
25
+ private final ** mReactHostDelegate;
26
+ }
27
+
28
+ -keep interface com.facebook.react.runtime.ReactHostDelegate { *; }
29
+
30
+ -keep class * implements com.facebook.react.runtime.ReactHostDelegate { *; }
31
+
24
32
  # Can't find referenced class org.bouncycastle.**
25
33
  -dontwarn com.nimbusds.jose.**
@@ -21,6 +21,18 @@ import java.util.ArrayList;
21
21
  import java.util.List;
22
22
 
23
23
  public class CodePush implements ReactPackage {
24
+ private static final Object LOCK = new Object();
25
+ private static volatile CodePush mCurrentInstance;
26
+ public static CodePush getInstance(String deploymentKey, Context context, boolean isDebugMode) {
27
+ if (mCurrentInstance == null) {
28
+ synchronized (LOCK) {
29
+ if (mCurrentInstance == null) {
30
+ mCurrentInstance = new CodePush(deploymentKey, context, isDebugMode);
31
+ }
32
+ }
33
+ }
34
+ return mCurrentInstance;
35
+ }
24
36
 
25
37
  private static boolean sIsRunningBinaryVersion = false;
26
38
  private static boolean sNeedToReportRollback = false;
@@ -38,7 +50,7 @@ public class CodePush implements ReactPackage {
38
50
 
39
51
  // Config properties.
40
52
  private String mDeploymentKey;
41
- private static String mServerUrl = "https://codepush.appcenter.ms/";
53
+ private static String mServerUrl = "https://api.appcircle.io/codepush";
42
54
 
43
55
  private Context mContext;
44
56
  private final boolean mIsDebugMode;
@@ -49,8 +61,6 @@ public class CodePush implements ReactPackage {
49
61
 
50
62
  private static ReactHostHolder mReactHostHolder;
51
63
 
52
- private static CodePush mCurrentInstance;
53
-
54
64
  public CodePush(String deploymentKey, Context context) {
55
65
  this(deploymentKey, context, false);
56
66
  }
@@ -59,7 +69,7 @@ public class CodePush implements ReactPackage {
59
69
  return mServerUrl;
60
70
  }
61
71
 
62
- public CodePush(String deploymentKey, Context context, boolean isDebugMode) {
72
+ private CodePush(String deploymentKey, Context context, boolean isDebugMode) {
63
73
  mContext = context.getApplicationContext();
64
74
 
65
75
  mUpdateManager = new CodePushUpdateManager(context.getFilesDir().getAbsolutePath());
@@ -90,18 +100,18 @@ public class CodePush implements ReactPackage {
90
100
  initializeUpdateAfterRestart();
91
101
  }
92
102
 
93
- public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl) {
103
+ private CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl) {
94
104
  this(deploymentKey, context, isDebugMode);
95
105
  mServerUrl = serverUrl;
96
106
  }
97
107
 
98
- public CodePush(String deploymentKey, Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
108
+ private CodePush(String deploymentKey, Context context, boolean isDebugMode, int publicKeyResourceDescriptor) {
99
109
  this(deploymentKey, context, isDebugMode);
100
110
 
101
111
  mPublicKey = getPublicKeyByResourceDescriptor(publicKeyResourceDescriptor);
102
112
  }
103
113
 
104
- public CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
114
+ private CodePush(String deploymentKey, Context context, boolean isDebugMode, String serverUrl, Integer publicKeyResourceDescriptor) {
105
115
  this(deploymentKey, context, isDebugMode);
106
116
 
107
117
  if (publicKeyResourceDescriptor != null) {
@@ -131,10 +141,10 @@ public class CodePush implements ReactPackage {
131
141
 
132
142
  private String getCustomPropertyFromStringsIfExist(String propertyName) {
133
143
  String property;
134
-
144
+
135
145
  String packageName = mContext.getPackageName();
136
146
  int resId = mContext.getResources().getIdentifier("CodePush" + propertyName, "string", packageName);
137
-
147
+
138
148
  if (resId != 0) {
139
149
  property = mContext.getString(resId);
140
150
 
@@ -142,7 +152,7 @@ public class CodePush implements ReactPackage {
142
152
  return property;
143
153
  } else {
144
154
  CodePushUtils.log("Specified " + propertyName + " is empty");
145
- }
155
+ }
146
156
  }
147
157
 
148
158
  return null;
@@ -431,4 +441,4 @@ public class CodePush implements ReactPackage {
431
441
  public List<ViewManager> createViewManagers(ReactApplicationContext reactApplicationContext) {
432
442
  return new ArrayList<>();
433
443
  }
434
- }
444
+ }
@@ -157,9 +157,6 @@ public class CodePushUpdateManager {
157
157
 
158
158
  String downloadUrlString = updatePackage.optString(CodePushConstants.DOWNLOAD_URL_KEY, null);
159
159
  HttpURLConnection connection = null;
160
- BufferedInputStream bin = null;
161
- FileOutputStream fos = null;
162
- BufferedOutputStream bout = null;
163
160
  File downloadFile = null;
164
161
  boolean isZip = false;
165
162
 
@@ -178,52 +175,51 @@ public class CodePushUpdateManager {
178
175
  }
179
176
 
180
177
  connection.setRequestProperty("Accept-Encoding", "identity");
181
- bin = new BufferedInputStream(connection.getInputStream());
182
178
 
183
179
  long totalBytes = connection.getContentLength();
184
180
  long receivedBytes = 0;
185
181
 
186
182
  File downloadFolder = new File(getCodePushPath());
187
183
  downloadFolder.mkdirs();
184
+
188
185
  downloadFile = new File(downloadFolder, CodePushConstants.DOWNLOAD_FILE_NAME);
189
- fos = new FileOutputStream(downloadFile);
190
- bout = new BufferedOutputStream(fos, CodePushConstants.DOWNLOAD_BUFFER_SIZE);
191
186
  byte[] data = new byte[CodePushConstants.DOWNLOAD_BUFFER_SIZE];
192
187
  byte[] header = new byte[4];
193
188
 
194
- int numBytesRead = 0;
195
- while ((numBytesRead = bin.read(data, 0, CodePushConstants.DOWNLOAD_BUFFER_SIZE)) >= 0) {
196
- if (receivedBytes < 4) {
197
- for (int i = 0; i < numBytesRead; i++) {
198
- int headerOffset = (int) (receivedBytes) + i;
199
- if (headerOffset >= 4) {
200
- break;
189
+ try (
190
+ BufferedInputStream bin = new BufferedInputStream(connection.getInputStream());
191
+ FileOutputStream fos = new FileOutputStream(downloadFile);
192
+ BufferedOutputStream bout = new BufferedOutputStream(fos, CodePushConstants.DOWNLOAD_BUFFER_SIZE)
193
+ ) {
194
+ int numBytesRead = 0;
195
+ while ((numBytesRead = bin.read(data, 0, CodePushConstants.DOWNLOAD_BUFFER_SIZE)) >= 0) {
196
+ if (receivedBytes < 4) {
197
+ for (int i = 0; i < numBytesRead; i++) {
198
+ int headerOffset = (int) (receivedBytes) + i;
199
+ if (headerOffset >= 4) {
200
+ break;
201
+ }
202
+
203
+ header[headerOffset] = data[i];
201
204
  }
202
-
203
- header[headerOffset] = data[i];
204
205
  }
206
+
207
+ receivedBytes += numBytesRead;
208
+ bout.write(data, 0, numBytesRead);
209
+ progressCallback.call(new DownloadProgress(totalBytes, receivedBytes));
205
210
  }
206
211
 
207
- receivedBytes += numBytesRead;
208
- bout.write(data, 0, numBytesRead);
209
- progressCallback.call(new DownloadProgress(totalBytes, receivedBytes));
210
- }
212
+ if (totalBytes != receivedBytes) {
213
+ throw new CodePushUnknownException("Received " + receivedBytes + " bytes, expected " + totalBytes);
214
+ }
211
215
 
212
- if (totalBytes != receivedBytes) {
213
- throw new CodePushUnknownException("Received " + receivedBytes + " bytes, expected " + totalBytes);
216
+ isZip = ByteBuffer.wrap(header).getInt() == 0x504b0304;
214
217
  }
215
-
216
- isZip = ByteBuffer.wrap(header).getInt() == 0x504b0304;
217
218
  } catch (MalformedURLException e) {
218
219
  throw new CodePushMalformedDataException(downloadUrlString, e);
219
220
  } finally {
220
- try {
221
- if (bout != null) bout.close();
222
- if (fos != null) fos.close();
223
- if (bin != null) bin.close();
224
- if (connection != null) connection.disconnect();
225
- } catch (IOException e) {
226
- throw new CodePushUnknownException("Error closing IO resources.", e);
221
+ if (connection != null) {
222
+ connection.disconnect();
227
223
  }
228
224
  }
229
225
 
@@ -347,32 +343,35 @@ public class CodePushUpdateManager {
347
343
  public void downloadAndReplaceCurrentBundle(String remoteBundleUrl, String bundleFileName) throws IOException {
348
344
  URL downloadUrl;
349
345
  HttpURLConnection connection = null;
350
- BufferedInputStream bin = null;
351
- FileOutputStream fos = null;
352
- BufferedOutputStream bout = null;
346
+
353
347
  try {
354
348
  downloadUrl = new URL(remoteBundleUrl);
355
349
  connection = (HttpURLConnection) (downloadUrl.openConnection());
356
- bin = new BufferedInputStream(connection.getInputStream());
350
+
357
351
  File downloadFile = new File(getCurrentPackageBundlePath(bundleFileName));
358
- downloadFile.delete();
359
- fos = new FileOutputStream(downloadFile);
360
- bout = new BufferedOutputStream(fos, CodePushConstants.DOWNLOAD_BUFFER_SIZE);
361
- byte[] data = new byte[CodePushConstants.DOWNLOAD_BUFFER_SIZE];
362
- int numBytesRead = 0;
363
- while ((numBytesRead = bin.read(data, 0, CodePushConstants.DOWNLOAD_BUFFER_SIZE)) >= 0) {
364
- bout.write(data, 0, numBytesRead);
352
+ if (downloadFile.exists() && !downloadFile.delete()) {
353
+ // Silent failure, but execution continues
354
+ }
355
+
356
+ try (
357
+ BufferedInputStream bin = new BufferedInputStream(connection.getInputStream());
358
+ FileOutputStream fos = new FileOutputStream(downloadFile);
359
+ BufferedOutputStream bout = new BufferedOutputStream(fos, CodePushConstants.DOWNLOAD_BUFFER_SIZE)
360
+ ) {
361
+ byte[] data = new byte[CodePushConstants.DOWNLOAD_BUFFER_SIZE];
362
+ int numBytesRead;
363
+ while ((numBytesRead = bin.read(data, 0, CodePushConstants.DOWNLOAD_BUFFER_SIZE)) >= 0) {
364
+ bout.write(data, 0, numBytesRead);
365
+ }
365
366
  }
367
+
366
368
  } catch (MalformedURLException e) {
367
369
  throw new CodePushMalformedDataException(remoteBundleUrl, e);
370
+ } catch (IOException e) {
371
+ throw new CodePushUnknownException("Error handling IO streams.", e);
368
372
  } finally {
369
- try {
370
- if (bout != null) bout.close();
371
- if (fos != null) fos.close();
372
- if (bin != null) bin.close();
373
- if (connection != null) connection.disconnect();
374
- } catch (IOException e) {
375
- throw new CodePushUnknownException("Error closing IO resources.", e);
373
+ if (connection != null) {
374
+ connection.disconnect();
376
375
  }
377
376
  }
378
377
  }
@@ -380,4 +379,4 @@ public class CodePushUpdateManager {
380
379
  public void clearUpdates() {
381
380
  FileUtils.deleteDirectoryAtPath(getCodePushPath());
382
381
  }
383
- }
382
+ }
@@ -62,11 +62,14 @@ public class CodePushUpdateUtils {
62
62
  if (file.isDirectory()) {
63
63
  addContentsOfFolderToManifest(fullFilePath, relativePath, manifest);
64
64
  } else {
65
- try {
66
- manifest.add(relativePath + ":" + computeHash(new FileInputStream(file)));
65
+ try (FileInputStream fis = new FileInputStream(file)) {
66
+ manifest.add(relativePath + ":" + computeHash(fis));
67
67
  } catch (FileNotFoundException e) {
68
68
  // Should not happen.
69
69
  throw new CodePushUnknownException("Unable to compute hash of update contents.", e);
70
+ } catch (IOException e) {
71
+ // Should not happen.
72
+ throw new CodePushUnknownException("Error occurred while reading file for hashing.", e);
70
73
  }
71
74
  }
72
75
  }
@@ -272,4 +275,4 @@ public class CodePushUpdateUtils {
272
275
 
273
276
  CodePushUtils.log("The update contents succeeded the code signing check.");
274
277
  }
275
- }
278
+ }
@@ -29,26 +29,19 @@ public class FileUtils {
29
29
  CodePushUtils.appendPathComponent(destinationDirectoryPath, sourceFile.getName()));
30
30
  } else {
31
31
  File destFile = new File(destDir, sourceFile.getName());
32
- FileInputStream fromFileStream = null;
33
- BufferedInputStream fromBufferedStream = null;
34
- FileOutputStream destStream = null;
35
32
  byte[] buffer = new byte[WRITE_BUFFER_SIZE];
36
- try {
37
- fromFileStream = new FileInputStream(sourceFile);
38
- fromBufferedStream = new BufferedInputStream(fromFileStream);
39
- destStream = new FileOutputStream(destFile);
33
+ try (
34
+ FileInputStream fromFileStream = new FileInputStream(sourceFile);
35
+ BufferedInputStream fromBufferedStream = new BufferedInputStream(fromFileStream);
36
+ FileOutputStream destStream = new FileOutputStream(destFile)
37
+ )
38
+ {
40
39
  int bytesRead;
41
40
  while ((bytesRead = fromBufferedStream.read(buffer)) > 0) {
42
41
  destStream.write(buffer, 0, bytesRead);
43
42
  }
44
- } finally {
45
- try {
46
- if (fromFileStream != null) fromFileStream.close();
47
- if (fromBufferedStream != null) fromBufferedStream.close();
48
- if (destStream != null) destStream.close();
49
- } catch (IOException e) {
50
- throw new CodePushUnknownException("Error closing IO resources.", e);
51
- }
43
+ } catch (IOException e) {
44
+ throw new CodePushUnknownException("Error closing IO resources.", e);
52
45
  }
53
46
  }
54
47
  }
@@ -200,4 +193,4 @@ public class FileUtils {
200
193
  if (out != null) out.close();
201
194
  }
202
195
  }
203
- }
196
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcircle/react-native-code-push",
3
- "version": "0.0.2-alpha.3",
3
+ "version": "0.0.2-alpha.5",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
@@ -3,8 +3,9 @@ module.exports = {
3
3
  platforms: {
4
4
  android: {
5
5
  packageInstance:
6
- "new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)"
6
+ "CodePush.getInstance(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)",
7
+ sourceDir: './android/app',
7
8
  }
8
9
  }
9
10
  }
10
- };
11
+ };
@@ -1,37 +0,0 @@
1
- package com.microsoft.codepush.react;
2
-
3
- import android.content.Context;
4
-
5
- public class CodePushBuilder {
6
- private String mDeploymentKey;
7
- private Context mContext;
8
-
9
- private boolean mIsDebugMode;
10
- private String mServerUrl;
11
- private Integer mPublicKeyResourceDescriptor;
12
-
13
- public CodePushBuilder(String deploymentKey, Context context) {
14
- this.mDeploymentKey = deploymentKey;
15
- this.mContext = context;
16
- this.mServerUrl = CodePush.getServiceUrl();
17
- }
18
-
19
- public CodePushBuilder setIsDebugMode(boolean isDebugMode) {
20
- this.mIsDebugMode = isDebugMode;
21
- return this;
22
- }
23
-
24
- public CodePushBuilder setServerUrl(String serverUrl) {
25
- this.mServerUrl = serverUrl;
26
- return this;
27
- }
28
-
29
- public CodePushBuilder setPublicKeyResourceDescriptor(int publicKeyResourceDescriptor) {
30
- this.mPublicKeyResourceDescriptor = publicKeyResourceDescriptor;
31
- return this;
32
- }
33
-
34
- public CodePush build() {
35
- return new CodePush(this.mDeploymentKey, this.mContext, this.mIsDebugMode, this.mServerUrl, this.mPublicKeyResourceDescriptor);
36
- }
37
- }