Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ebhsgit
Copy link
Contributor

@ebhsgit ebhsgit commented May 21, 2021

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
Copy link

@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
Copy link

CodeWithOz commented Jul 26, 2021

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
Copy link
Contributor Author

ebhsgit commented Jul 26, 2021

@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
Copy link

kozuch commented Jul 27, 2021

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
Copy link
Contributor

@wf9a5m75 please merge and publish a new version asap!

@EinfachHans
Copy link
Contributor

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
Copy link

kozuch commented Aug 4, 2021

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
Copy link
Contributor Author

ebhsgit commented Aug 4, 2021

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
Copy link
Member

wf9a5m75 commented Aug 4, 2021

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
Copy link
Contributor

EinfachHans commented Aug 5, 2021

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
Copy link
Contributor

@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
Copy link
Contributor Author

ebhsgit commented Aug 5, 2021

@CodeWithOz
@EinfachHans

Not sure what the issue is with icons.

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

@EinfachHans
Copy link
Contributor

@ebhsgit give it a try yourself 😃

@ebhsgit
Copy link
Contributor Author

ebhsgit commented Aug 5, 2021

I am not experiencing any issues with markers

@EinfachHans
Copy link
Contributor

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

@ebhsgit
Copy link
Contributor Author

ebhsgit commented Aug 5, 2021

Yup.

eg:

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

@EinfachHans
Copy link
Contributor

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

@ebhsgit
Copy link
Contributor Author

ebhsgit commented Aug 5, 2021

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

@EinfachHans
Copy link
Contributor

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

@wf9a5m75
Copy link
Member

wf9a5m75 commented Aug 5, 2021

#2872 (comment)

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
Copy link
Contributor

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

@EinfachHans
Copy link
Contributor

Okay i debugged a bit more, looks like this Marker Problem is cordova-android related: apache/cordova-android#1316 - Thanks 😊

lempere pushed a commit to we-are-Joinup/cordova-plugin-googlemaps that referenced this pull request Sep 6, 2021
@yurik94
Copy link

yurik94 commented Oct 12, 2021

Sadly still white map :(

@alexp25
Copy link

alexp25 commented Oct 17, 2021

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
Copy link

alexp25 commented Oct 17, 2021

The fix 1de03cd seemes to solve the white map issue but unfortunately, the app crashes when loading custom markers.

@alexp25
Copy link

alexp25 commented Oct 17, 2021

Actually, this fix by @ebhsgit seems to work with a clean install (reinstall platform and plugins, and also remove package-lock.json) 0b8ea76. With the merge commit 1de03cd I got some build errors as pointed out by @EinfachHans

@sachi097
Copy link

@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
Copy link

lrobak0 commented Oct 20, 2021

@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
Copy link

@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
Copy link

lrobak0 commented Oct 21, 2021

@sachi097
Copy link

sachi097 commented Oct 21, 2021

@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
Copy link

alexp25 commented Oct 21, 2021

@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
Copy link

lrobak0 commented Oct 21, 2021

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
Copy link

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

Copy link

@shajz shajz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and approved with

"cordova-android": "^10.1.1",
"cordova-plugin-androidx-adapter": "^1.1.3",
"cordova-plugin-googlemaps": "github:mapsplugin/cordova-plugin-googlemaps#0b8ea76ad34fb2a202a9de1b9d0e051a82ad9443",

Additional info for anyone struggling with the cordova-android@10 upgrade

  • As I'm using "cordova-plugin-geolocation": "^4.1.0",, I had to add <custom-preference delete="true" name="android-manifest/uses-feature[@android:name='android.hardware.location.gps']" /> (plugin cordova-custom-config is necessary) in my config.xml and set "cordova-plugin-geolocation": { "GPS_REQUIRED": "false" }, in my package.json. (because both plugins add this entry in AndroidManifest.xml, the build will crash. This line removes one of the two entries)
  • I also set <preference name="AndroidInsecureFileModeEnabled" value="true" /> as I'm still using file:// scheme internally.

@wf9a5m75 could you merge this PR and release 2.7.2 to help others migrate to cordova-android@10 ? Thanks!

@ebhsgit
Copy link
Contributor Author

ebhsgit commented Oct 23, 2021

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

@adirgan
Copy link

adirgan commented Oct 26, 2021

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

@cels
Copy link

cels commented Dec 10, 2021

Are there any estimates when this will be merged?

@mrbdrm
Copy link

mrbdrm commented Jan 1, 2022

Kindly Merge

thank you for the support :)

@natIs3
Copy link

natIs3 commented Mar 4, 2022

Hi when can you merge this branch?

@sachi097
Copy link

@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
Copy link

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

@gfranco69
Copy link

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
Copy link

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
Copy link

gfranco69 commented Dec 8, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] When app is compiled with AGP 4.1.3 ('com.android.tools.build:gradle:4.1.3'), the map is blank