mapsplugin / cordova-plugin-googlemaps

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

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

Open ebhsgit opened 3 years ago

ebhsgit commented 3 years ago

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

CodeWithOz commented 3 years ago

@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 commented 3 years ago

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.

ebhsgit commented 3 years ago

@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

kozuch commented 3 years ago

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.

EinfachHans commented 3 years ago

@wf9a5m75 please merge and publish a new version asap!

EinfachHans commented 3 years ago

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 🤔

kozuch commented 3 years ago

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 cordova-android@9.1.0 and can not use latest cordova-android@10.0.0 which needs Android Gradle Plugin (AGP) version 4.2.2. Thank you!

ebhsgit commented 3 years ago

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

wf9a5m75 commented 3 years ago

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.

EinfachHans commented 3 years ago

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 commented 3 years ago

@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

ebhsgit commented 3 years ago

@CodeWithOz @EinfachHans

Not sure what the issue is with icons.

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

EinfachHans commented 3 years ago

@ebhsgit give it a try yourself 😃

ebhsgit commented 3 years ago

I am not experiencing any issues with markers

EinfachHans commented 3 years ago

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

ebhsgit commented 3 years ago

Yup.

eg:

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

EinfachHans commented 3 years ago

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

ebhsgit commented 3 years ago
icon: {
   url: '....',
   size: '.....'
}
EinfachHans commented 3 years ago

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

wf9a5m75 commented 3 years ago

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?

EinfachHans commented 3 years ago

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

EinfachHans commented 3 years ago

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

yurik94 commented 3 years ago

Sadly still white map :(

alexp25 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

sachi097 commented 3 years ago

@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

lrobak0 commented 3 years ago

@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

sachi097 commented 3 years ago

@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?

lrobak0 commented 3 years ago

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

sachi097 commented 3 years ago

@lrobak0 thanks for the quick response.

If I get it right you meant, cordova plugin add https://github.com/mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443

Quick questions: 1) Did you get any build errors post install? 2) Is the Map now rendering? 3) Did you test in production?

alexp25 commented 3 years ago

@sachi097 you can also define it in the package.json: "cordova-plugin-googlemaps": "git+https://github.com/mapsplugin/cordova-plugin-googlemaps.git#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443"

In my case, having a large project with lots of plugins, lots of features, custom markers, interactions:

  1. The build passed
  2. The map is rendering properly
  3. Partially tested but not in production
lrobak0 commented 3 years ago

yes,

  1. Did you get any build errors post install? - I musted add library com.google.android.libraries.maps:maps:3.1.0-beta in file project.properties
  2. Yes
  3. Did you test in production? - no
sachi097 commented 3 years ago

@alexp25 @lrobak0 thanks for your answers.

As per @lrobak0 comment installed the plugin via cordova plugin add https://github.com/mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443

Summary:

  1. Got build errors initially, then uninstalled all the plugins and reinstalled (including https://github.com/mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443), deleted www folder and reinstall platform (ionic cordova platform add android@10.1.0). Post this build passed like a charm.
  2. The map is rendering properly.
  3. Currently, my app is in development phase. I will provide feedback once I test in production.
ebhsgit commented 3 years ago

PR #2887 will fix the customer marker issue mentioned here with cordova-android 10+, without needing to set AndroidInsecureFileModeEnabled

adirgan commented 3 years ago

Hello everyone, do you know when you will do the merge of this PR?

cels commented 2 years ago

Are there any estimates when this will be merged?

mrbdrm commented 2 years ago

Kindly Merge

thank you for the support :)

natIs3 commented 2 years ago

Hi when can you merge this branch?

sachi097 commented 2 years ago

@alexp25 @lrobak0 thanks for your answers.

As per @lrobak0 comment installed the plugin via cordova plugin add https://github.com/mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443

Summary:

  1. Got build errors initially, then uninstalled all the plugins and reinstalled (including https://github.com/mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443), deleted www folder and reinstall platform (ionic cordova platform add android@10.1.0). Post this build passed like a charm.
  2. The map is rendering properly.
  3. Currently, my app is in development phase. I will provide feedback once I test in production.

Map works like charm in the production.

nosTa1337 commented 2 years ago

Any updates on merging this? Just updated my cordova to android 10 and faced this issue. Testing the PR right now.

gfranco69 commented 2 years ago

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

Thank you , this fix Blank White Map Screen , but , now dont fire , plugin.google.maps.event.PANORAMA_READY @wf9a5m75 Any help would be appreciated.

subha-menuHuts commented 1 year ago

i have

"cordova-android": "^10.1.2", "cordova-plugin-androidx-adapter": "^1.1.3", "cordova-plugin-googlemaps": "^2.7.1",

google map not load display white screen

any one help me

gfranco69 commented 1 year ago

Replace these files CordovaGooleMaps PluginMap

Copy here: ....\\platforms\android\app\src\main\java\plugin\google\maps


From: subha-menuHuts @.> Sent: Thursday, December 8, 2022 8:02 AM To: mapsplugin/cordova-plugin-googlemaps @.> Cc: Guillermo Franco @.>; Comment @.> Subject: Re: [mapsplugin/cordova-plugin-googlemaps] Fix #2871 - Resolve blank map when running compiled with latest cordova-android (which uses AGP 4.1.3) (#2872)

i have

"cordova-android": "^10.1.2", "cordova-plugin-androidx-adapter": "^1.1.3", "cordova-plugin-googlemaps": "^2.7.1",

google map not load display white screen

any one help me

— Reply to this email directly, view it on GitHubhttps://github.com/mapsplugin/cordova-plugin-googlemaps/pull/2872#issuecomment-1342623330, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIJPNTMDXNQGLISIN27V5IDWMHE5PANCNFSM45IT6X7Q. You are receiving this because you commented.Message ID: @.***>