UNPKG

15.3 kBMarkdownView Raw
1# Installation
2
3- [Installation Requirements](#installation-requirements)
4- [Android details](#android-details)
5 - [Compilation](#compilation)
6 - [Co-existing with Facebook Plugin](#co-existing-with-facebook-plugin)
7 - [Co-existing with plugins that use Firebase](#co-existing-with-plugins-that-use-firebase)
8 - [Common errors](#common-errors)
9 - [minSdkVersion === 14](#minsdkversion--14)
10 - [Multidex](#multidex)
11 - [More than one library with package name 'com.google.android.gms'](#more-than-one-library-with-package-name-comgoogleandroidgms)
12- [Browser details](#browser-details)
13 - [Browser quirks](#browser-quirks)
14 - [Browser Support](#browser-support)
15- [iOS details](#ios-details)
16 - [Xcode](#xcode)
17 - [Bitcode](#bitcode)
18 - [CocoaPods](#cocoapods)
19 - [Common CocoaPod Installation issues](#common-cocoapod-installation-issues)
20 - [CocoaPod Disk Space](#cocoapod-disk-space)
21 - [Library not found for -lPods-Appname](#library-not-found-for--lPods-Appname)
22 - [Library not found for -lGoogleToolboxForMac](#library-not-found-for--lPods-Appname)
23- [Additional Resources](#additional-resources)
24
25## Installation Requirements
26
27Plugin version | Cordova CLI | Cordova Android | Cordova iOS | CocoaPods
28---- | ---- | ---- | ---- | ----
292.0.0 | 7.0.0 | 6.2.1 | 4.4.0 | 1.1.1
301.9.0 | 6.4.0 | 6.0.0 | 4.3.0 | 1.1.1
311.8.0 | 3.6.3 | 4.0.0 | 4.1.0 | N/A
32
33To install from the command line:
34
35```
36phonegap plugin add phonegap-plugin-push
37```
38or
39
40```
41cordova plugin add phonegap-plugin-push
42```
43
44It is also possible to install via repo url directly ( unstable )
45
46```
47phonegap plugin add https://github.com/phonegap/phonegap-plugin-push
48```
49
50or
51
52```
53cordova plugin add https://github.com/phonegap/phonegap-plugin-push
54```
55
56As of version 2.0.0 the SENDER_ID parameter has been removed at install time. Instead you put your google-services.json (Android) and/or GoogleService-Info.plist in the root folder of your project and then add the following lines into your config.xml.
57
58In the platform tag for Android add the resource-file tag:
59
60```
61<platform name="android">
62 <resource-file src="google-services.json" target="google-services.json" />
63</platform>
64```
65
66In the platform tag for iOS add the resource-file tag:
67
68```
69<platform name="ios">
70 <resource-file src="GoogleService-Info.plist" />
71</platform>
72```
73
74> Note: if you are using Ionic you may need to specify the SENDER_ID variable in your package.json.
75
76```
77 "cordovaPlugins": [
78 {
79 "locator": "phonegap-plugin-push"
80 }
81 ]
82```
83
84> Note: You need to specify the SENDER_ID variable in your config.xml if you plan on installing/restoring plugins using the prepare method. The prepare method will skip installing the plugin otherwise.
85
86```
87<plugin name="phonegap-plugin-push" spec="2.0.0" />
88```
89
90## Android details
91
92### Compilation
93
94As of version 2.0.0 the plugin has been switched to using pinned version of Gradle libraries. You will need to ensure that you have installed the following items through the Android SDK Manager:
95
96- Android Support Library version 25.1.0
97- FirebaseMessaging Library version 9.8.0
98
99![android support library](https://cloud.githubusercontent.com/assets/353180/10230226/0627931e-684a-11e5-9a6b-72d72997f655.png)
100
101For more detailed instructions on how to install the Android Support Library visit [Google's documentation](https://developer.android.com/tools/support-library/setup.html).
102
103*Note:* if you are using an IDE to like Eclipse, Xamarin, etc. then the Android SDK installed by those tools may not be the same version as the one used by the Cordova/PhoneGap CLI while building. Please make sure your command line tooling is up to date with the software versions above. An easy way to make sure you up to date is to run the following command:
104
105```
106android update sdk --no-ui --filter "extra"
107```
108
109### Co-existing with Facebook Plugin
110
111There are a number of Cordova Facebook Plugins available but the one that we recommend is [Jeduan's fork](https://github.com/jeduan/cordova-plugin-facebook4) of the original Wizcorp plugin. It is setup to use Gradle/Maven and the latest Facebook SDK properly.
112
113To add to your app:
114
115```
116phonegap plugin add --save cordova-plugin-facebook4 --variable APP_ID="App ID" --variable APP_NAME="App Name"
117```
118or
119
120```
121cordova plugin add --save cordova-plugin-facebook4 --variable APP_ID="App ID" --variable APP_NAME="App Name"
122```
123
124### Co-existing with plugins that use Firebase
125
126Problems may arise when push plugin is used along plugins that implement Firebase functionality (cordova-plugin-firebase-analytics, for example). Firebase uses `@string/google_app_id`, as does the push plugin, though the value format differs, causing problems like this: `Invalid google_app_id. Firebase Analytics disabled`.
127
128To make the two work together, you need to migrate your GCM project from Google console to Firebase console:
129
1301) In Firebase console - [import your existing GCM project](https://firebase.google.com/support/guides/google-android#migrate_your_console_project), don't create a new one.
1312) Set your `SENDER_ID` variable to match the id of your imported Firebase project. In case of cordova, your `config.xml` would look something like this:
132```xml
133<plugin name="phonegap-plugin-push" spec="~1.10.0">
134 <variable name="SENDER_ID" value="1:956432534015:android:df201d13e7261425" />
135</plugin>
136```
1373) In your JavaScript, when you init the PushPlugin, senderID remains the same format as before:
138```javascript
139PushNotification.init({
140 android: {
141 senderID: 956432534015
142 }
143});
144```
145
146*Note:* No changes on the back-end side are needed: [even though recommended](https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints), it isn't yet required and sending messages through GCM gateway should work just fine.
147
148### Common errors
149
150#### minSdkVersion === 14
151
152If you have an issue compiling the app and you are getting an error similar to this:
153
154```
155* What went wrong:
156Execution failed for task ':processDebugManifest'.
157> Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version 15 declared in library .../platforms/android/build/intermediates/exploded-aar/com.facebook.android/facebook-android-sdk/4.6.0/AndroidManifest.xml
158 Suggestion: use tools:overrideLibrary="com.facebook" to force usage
159```
160
161Then you can add the following entry into your config.xml file in the android platform tag:
162
163```xml
164<platform name="android">
165 <preference name="android-minSdkVersion" value="15"/>
166 </platform>
167```
168
169or compile your project using the following command, if the solution above doesn't work for you. Basically add `-- --minSdkVersion=15` to the end of the command line (mind the extra `--`, it's needed):
170
171```bash
172cordova compile android -- --minSdkVersion=15
173cordova build android -- --minSdkVersion=15
174cordova run android -- --minSdkVersion=15
175cordova emulate android -- --minSdkVersion=15
176```
177
178#### Multidex
179
180If you have an issue compiling the app and you're getting an error similar to this (`com.android.dex.DexException: Multiple dex files define`):
181
182```
183UNEXPECTED TOP-LEVEL EXCEPTION:
184com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
185 at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
186 at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
187 at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
188 at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
189 at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
190 at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
191 at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
192 at com.android.dx.command.dexer.Main.run(Main.java:277)
193 at com.android.dx.command.dexer.Main.main(Main.java:245)
194 at com.android.dx.command.Main.main(Main.java:106)
195```
196
197Then at least one other plugin you have installed is using an outdated way to declare dependencies such as `android-support` or `play-services-gcm`.
198This causes gradle to fail, and you'll need to identify which plugin is causing it and request an update to the plugin author, so that it uses the proper way to declare dependencies for cordova.
199See [this for the reference on the cordova plugin specification](https://cordova.apache.org/docs/en/5.4.0/plugin_ref/spec.html#link-18), it'll be usefull to mention it when creating an issue or requesting that plugin to be updated.
200
201Common plugins to suffer from this outdated dependency management are plugins related to *facebook*, *google+*, *notifications*, *crosswalk* and *google maps*.
202
203#### More than one library with package name 'com.google.android.gms'
204
205When some other packages include `cordova-google-play-services` as a dependency, such as is the case with the cordova-admob and cordova-plugin-analytics plugins, it is impossible to also add the phonegap-plugin-push, for the following error will rise during the build process:
206
207```
208:processDebugResources FAILED
209FAILURE: Build failed with an exception.
210
211What went wrong: Execution failed for task ':processDebugResources'. > Error: more than one library with package name 'com.google.android.gms'
212```
213
214Those plugins should be using gradle to include the Google Play Services package but instead they include the play services jar directly or via a plugin dependency. So all of that is bad news. These plugins should be updated to use gradle. Please raise issues on those plugins as the change is not hard to make.
215
216In fact there is a PR open to do just that appfeel/analytics-google#11 for cordova-plugin-analytics. You should bug the team at appfeel to merge that PR.
217
218Alternatively, switch to another plugin that provides the same functionality but uses gradle:
219
220[https://github.com/danwilson/google-analytics-plugin](https://github.com/danwilson/google-analytics-plugin)
221[https://github.com/cmackay/google-analytics-plugin](https://github.com/cmackay/google-analytics-plugin)
222
223## Browser details
224
225### Browser quirks
226
227For the time being push support on the browser will only work using the PhoneGap push server.
228
229When you run `phonegap serve` to test browser push point your browser at `http://localhost:3000`. The browser push implementation uses the W3C Push Spec's implementation which relies on ServiceWorkers and ServiceWorkers can only be accessed via the `https` protocol or via `http://localhost`. Pointing your browser at `localhost` will be the easiest way to test.
230
231### Browser Support
232
233Chrome 49+
234Firefox 46+
235
236## iOS details
237
238### Xcode
239
240Xcode version 8.0 or greater is required for building this plugin.
241
242### Bitcode
243
244If you are running into a problem where the linker is complaining about bit code. For instance:
245
246```
247ld: '<file.o>' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
248```
249
250You have two options. The first is to [disable bitcode as per this StackOverflow answer](http://stackoverflow.com/a/32466484/41679) or [upgrade to cordova-ios 4 or greater](https://cordova.apache.org/announcements/2015/12/08/cordova-ios-4.0.0.html).
251
252```
253cordova platform update ios@4.0.0
254```
255
256### CocoaPods
257
258Required `cordova-cli` minimum version: `6.4.0`
259
260Required `cordova-ios` minimum version: `4.3.0`
261
262Required `CocoaPods` minimum version: `1.0.1`
263
264
265To install CocoaPods, please follow the installation instructions [here](https://guides.cocoapods.org/using/getting-started). After installing CocoaPods, please run:
266
267 pod setup
268
269This will clone the required CocoaPods specs-repo into your home folder at `~/.cocoapods/repos`, so it might take a while. See the [CocoaPod Disk Space](#cocoapod-disk-space) section below for more information.
270
271
272Version `2.0.0` (and above) of this plugin supports [CocoaPods](https://cocoapods.org) installation of the [Firebase Cloud Messaging](https://cocoapods.org/pods/FirebaseMessaging) library.
273
274If you are installing this plugin using `npm`, and you are using version `6.1.0` or greater of the `cordova-cli`, it will automatically download the right version of this plugin for both your platform and cli.
275
276If you are on a `cordova-cli` version less than `6.1.0`, you will either have to upgrade your `cordova-cli` version, or install the plugin explicitly:
277
278i.e.
279```
280cordova plugin add phonegap-plugin-push@1.8.1
281```
282
283If you are installing this plugin using a `local file reference` or a `git url`, you will have to specify the version of this plugin explicitly (see above) if you don't fulfill the `cordova-cli` and `cordova-ios` requirements.
284
285#### Common CocoaPod Installation issues
286
287If you are attempting to install this plugin and you run into this error:
288
289```
290Installing "phonegap-plugin-push" for ios
291Failed to install 'phonegap-plugin-push':Error: pod: Command failed with exit code 1
292 at ChildProcess.whenDone (/Users/smacdona/code/push151/platforms/ios/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
293 at emitTwo (events.js:87:13)
294 at ChildProcess.emit (events.js:172:7)
295 at maybeClose (internal/child_process.js:818:16)
296 at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
297Error: pod: Command failed with exit code 1
298```
299
300Please run the command `pod repo update` and re-install the plugin. You would only run `pod repo update` if you have the specs-repo already cloned on your machine through `pod setup`.
301
302##### CocoaPod Disk Space
303
304Running `pod setup` can take over 1 GB of disk space and that can take quite some time to download over a slow internet connection. If you are having issues with disk space/network try this neat hack from @VinceOPS.
305
306```
307git clone --verbose --depth=1 https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master
308pod setup --verbose
309```
310
311##### Library not found for -lPods-Appname
312
313If you open the app in Xcode and you get an error like:
314
315```
316ld: library not found for -lPods-Appname
317clang: error: linker command failed with exit code 1
318```
319
320Then you are opening the .xcodeproj file when you should be opening the .xcworkspace file.
321
322##### Library not found for -lGoogleToolboxForMac
323
324Trying to build for iOS using the latest cocoapods (1.2.1) but failed with the following error (from terminal running cordova build ios):
325
326```
327ld: library not found for -lGoogleToolboxForMac
328```
329
330Workarounds are to add the platform first and install the plugins later, or to manually run pod install on projectName/platforms/ios.
331
332## Additional Resources
333
334The push plugin enables you to play sounds and display different icons during push (Android only). These additional resources need to be added to your projects `platforms` directory in order for them to be included into your final application binary.
335
336You can now use the `resource-file` tag to deliver the image and sound files to your application. For example if you wanted to include an extra image file for only your Android build you would add the `resource-file` tag to your android `platform` tag:
337
338```
339<platform name="android">
340 <resource-file src="myImage.png" target="res/drawable/myImage.png" />
341</platform>
342```
343
344or if you wanted to include a sound file for iOS:
345
346
347```
348<platform name="ios">
349 <resource-file src="mySound.caf" />
350</platform>
351```