question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Can't resolve 'cordova/exec' when using Cordova plugin

See original GitHub issue

I am trying to use cordova-plugin-mauron85-background-geolocation so I can collect geolocation data while the app is in the background (see #516).

However following these instructions ends up giving me a build error: Error: Can't resolve 'cordova/exec'. I believe this is the offending line, however running npm install cordova does not fix the issue.

Is there something really obvious I’m missing?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
diachedeliccommented, Dec 4, 2018

For anyone else wanting to use the cordova-plugin-mauron85-background-geolocation plugin, this is what I ended up doing to get it working on Android:

  1. npm install cordova-plugin-mauron85-background-geolocation
  2. npm install cordova-android-play-services-gradle-release (optional, fixes compatibility with Capacitor’s PushNotification plugin)
  3. npx cap copy
  4. Add suitable values to android/app/src/main/res/values/strings.xml:
    <string name="mauron85_bgloc_content_authority">com.bundle.id</string>
    <string name="mauron85_bgloc_account_type">com.bundle.id.account</string>
    <string name="mauron85_bgloc_account_name">My App</string>
  1. Use in script like so:
    const { BackgroundGeolocation } = window

    BackgroundGeolocation.on('location', function(location) {
      // {
      //   accuracy: 21
      //   altitude: 15
      //   bearing: 0
      //   id: 3
      //   isFromMockProvider: false
      //   latitude: -33.95674337167293
      //   locationProvider: 0
      //   longitude: 150.98079233430326
      //   mockLocationsEnabled: false
      //   provider: "gps"
      //   speed: 0.14999999105930328
      //   time: 1543912755527
      // }

      const {
        latitude,
        longitude,
        altitude,
        accuracy,
      } = location

      this.accuracy = accuracy

      this.path.features[0].geometry.coordinates.push([
        longitude,
        latitude,
        altitude,
      ])
    })

    
    BackgroundGeolocation.start()
1reaction
seanfishercommented, Sep 5, 2019

This worked for me, based on this snippet from @mauron85:

import { BackgroundGeolocationPlugin }  from '@mauron85/cordova-plugin-background-geolocation';
declare const BackgroundGeolocation: BackgroundGeolocationPlugin;

// ... Usage
BackgroundGeolocation.configure({...});
Read more comments on GitHub >

github_iconTop Results From Across the Web

`cordova.exec` not working in capacitor project - Stack Overflow
The problem is in the cordova plugin not being executed: cordova.exec(successCallback, errorCallback, 'MsalPlugin', 'msalInit', [JSON.stringify( ...
Read more >
Using Cordova Plugins and Ionic Native - Capacitor
Using Cordova Plugins and Ionic Native. When developing an app that uses Capacitor, it's possible to use both Cordova and Ionic Native plugins....
Read more >
Android Plugin Development Guide - Apache Cordova
Android Plugin Development Guide. This section provides details for how to implement native plugin code on the Android platform.
Read more >
Can't import Cordova Zip plugin - ionic-v3
To fix this I just removed all entries related to this plugin from the package. json file and then installed everything again.
Read more >
cordova-js - npm
js process is a Node.js script that concatenates all of the core Cordova plugins in this repository into a cordova.<platform>.js file under the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found