mauron85/cordova-plugin-background-geolocation

Unable to generate signed apk

Closed this issue · 17 comments

Your Environment

  • Plugin version: 3.1.0
  • Platform: Android
  • OS version:
  • Device manufacturer and model:
  • Running in Simulator:
  • Cordova version (cordova -v): --- Capacitor with navite plugin
  • Cordova platform version (cordova platform ls): ---
  • Plugin configuration options:
  • Link to your project:

Context

Trying generating signed apk in android studio.

Expected Behavior

Actual Behavior

Gets error:

  • Type org.apache.commons.io.Charsets is defined multiple times
  • com.android.tools.r8.CompilationFailedException: Compilation failed to complete

Possible Fix

Steps to Reproduce

Plugins:
@mauron85/cordova-plugin-background-geolocation (3.1.0)
cordova-plugin-actionsheet (2.3.3)
cordova-plugin-badge (0.8.8)
cordova-plugin-device (2.0.3)
cordova-plugin-dialogs (2.0.2)
cordova-plugin-ionic (5.4.7)
cordova-plugin-whitelist (1.3.4)
cordova-sms-plugin (1.0.0)
uk.co.workingedge.phonegap.plugin.launchnavigator (5.0.4)

Context

Problem appears only on signed apk

Debug logs

I'm able to sign my app, but I'm not using all your plug-ins.
Here's my app package.json file:
https://github.com/IsraelHikingMap/Site/blob/4ed26c9817f1deab55a7a6e80e7e9d4ba006ddb7/IsraelHiking.Web/package.json#L52
Might be a plugin collision, I don't know...

I got the error from:
"cordova-plugin-ionic": "5.4.7",
"cordova-plugin-whitelist": "^1.3.4"

they're added by initializing ionic appflow service

Schermata 2020-07-07 alle 10 58 42

Resolved by editing dependencies and plugin.xml

I've created fork to solve this problem
https://github.com/darron1217/cordova-plugin-background-geolocation/tree/bugfix

You can install it by npm install https://github.com/darron1217/cordova-plugin-background-geolocation.git#bugfix

Awesome work @darron1217 that saved the day!

I had the same issue while trying to sign the app. It was working without signing.
Can we get this merged @mauron85? 🙏

In appflow now I have progress, and getting the same thing mentioned here #562 (comment)

@vuk-nikolic I'm having the same issue too. There is a workaround suggested here but I haven't tried it #728 and it seems a bit hacky. Seems like a Capacitor bug, as I have the strings.xml file in the right place, but somehow those values aren't being seen when packaging this plugin.

@vuk-nikolic could you elaborate a bit more please, I am facing the same issue and got stuck on the

AAPT: error: resource string/mauron85_bgloc_content_authority (aka capacitor.android.plugins:string/mauron85_bgloc_content_authority) not found.

@vuk-nikolic could you elaborate a bit more please, I am facing the same issue and got stuck on the

AAPT: error: resource string/mauron85_bgloc_content_authority (aka capacitor.android.plugins:string/mauron85_bgloc_content_authority) not found.

@LgArcida this is how you fix it

sorry @LgArcida, unfortunately we're no longer using this plugin.

@vuk-nikolic Also, if you're using Capacitor, the app will still die after 5 minutes of being in the background because Capacitor turns off timers when going into the background. Not a problem on iOS though. Just saw you're not using it anymore, what plugin did you switch to?

I've created fork to solve this problem https://github.com/darron1217/cordova-plugin-background-geolocation/tree/bugfix

You can install it by npm install https://github.com/darron1217/cordova-plugin-background-geolocation.git#bugfix

Hi Darron, I installed your repo and even forked my own and did the same modification. However, in Appflow build it says it can't find the gitmodule files. I reckon it's because the gitmodules didn't get installed. Did you encounter this problem?

This plugin is practically dead. We are maintaining a fork under here if anyone is interested:
https://github.com/HaylLtd/cordova-background-geolocation-plugin

This plugin is practically dead. We are maintaining a fork under here if anyone is interested: https://github.com/HaylLtd/cordova-background-geolocation-plugin

Thanks for the info and maintaining the plugin.

Does your repo support Capacitor? As ionic's official plugin is based on mauron85's plugin with their awesome-cordova-plugin as an interface, I'm afraid Capacitor won't be able to run with your plugin.

I'm still not using capacitor, so I don't know.
But if you send a PR to help fixing what's missing I'll be happy to review it :-)

@HarelM I don't think its something to be done with your repo. I just submitted a request to ionic's repo asking them to move onto your repo.

==============================
My workaround

After years not being able to build thru Appflow I took 2 weeks updated my App to Capacitor. Spent more than a week digging why Appflow still couldn't build with Capacitor. I tried capacitor background geolocation plugin, but it uses Google APIs but my devices do not have Google APIs. I tried migrating mauron85's functions into capacitor plugin but the result was not good enough. So if you are facing the same situation, do what I write below.

For others using capacitor that got errors from Appflow:

  1. android/capacitor-cordova-android-plugins/src/main/res/xml/authenticator.xml:7: AAPT: error: resource mipmap/ic_launcher (aka capacitor.android.plugins:mipmap/ic_launcher) not found.
  2. android/capacitor-cordova-android-plugins/src/main/AndroidManifest.xml:20:1-199: AAPT: error: resource string/mauron85_bgloc_content_authority (aka capacitor.android.plugins:string/mauron85_bgloc_content_authority) not found.
  3. Error: ENOENT: no such file or directory, stat '/builds/[xxx/xxx]/node_modules/@mauron85/cordova-plugin-background-geolocation/android/common/src/main/java/com/marianhello/bgloc/BackgroundGeolocationFacade.java'

I have got an workaround at my repo:https://github.com/txlife/cordova-plugin-background-geolocation
Fork your own repo or simply use mine.

What I have done is:

  1. Copied android/common submodule's files into the repo as local files. Since no one is maintaining the original repo so it does not make any difference. This solves error 3. I don't know why Appflow did not pull the submodule.
  2. Modified plugin.xml, added
<resource-file src="android/common/src/main/res/values/strings.xml" target="res/values/strings.xml" />

3.Updated strings.xml with:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="mauron85_bgloc_account_name">$ACCOUNT_NAME</string>
  <string name="mauron85_bgloc_account_type">$ACCOUNT_TYPE</string>
  <string name="mauron85_bgloc_content_authority">$CONTENT_AUTHORITY</string>
  <string name="mauron85_bgloc_account_label">$ACCOUNT_LABEL</string>
  <string name="mauron85_bgloc_icon">$ICON</string>
  <string name="mauron85_bgloc_small_icon">$SMALL_ICON</string>
</resources>

4.Updated authenticator.xml with:

<?xml version="1.0" encoding="utf-8"?>
<account-authenticator
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="@string/mauron85_bgloc_account_type"
    android:icon="@string/mauron85_bgloc_icon"
    android:smallIcon="@string/mauron85_bgloc_small_icon"
    android:label="@string/mauron85_bgloc_account_label"/>

Now the appflow should be able to build.

The method mentioned here might also work, it seems working to me but didn't try thru appflow. It basically does the same thing.

In my repo, I also used @darron1217 's modifications to resolve the issues of this original post. I didn't fork darron's repo was because I thought his repo was causing issues but actually it was not the case.

==================
Cordova Users

For cordova users you might want to try #707 (comment)

==================
PS

Donate to active maintainers if possible. The work has been done by original author is huge and I gotta say this is probably the most comprehensive background geolocation plugin for hybrid apps so far. This repo's abandonment has resulted us spending thousands of dollars extra to maintain our app.