cordova-plugin-googlemaps icon indicating copy to clipboard operation
cordova-plugin-googlemaps copied to clipboard

Fix #2871 - Resolve blank map when running compiled with latest cordova-android (which uses AGP 4.1.3)

Open ebhsgit opened this issue 4 years ago • 45 comments

Fix #2871

From AGP 4.1.+ assert keyword/statements are enabled by the compile through code rewrite.

Which is causing PluginMap to fail


The issue is caused by PluginMap being initialised 2 times. The 2nd time it is initialised, CordovaPlugin.privateInitialize has assert to prevent this.

This PR removes initialising the PluginMap in CordovaGoogleMaps.getMap, because when it is added to PluginManager it will be initialised then.


NOTE

Although the relevant code in PluginManager and CordovaPlugin has not been changed for many years. The plugin's codebase works for older cordova-android versions because they use older AGP.

In these older versions, assert keyword/statement do nothing

ebhsgit avatar May 21 '21 07:05 ebhsgit

@ebhsgit I installed from your fork and I no longer get custom map marker icons. It always uses the default red pin from Google maps. Can you please test on your end to see if you have a similar problem?

CodeWithOz avatar Jul 26 '21 14:07 CodeWithOz

The problem was that I was using a relative path ('./www/img/myimg.png'). When I switched to the full path (${cordova.file.applicationDirectory}www/img/myimg.png) then it worked. Of course the relative path was working before I switched to this fork, so perhaps you could still check that too.

CodeWithOz avatar Jul 26 '21 17:07 CodeWithOz

@CodeWithOz

Please note my fork is not intended for production usage.

That said, there shouldn't be any changes related to map markers in the fork.

If you find the issue. Feel free to suggest a PR

ebhsgit avatar Jul 26 '21 23:07 ebhsgit

I also have the issue with blank map. Works when AGP 4.0.2 is used, but is broken with AGP 4.1.x and above.

kozuch avatar Jul 27 '21 14:07 kozuch

@wf9a5m75 please merge and publish a new version asap!

EinfachHans avatar Jul 28 '21 10:07 EinfachHans

Kinda strange, because i don't see any changes that would cause that, but i can confirm what @CodeWithOz said. My Markers that are set via url: './assets/...' doesn't work anymore with your PR 🤔

EinfachHans avatar Aug 04 '21 07:08 EinfachHans

I have not tested this fix but if it works please try to merge it so that we can use official release of this plugin and do not have to hack the solution ourselves in code. Without fix we are stuck to [email protected] and can not use latest [email protected] which needs Android Gradle Plugin (AGP) version 4.2.2. Thank you!

kozuch avatar Aug 04 '21 13:08 kozuch

There are no changes in this branch related to markers. This pr is branched from master.

Maybe you guys are using a different branch? eg: multiple_maps, there are lots of other changes between master and multiple_maps

ebhsgit avatar Aug 04 '21 23:08 ebhsgit

Could you try the 20210804 branch? I'm working on the next version recently, and don't touch v2.x these days. But it seems I've tried to improve something.

wf9a5m75 avatar Aug 04 '21 23:08 wf9a5m75

No i'm using your branch @ebhsgit 🤔 Before i was using Version 2.7.1.

@wf9a5m75 i think this should be fixed in a hotfix 2.7.2 as it blocks the migration to cordova-android@10

EinfachHans avatar Aug 05 '21 06:08 EinfachHans

@wf9a5m75 i just tried to install from your branch. I got a lot of build errors, for example:

L.92: Cannot resolve symbol 'viewPlugins'
L.102: Inconvertible types; cannot cast 'org.apache.cordova.PluginEntry' to 'plugin.google.maps.PluginMarker'
L.410: Cannot resolve method 'getGoogleMap' in 'PluginMap'

in PluginMarker.java

and lots of Errors in CordovaGoogleMaps.java, which seems all be related to:

L.52: Cannot resolve symbol 'MyPluginLayout'

All in all 66 Errors Bildschirmfoto 2021-08-05 um 11 38 40

EinfachHans avatar Aug 05 '21 09:08 EinfachHans

@CodeWithOz @EinfachHans

Not sure what the issue is with icons.

The changes are simple, and are definitely not related to markers.

ebhsgit avatar Aug 05 '21 11:08 ebhsgit

@ebhsgit give it a try yourself 😃

EinfachHans avatar Aug 05 '21 11:08 EinfachHans

I am not experiencing any issues with markers

ebhsgit avatar Aug 05 '21 11:08 ebhsgit

Do you add at least one via ./assets/...?

EinfachHans avatar Aug 05 '21 11:08 EinfachHans

Yup.

eg:

./assets/imgs/map/markers/start.png

ebhsgit avatar Aug 05 '21 11:08 ebhsgit

Do you just set the icon: './assets/imgs/map/markers/start.png' or do you set more options like size and anchor?

EinfachHans avatar Aug 05 '21 11:08 EinfachHans

icon: {
   url: '....',
   size: '.....'
}

ebhsgit avatar Aug 05 '21 11:08 ebhsgit

Strange, Version 2.7.1 works fine, but when i install from this PR directly it doesn't

EinfachHans avatar Aug 05 '21 11:08 EinfachHans

https://github.com/mapsplugin/cordova-plugin-googlemaps/pull/2872#issuecomment-893316041

I was able to build the plugin in ionic v5 project at least. Did you rebuild with command ionic cordova clean then ionic cordova build android?

wf9a5m75 avatar Aug 05 '21 16:08 wf9a5m75

@wf9a5m75 I completely removed the platforms, plugins, www, node_modules folder and the package_lock.json and installed and build everything from zero

EinfachHans avatar Aug 05 '21 16:08 EinfachHans

Okay i debugged a bit more, looks like this Marker Problem is cordova-android related: https://github.com/apache/cordova-android/issues/1316 - Thanks 😊

EinfachHans avatar Aug 09 '21 07:08 EinfachHans

Sadly still white map :(

yurik94 avatar Oct 12 '21 01:10 yurik94

It really needs to be fixed soon, because the switch to Android 11 (API Level 30) will be required by Google from 1st Nov 2021. Can the current fix be used in production at least?

alexp25 avatar Oct 17 '21 10:10 alexp25

The fix https://github.com/mapsplugin/cordova-plugin-googlemaps/commit/1de03cdb14f0239c23ac88d59ea296fa185be56e seemes to solve the white map issue but unfortunately, the app crashes when loading custom markers.

alexp25 avatar Oct 17 '21 11:10 alexp25

Actually, this fix by @ebhsgit seems to work with a clean install (reinstall platform and plugins, and also remove package-lock.json) https://github.com/mapsplugin/cordova-plugin-googlemaps/commit/0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443. With the merge commit https://github.com/mapsplugin/cordova-plugin-googlemaps/commit/1de03cdb14f0239c23ac88d59ea296fa185be56e I got some build errors as pointed out by @EinfachHans

alexp25 avatar Oct 17 '21 12:10 alexp25

@wf9a5m75 any timeline on when this will be merged. Many of us are waiting for the fix since switch to Android 11 (API Level 30) will be required by Google from 1st Nov 2021.

Could you please provide your thoughts upon this.

Thanks

sachi097 avatar Oct 20 '21 08:10 sachi097

@alexp25 comment out line 1150 and 1151 (result.image.recycle(),result.image = null) in the file src/android/plugin/google/maps/PluginMarker.java then custom markers work fine

lrobak0 avatar Oct 20 '21 13:10 lrobak0

@alexp25 @lrobak0 can someone please help me installing commit 1de03cd

Currently I am installing via below command cordova plugin add https://github.com/mapsplugin/cordova-plugin-googlemaps#1de03cdb14f0239c23ac88d59ea296fa185be56e

Is this correct?

sachi097 avatar Oct 21 '21 08:10 sachi097

I installed: https://github.com/mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443

lrobak0 avatar Oct 21 '21 08:10 lrobak0