Cordova-plugin-background-geolocation: Plugin crashes the App in Android platform

Created on 18 Feb 2017  路  15Comments  路  Source: mauron85/cordova-plugin-background-geolocation

Your Environment

  • Plugin version: 2.2.5
  • Platform: Android
  • OS version: Android 6
  • Device manufacturer and model: Asus Selfie
  • Cordova version (cordova -v): 6.4.0
  • Cordova platform version (cordova platform ls): android 6.0.0
  • Plugin configuration options:

{
desiredAccuracy: 100,
stationaryRadius: 100,
distanceFilter: 100,
maxLocations: 1000,
stopOnTerminate: false,
// Android only section
locationProvider: backgroundGeolocation.provider.ANDROID_ACTIVITY_PROVIDER,
interval: 60000,
fastestInterval: 5000,
activitiesInterval: 10000,
notificationTitle: "Nearby promotions notifications active.",
notificationText: "We will notify you of nearby promotions.",
notificationIconColor: "#002661",
notificationIconSmall: "icon_small",
notificationIconLarge: "icon_large",
// iOS only
pauseLocationUpdates: false
}

Context

I have build an app which was working as expected with your plugin but after update in Android studio it crashes the app.
When I install the app with this plugin it always says "Unfortunately [App name] has stopped".
Without your plugin the app runs as expected.
Please help.

This is what I have in Android SDK Manager

screen shot 2017-02-18 at 1 45 26 pm

Steps to Reproduce


  1. Build app with your plugin
  2. Configure your plugin and call the function backgroundGeolocation.start();
  3. It will crash the app with message "Unfortunately [App name] has stopped"

Debug logs


This is the logcat output.
App ID is com.sirkle.app
logcat.txt

waiting for input

Most helpful comment

I resolved with an update of the "phonegap-plugin-push", because "phonegap-plugin-push" updated from "com.google.android.gms:play-services-gcm:9.8+" to "com.google.android.gms:play-services-gcm:10.2+" and resolved

All 15 comments

I use phonegap so that I have only one codebase for both iOS and Android.
My workaround is to use cordova cli-6.3.0 and plugin version 2.2.4
I also aim at Android version 4

Thanks for reply @klaus-donnert, I tried plugin version 2.2.4 this morning but still not working :(

hey @yadutechnologies,

are you sure that the problem is linked to this plugin?

according to this stacktrace it is not:
02-18 13:58:59.587 4170 4352 V PushPlugin: execute: senderID=662927652806
02-18 13:58:59.613 4170 4352 E AndroidRuntime: FATAL EXCEPTION: pool-1-thread-2
02-18 13:58:59.613 4170 4352 E AndroidRuntime: Process: com.sirkle.app, PID: 4170
02-18 13:58:59.613 4170 4352 E AndroidRuntime: Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
02-18 13:58:59.613 4170 4352 E AndroidRuntime: java.lang.NoSuchMethodError: No static method getNoBackupFilesDir(Landroid/content/Context;)Ljava/io/File; in class Lcom/google/android/gms/common/util/zzw; or its super classes (declaration of 'com.google.android.gms.common.util.zzw' appears in /data/app/com.sirkle.app-2/base.apk)
02-18 13:59:16.288 4485 4551 E AndroidRuntime: at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
02-18 13:59:16.288 4485 4551 E AndroidRuntime: at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
02-18 13:59:16.288 4485 4551 E AndroidRuntime: at com.adobe.phonegap.push.PushPlugin$1.run(PushPlugin.java:74)
(same stack at 02-18 13:59:16.288 ).

Post just the exact exception stack please. That would ease the debugging.

AndroidRuntime: java.lang.NoSuchMethodError: No static method getNoBackupFilesDir(Landroid/content/Context;)Ljava/io/File; in class Lcom/google/android/gms/common/util/zzw

I agree with @gustavo-iniguez-goya. It doesn't seems that is caused by this plugin directly.
I've seen this kind of errors, when you have multiple cordova plugins using different versions of native libraries (like google play ...).

@yadutechnologies Please post full list of cordova plugins you're using.

sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add [email protected] --save;
sudo ionic plugin add cordova.plugins.[email protected] --save;
sudo ionic plugin add [email protected] --save --variable SENDER_ID=xxxxxx;
sudo ionic plugin add uk.co.workingedge.phonegap.plugin.[email protected] --save;
sudo ionic plugin add [email protected] --save;

removed from project, after removing it build it successfully.

sudo ionic plugin add [email protected] --save;

Above is the list of plugins with there version used in the app.

First small advice (playing smart ass I know :-)). Try to avoid installing plugins with sudo, it's not good idea (but maybe you have good reason).

Back to your problem. The list of plugins is quite long. I would suspect collision between plugins that are using google play services. Cannot be 100% sure, which are using google play, but I would suspect:
cordova-plugin-device-motion
cordova-plugin-geolocation
phonegap-plugin-push

Try to remove those and add cordova-plugin-mauron85-background-geolocation. Check if your project compiles.

The stacktrace of the error is practically the same than this one:
https://stackoverflow.com/a/41140199

Besides what mauron85 has said, check that answer (and the accepted one) and see if it helps you. Good luck :)

I resolved with an update of the "phonegap-plugin-push", because "phonegap-plugin-push" updated from "com.google.android.gms:play-services-gcm:9.8+" to "com.google.android.gms:play-services-gcm:10.2+" and resolved

Bah just figured the above out as well: https://github.com/phonegap/phonegap-plugin-push/issues/1588

I was having issues with this for the past week!

@abner-serafim I have changed the build.gradle file as you suggested but while building the app the build.gradle file reverted back to its original state.
before build
screen shot 2017-03-31 at 11 47 25 am

After changing build.gradle
screen shot 2017-03-31 at 11 49 41 am

After build
screen shot 2017-03-31 at 11 50 34 am

I have this code in config.xml file after adding the plugin, do I need to change anything over here.
screen shot 2017-03-31 at 11 57 30 am

Edit platforms/android/project.properties and change "com.google.android.gms:play-services-gcm:9.8+" to "com.google.android.gms:play-services-gcm:10.2+"

@stephenandrews Thank the solution worked for me 馃憤

Was this page helpful?
0 / 5 - 0 ratings