Ionic Capacitor 3 with @capacitor-community/background-geolocation fails to run in android

I have upgraded to Latest version of ionic 6.16.1 and created a new project with Capacitor 3.

I just added the plugin @capacitor-community/background-geolocation and the sample code in their npm page

When i try to build the Android Application i am getting the following error

[capacitor] FAILURE: Build failed with an exception.
[capacitor] * Where:
[capacitor] Build file ‘E:\Projects\ionic\background_location\node_modules@capacitor-community\background-geolocation\android\build.gradle’ line: 54
[capacitor] * What went wrong:
[capacitor] A problem occurred evaluating project ‘:capacitor-community-background-geolocation’.
[capacitor] > Could not get unknown property ‘androidxLocalbroadcastmanagerVersion’ for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
[capacitor] * Try:
[capacitor] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[capacitor] * Get more help at
[capacitor] Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
[capacitor] Use ‘–warning-mode all’ to show the individual deprecation warnings.
[capacitor] See Command-Line Interface
[capacitor] BUILD FAILED in 11m 12s

Can anyone provide some solution for this?

1 Like

This can be fixed by adding these two lines in variales.gradle file & sync now

androidxAppCompatVersion = ‘1.2.0’

But Still my background geolocation is not working, it’s adding watcher & removing it


Thanks for your reply.

For me it got compiled after adding the following lines in variables.gradle

androidxLocalbroadcastmanagerVersion = ‘1.0.0’
playServicesLocationVersion = ‘17.0.0’

androidxAppCompatVersion = ‘1.2.0’ was already there in the generated vairables.gradle file.

But the App automatically closes when opened. When opening the second time it crashes with following error

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(
at com.getcapacitor.-$$Lambda$Bridge$ Source:8)
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.getcapacitor.PluginHandle.invoke(
at com.getcapacitor.Bridge.lambda$callPluginMethod$0$Bridge(
… 5 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void com.equimaps.capacitor_background_geolocation.BackgroundGeolocationService$LocalBinder.removeWatcher(java.lang.String)’ on a null object reference
at com.equimaps.capacitor_background_geolocation.BackgroundGeolocation.removeWatcher(
… 8 more

I suspect that it might be due to Android Studio JDK getting updated from JDK 8 to JDK 11 recently and the changes corresponding to that is not yet handled in the plugin…

Any guidance on this would be very much helpful.


@spbhaskar Just a random guess, but if you update JDK to version 15, does it work? You can download it from here.

I can confirm the plugin works for me with JDK version 15, after adding

androidxLocalbroadcastmanagerVersion = '1.0.0'
playServicesLocationVersion = '17.0.0'

…to variables.gradle.

@priyansh360 Is it possible that you are using the demo code which adds and instantly removes the watcher?

    function callback(location, error) {
).then(function after_the_watcher_has_been_added(watcher_id) {
    // When a watcher is no longer needed, it should be removed by calling
    // 'removeWatcher' with an object containing its ID.
    BackgroundGeolocation.removeWatcher({      👈 WATCHER IS REMOVED HERE
                                                   RIGHT AFTER IT WAS ADDED. MAYBE
                                                   COMMENT OUT THIS?
        id: watcher_id
1 Like