capacitor-community / background-geolocation

A Capacitor plugin that sends you geolocation updates, even while the app is in the background.
MIT License
185 stars 57 forks source link

Error: package com.equimaps.capacitor_background_geolocation does not exist #9

Closed danielrf121 closed 3 years ago

danielrf121 commented 3 years ago

I installed the plugin, run CAP SYNC, but when importing it into MainActivity he doesn't find the plugin.

Captura de Tela 2021-03-05 às 13 12 07

diachedelic commented 3 years ago

I would expect "capacitor-community-background-geolocation" to appear in the project pane. I wonder why it doesn't?

diachedelic commented 3 years ago

Perhaps try running File -> "Sync Project with Gradle settings"?

jaanreinok commented 3 years ago

For me Android studio redlined dependency but after gradle install build ran successfuly but the red lines still remained until next restart. Everything worked like expected. Good readme.

danielrf121 commented 3 years ago

Removing everything and installing again, when trying to synchronize with "Sync Project with Gradle Files" I got the following image error. Note that the plugin is not showing up there with the others in the project directories. In the other image it is possible to see that the capacitor finds the plugin at the time of the build, plays for "capacitor.build.gradle" but it is as if it were not on the project's premises.

OBS: For iOS works fine!

capacitor.build.gradle

apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
    implementation project(':capacitor-community-background-geolocation')
    implementation project(':rdlabo-capacitor-facebook-login')
    implementation project(':capacitor-apple-login')
    implementation project(':capacitor-firebase-analytics')
    implementation "com.android.support:support-v4:24.1.1+"
    implementation "com.onesignal:OneSignal:3.15.6"
    implementation "com.squareup.okhttp3:okhttp:3.12.0"
}
apply from: "../../node_modules/cordova-plugin-badge/src/android/badge.gradle"
apply from: "../../node_modules/onesignal-cordova-plugin/build-extras-onesignal.gradle"

if (hasProperty('postBuildExtras')) {
  postBuildExtras()
}

capacitor.settings.gradle

include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

include ':capacitor-community-background-geolocation'
project(':capacitor-community-background-geolocation').projectDir = new File('../node_modules/@capacitor-community/background-geolocation/android')

include ':rdlabo-capacitor-facebook-login'
project(':rdlabo-capacitor-facebook-login').projectDir = new File('../node_modules/@rdlabo/capacitor-facebook-login/android/@rdlabo/capacitor-facebook-login')

include ':capacitor-apple-login'
project(':capacitor-apple-login').projectDir = new File('../node_modules/capacitor-apple-login/android')

include ':capacitor-firebase-analytics'
project(':capacitor-firebase-analytics').projectDir = new File('../node_modules/capacitor-firebase-analytics/android/capacitor-firebase-analytics')

Captura de Tela 2021-03-08 às 11 37 21

diachedelic commented 3 years ago

I have no idea what is causing this, please let me know if you find a solution.

EpicVidak commented 3 years ago

Have you added service into AndroidManifest.xml?

ex.

<application
    android:usesCleartextTraffic="true"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <service
        android:name="com.equimaps.capacitor_background_geolocation.BackgroundGeolocationService"
        android:enabled="true"
        android:exported="true"
        android:foregroundServiceType="location" />

</application>
diachedelic commented 3 years ago

This looks like an issue with Android Studio to me.

msacchetti commented 3 years ago

Perhaps try running File -> "Sync Project with Gradle settings"?

This worked for me!

jongbonga commented 3 years ago

Removing everything and installing again, when trying to synchronize with "Sync Project with Gradle Files" I got the following image error. Note that the plugin is not showing up there with the others in the project directories. In the other image it is possible to see that the capacitor finds the plugin at the time of the build, plays for "capacitor.build.gradle" but it is as if it were not on the project's premises.

OBS: For iOS works fine!

capacitor.build.gradle

apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
    implementation project(':capacitor-community-background-geolocation')
    implementation project(':rdlabo-capacitor-facebook-login')
    implementation project(':capacitor-apple-login')
    implementation project(':capacitor-firebase-analytics')
    implementation "com.android.support:support-v4:24.1.1+"
    implementation "com.onesignal:OneSignal:3.15.6"
    implementation "com.squareup.okhttp3:okhttp:3.12.0"
}
apply from: "../../node_modules/cordova-plugin-badge/src/android/badge.gradle"
apply from: "../../node_modules/onesignal-cordova-plugin/build-extras-onesignal.gradle"

if (hasProperty('postBuildExtras')) {
  postBuildExtras()
}

capacitor.settings.gradle

include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

include ':capacitor-community-background-geolocation'
project(':capacitor-community-background-geolocation').projectDir = new File('../node_modules/@capacitor-community/background-geolocation/android')

include ':rdlabo-capacitor-facebook-login'
project(':rdlabo-capacitor-facebook-login').projectDir = new File('../node_modules/@rdlabo/capacitor-facebook-login/android/@rdlabo/capacitor-facebook-login')

include ':capacitor-apple-login'
project(':capacitor-apple-login').projectDir = new File('../node_modules/capacitor-apple-login/android')

include ':capacitor-firebase-analytics'
project(':capacitor-firebase-analytics').projectDir = new File('../node_modules/capacitor-firebase-analytics/android/capacitor-firebase-analytics')

Captura de Tela 2021-03-08 às 11 37 21

I'm getting the exact same issue on version 1.0.2 for capacitor 3

Here is the error log

No variants found for ':capacitor-community-background-geolocation'. Check build files to ensure at least one variant exists. at: com.android.tools.idea.gradle.project.sync.idea.svs.AndroidModule.deliverModels(AndroidModule.kt:191) com.android.tools.idea.gradle.project.sync.idea.svs.AndroidExtraModelProvider$Worker.populateBuildModels(AndroidExtraModelProvider.kt:121)

wwwizzarrdry commented 2 years ago

SOLUTION

I nearly gave up on this. but eventually found that my plugins weren't being implemented properly with the capacitor cli. The fix finally came when I manually registered the plugin in /src-capacitor/android/app/src/main/java/MainActivity.java:

package org.capacitor.quasar.app;

import android.os.Bundle;

import com.getcapacitor.BridgeActivity;
import com.getcapacitor.Plugin;

import java.util.ArrayList;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      registerPlugin(com.capacitorjs.plugins.geolocation.GeolocationPlugin.class);
      registerPlugin(com.equimaps.capacitor_background_geolocation.BackgroundGeolocation.class);
    }});
  }
}

I found the classpath's for the plugin inside /src-capacitor/android/app/src/main/assets/capacitor.plugins.json

[
    {
        "pkg": "@capacitor-community/background-geolocation",
        "classpath": "com.equimaps.capacitor_background_geolocation.BackgroundGeolocation"
    },
    {
        "pkg": "@capacitor/geolocation",
        "classpath": "com.capacitorjs.plugins.geolocation.GeolocationPlugin"
    }
]

Obviously, you need to register the plugin inside your Index.vue file:

import { registerPlugin } from "@capacitor/core";
const Geolocation = registerPlugin("Geolocation");
const BackgroundGeolocation = registerPlugin("BackgroundGeolocation");

Details

$ npx cap doctor

Capacitor Doctor

Latest Dependencies:

  @capacitor/cli: 3.5.1
  @capacitor/core: 3.5.1
  @capacitor/android: 3.5.1
  @capacitor/ios: 3.5.1

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 3.5.1
  @capacitor/core: 3.5.1
  @capacitor/android: 3.5.1

[success] Android looking great!

$ quasar info

Operating System - Windows_NT(10.0.22000) - win32/x64
NodeJs - 14.15.1

Global packages
  NPM - 6.14.8
  yarn - 1.22.15
  @quasar/cli - 1.3.2
  @quasar/icongenie - 2.5.1
  cordova - 11.0.0

Important local packages
  quasar - 1.18.10 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app - 2.3.0 -- Quasar Framework local CLI
  @quasar/extras - 1.13.6 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 2.6.14 -- Reactive, component-oriented view layer for modern web interfaces.
  vue-router - 3.5.3 -- Official router for Vue.js 2
  vuex - 3.6.2 -- state management for Vue.js
  electron - Not installed
  electron-packager - Not installed
  electron-builder - Not installed
  @babel/core - 7.17.10 -- Babel compiler core.
  webpack - 4.44.2 -- Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
  webpack-dev-server - 3.11.3 -- Serves a webpack app. Updates the browser on changes.
  workbox-webpack-plugin - Not installed
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  typescript - 4.2.2 -- TypeScript is a language for application scale JavaScript development
  @capacitor/core - 3.5.1 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/cli - 3.5.1 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/android - 3.5.1 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/ios - Not installed

Hope this helps someone down the road. These final steps really need to be added to the Readme.md...