mapsplugin / cordova-plugin-googlemaps

Google Maps plugin for Cordova
Apache License 2.0
1.66k stars 918 forks source link

Conflict with cordova-plugin-geolocation #2844

Open ggiordan opened 3 years ago

ggiordan commented 3 years ago

I'm submitting a ... (check one with "x")

OS: (check one with "x")

cordova information: (run $> cordova plugin list)

C:\Users\jeff.giordano\Documents\RoverMobile>cordova plugin list
cordova-plugin-appavailability 0.4.2 "AppAvailability"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-geolocation 4.1.0 "Geolocation"
cordova-plugin-globalization 1.11.0 "Globalization"
cordova-plugin-googlemaps 2.7.1 "cordova-plugin-googlemaps"
cordova-plugin-inappbrowser 4.1.0 "InAppBrowser"
cordova-plugin-insomnia 4.3.0 "Insomnia (prevent screen sleep)"
cordova-plugin-ios-non-exempt-encryption 1.0.0 "ITSAppUsesNonExemptEncryption false"
cordova-plugin-media 5.0.3 "Media"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-sim 1.3.3 "SIM"
cordova-plugin-splashscreen 6.0.0 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova-plugin-wkwebview-file-xhr 3.0.0 "Cordova WKWebView File XHR Plugin"
cordova-support-google-services 1.3.2 "cordova-support-google-services"

Current behavior: Build fails with the following error:

> Task :app:processDebugManifest FAILED
C:\Users\jeff.giordano\Documents\RoverMobile\platforms\android\app\src\main\AndroidManifest.xml:23:5-66 Error:
        Element uses-feature#android.hardware.location.gps at AndroidManifest.xml:23:5-66 duplicated with element declared at AndroidManifest.xml:19:5-90
C:\Users\jeff.giordano\Documents\RoverMobile\platforms\android\app\src\main\AndroidManifest.xml Error:
        Validation failed, exiting

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed with multiple errors, see logs

Expected behavior: Clean build

Solution: Not using the geolocation plugin does not work for me. My app needs the ability to watch user's the location.

The solution is straight forward, the issue is that the merge process needs the lines for to match.

To resolve I did the following to plugin.xml: 1) line 130 add: <preference name="GPS_REQUIRED" default="true"/> 2) line 253 change <uses-feature android:name="android.hardware.location.gps" /> to be <uses-feature android:name="android.hardware.location.gps" android:required="$GPS_REQUIRED"/>

This way, the 2 plugins will move in sync with each other on the requirement for GPS. Another option would be to simply add the android:required="true" to line 253. I think the former solution is a bit better, as the GPS is only required if the user wants to use getlocation and show the map dot (granted that's most folks, but true is the default anyway).

Support this plugin activity

I appreicate if you give me a beer :beer: from here

mcastets commented 3 years ago

Hi,

I met the same issue and I've found a workaround that doesn't need to update the plugin files (which was not a solution for us as we build our app from scratch in a cloud environment).

Take a look: https://stackoverflow.com/a/64995384/2118909

Obviously, it would be better if we could get rid of this workaround and could be fixed in a new bug-fix release.

SimonBrazell commented 3 years ago

@mcastets I added the following to my config.xml file as described in your SO post:

<platform name="android">
    <!-- ... -->
    <edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.location.gps']">
        <uses-feature android:name="android.hardware.location.gps" />
    </edit-config>
</platform>

But I get the following error when attempting to build the project:

The prefix "android" for attribute "android:name" associated with an element type "uses-feature" is not bound.

I wonder if there are any other steps you may have left off of your workaround?

Environment:

Ionic:

   Ionic CLI                     : 6.12.2 (.../.nvm/versions/node/v12.19.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.1
   @angular-devkit/build-angular : 0.1100.2
   @angular-devkit/schematics    : 11.0.2
   @angular/cli                  : 11.0.2
   @ionic/angular-toolkit        : 3.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 12 other plugins)

Utility:

   cordova-res                          : 0.15.2
   native-run (update available: 1.3.0) : 1.2.2

System:

   Android SDK Tools : 26.1.1 (.../Library/Android/sdk/)
   NodeJS            : v12.19.0 (.../.nvm/versions/node/v12.19.0/bin/node)
   npm               : 6.14.8
   OS                : macOS Catalina
   Xcode             : Xcode 12.2 Build version 12B45b
mcastets commented 3 years ago

@SimonBrazell I didn't encounter your issue.

Have you considered reinstalling the android platform? No related warning during cordova prepare?

Could you copy and paste your generated AndroidManifest.xml (located in platforms/android/app/src folder) without the config.xml workaround? (or at least your <uses-feature /> tags).

Could you then confirm that you have the following lines (the xmlns:android namespace on the manifest tag seems important):

<?xml version='1.0' encoding='utf-8'?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- other tags here -->
    <uses-feature android:name="android.hardware.location.gps" android:required="true" />
    <uses-feature android:name="android.hardware.location" />
    <uses-feature android:name="android.hardware.location.gps" />
</manifest>

If you don't have the xmlns:android namespace, you might want to add it to your config.xml (as an attribute of the <widget> tag). Mine looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<widget xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0" android-versionCode="1" id="com.yourid" ios-CFBundleVersion="1" version="1.0.0" xmlns="http://www.w3.org/ns/widgets">
<!--  other tags here -->
SimonBrazell commented 3 years ago

Hi @mcastets thanks for responding.

I tried reinstalling the platform i.e. cordova platform rm android, still get the same error.

AndroidManifest.xml looks like this when I don't include your edit-config solution:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10001" android:versionName="1.0.0" package="..." xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:networkSecurityConfig="@xml/network_security_config" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <provider android:authorities="${applicationId}.cordova.plugin.camera.provider" android:exported="false" android:grantUriPermissions="true" android:name="org.apache.cordova.camera.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/camera_provider_paths" />
        </provider>
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="${GOOGLE_MAPS_ANDROID_API_KEY}" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
        <uses-library android:name="org.apache.http.legacy" android:required="false" />
        <provider android:authorities="${applicationId}.localnotifications.provider" android:exported="false" android:grantUriPermissions="true" android:name="de.appplant.cordova.plugin.notification.util.AssetProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/localnotification_provider_paths" />
        </provider>
        <receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.TriggerReceiver" />
        <receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.ClearReceiver" />
        <service android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.ClickReceiver" />
        <receiver android:directBootAware="true" android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.RestoreReceiver">
            <intent-filter>
                <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false" xmlns:amazon="http://schemas.amazon.com/apk/res/android" />
        <service android:exported="false" android:name="com.onesignal.ADMMessageHandler" />
        <receiver android:name="com.onesignal.ADMMessageHandler$Receiver" android:permission="com.amazon.device.messaging.permission.SEND">
            <intent-filter>
                <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
                <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
                <category android:name="..." />
            </intent-filter>
        </receiver>
    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />
    <uses-feature android:name="android.hardware.location" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
    <permission android:name="....permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
    <uses-permission android:name="....permission.RECEIVE_ADM_MESSAGE" />
    <uses-feature android:name="android.hardware.location.gps" android:required="true" />
</manifest>

When I do include the edit-config snippet it only gets this far:

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="10001" android:versionName="1.0.0" package="..." xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
SimonBrazell commented 3 years ago

@mcastets I was able to resolve the issue by downgrading the cordova-plugin-geolocation to 4.0.2, it appears the issue only arrises in the latest version (4.1.0).

You are running 4.1.0 right? If so it's strange that you were able to resolve it while I wasn't.

mcastets commented 3 years ago

@SimonBrazell Sorry, but I'm quite busy this week. But, I really would like to be helpful and make some experiments to understand your case and find a solution.

You're right, I'm running 4.1.0 so that's really weird.

SimonBrazell commented 3 years ago

All good @mcastets, I think pinning the geolocation plugin to the previous version is enough for me for now, although I still need to test this on a device, I appreciate your efforts regardless.

Cheers!

agabardo commented 3 years ago

downgrading the cordova-plugin-geolocation to 4.0.2 worked for me... Awesome. Thank you @SimonBrazell

mostafa-mansour1 commented 3 years ago

this worked with me

<platform name="android">
.....
 <edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.location.gps']" xmlns:android="http://schemas.android.com/apk/res/android">
            <uses-feature android:name="android.hardware.location.gps" />
        </edit-config>
</platform>
mostafa-mansour1 commented 3 years ago

@mcastets I added the following to my config.xml file as described in your SO post:

<platform name="android">
    <!-- ... -->
    <edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.location.gps']">
        <uses-feature android:name="android.hardware.location.gps" />
    </edit-config>
</platform>

But I get the following error when attempting to build the project:

The prefix "android" for attribute "android:name" associated with an element type "uses-feature" is not bound.

I wonder if there are any other steps you may have left off of your workaround?

Environment:

Ionic:

   Ionic CLI                     : 6.12.2 (.../.nvm/versions/node/v12.19.0/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.1
   @angular-devkit/build-angular : 0.1100.2
   @angular-devkit/schematics    : 11.0.2
   @angular/cli                  : 11.0.2
   @ionic/angular-toolkit        : 3.0.0

Cordova:

   Cordova CLI       : 10.0.0
   Cordova Platforms : android 9.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 12 other plugins)

Utility:

   cordova-res                          : 0.15.2
   native-run (update available: 1.3.0) : 1.2.2

System:

   Android SDK Tools : 26.1.1 (.../Library/Android/sdk/)
   NodeJS            : v12.19.0 (.../.nvm/versions/node/v12.19.0/bin/node)
   npm               : 6.14.8
   OS                : macOS Catalina
   Xcode             : Xcode 12.2 Build version 12B45b

u have to define xmlns:android="http://schemas.android.com/apk/res/android"

arisca-abdullah commented 3 years ago

Try this

<platform name="android">
    .....
    <edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.location.gps']" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-feature android:name="android.hardware.location.gps" android:required="true" />
    </edit-config>
    ....
</platform>
sergip76 commented 3 years ago

Try this

<platform name="android">
    .....
    <edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.location.gps']" xmlns:android="http://schemas.android.com/apk/res/android">
        <uses-feature android:name="android.hardware.location.gps" android:required="true" />
    </edit-config>
    ....
</platform>

It fails. But @mostafa-mansour1 solution works correctly:

<platform name="android">
.....
<edit-config file="app/src/main/AndroidManifest.xml" mode="overwrite" target="/manifest/uses-feature[@android:name='android.hardware.location.gps']" xmlns:android="http://schemas.android.com/apk/res/android">
           <uses-feature android:name="android.hardware.location.gps" />
       </edit-config>
</platform>

Thanks!!

dustinparker commented 2 years ago

Hey everyone,

Thanks for posting your solutions! After trying all the solutions above, I was still getting the same error. The only way I could solve it and get it to build was by following the script solution here. Thought it might help someone else.

TelmoFerreira commented 2 years ago

Try this..

https://github.com/apache/cordova-plugin-geolocation/issues/222#issuecomment-906391121

soft24technologies commented 5 months ago

Thanks @mostafa-mansour1 Your solutions works for me