Cannot build Ionic App on Android once installed BackgroundGeolocation Plugin with Capacitor
Asked Answered
M

2

3

I'm trying to migrate my app from Cordova to Capacitor, but I still need to use functionalities like Background Geolocation. For that, I'm using this plugin: https://ionicframework.com/docs/native/background-geolocation

So, to test this, I created a fresh app, added Capacitor and installed this plugin. As mentioned here (https://github.com/ionic-team/capacitor/issues/2529#issuecomment-603205348), I added this lines to my strings file:

<string name="mauron85_bgloc_account_name">@string/app_name</string>
<string name="mauron85_bgloc_account_type">$PACKAGE_NAME.account</string>
<string name="mauron85_bgloc_content_authority">$PACKAGE_NAME</string>

After that, I ran npx cap sync

Now, whenever I'm trying to build my application, I get the following error: Execution failed for task ':capacitor-cordova-android-plugins:compileDebugJavaWithJavac'.

In my console, above that, there are a lot of missing import errors, like this:

C:\Users\zxy\Desktop\mobile_apps\testApp\android\capacitor-cordova-android-plugins\src\main\java\com\evgenii\jsevaluator\JsEvaluator.java:4: error: package android.support.annotation does not exist
import android.support.annotation.VisibleForTesting;
> C:\Users\zxy\Desktop\mobile_apps\testApp\android\capacitor-cordova-android-plugins\src\main\java\com\marianhello\bgloc\BackgroundGeolocationFacade.java:17: error: package android.support.v4.content does not exist
> import android.support.v4.content.ContextCompat;
>                                  ^
> C:\Users\zxy\Desktop\mobile_apps\testApp\android\capacitor-cordova-android-plugins\src\main\java\com\marianhello\bgloc\BackgroundGeolocationFacade.java:18: error: package android.support.v4.content does not exist
> import android.support.v4.content.LocalBroadcastManager;

Any idea how I can make this plugin to work with Capacitor?

Markup answered 30/4, 2020 at 9:32 Comment(0)
P
12

I have gotten it to build eventually.

The following error (and related errors) error: package android.support.annotation does not exist was fixed by running $ npx jetifier from project root.

Source: https://github.com/ionic-team/capacitor/issues/1937

It is also suggested to incorporated that in a postinstall hook. Hope this helps somewhat!

Prune answered 30/4, 2020 at 9:47 Comment(0)
O
0

The plugin relies on 3 strings that are automatically added for Cordova, but not for Capacitor.

Just add this to your strings.xml file:

Path: android\app\src\main\res\values\strings.xml

    <string name="mauron85_bgloc_account_name">@string/app_name</string>
    <string name="mauron85_bgloc_account_type">$PACKAGE_NAME.account</string>
    <string name="mauron85_bgloc_content_authority">$PACKAGE_NAME</string>
Obrien answered 28/9, 2023 at 7:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.