Reputation: 1912
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?
Upvotes: 3
Views: 3464
Reputation: 11
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>
Upvotes: 0
Reputation: 351
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!
Upvotes: 12