Skip to content

Commit

Permalink
Fix plugin crashes caused by failing assertions
Browse files Browse the repository at this point in the history
The Maps plugin creates some helper CordovaPlugin objects and registers
them with PluginManager, and, at the same time, calls
'privateInitialize' manually. This causes an assertion to trip inside
Cordova Android.

The failing assertion only affects debug-mode builds that use a new
Android SDK. See also
mapsplugin#2900
  • Loading branch information
lorenzodallavecchia committed Sep 6, 2022
1 parent 3d1d9e9 commit 66e8d26
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/android/plugin/google/maps/CordovaGoogleMaps.java
Expand Up @@ -454,6 +454,7 @@ public void getMap(final JSONArray args, final CallbackContext callbackContext)
pluginMap.mapCtrl = CordovaGoogleMaps.this;
pluginMap.self = pluginMap;

pluginMap.cordova = null; // avoid failure caused by repreated initialization
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
pluginManager.addService(pluginEntry);

Expand All @@ -475,6 +476,7 @@ public void getPanorama(final JSONArray args, final CallbackContext callbackCont
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
pluginStreetView.self = pluginStreetView;

pluginStreetView.cordova = null; // avoid failure caused by repreated initialization
PluginEntry pluginEntry = new PluginEntry(mapId, pluginStreetView);
pluginManager.addService(pluginEntry);

Expand Down
2 changes: 2 additions & 0 deletions src/android/plugin/google/maps/PluginMap.java
Expand Up @@ -613,6 +613,7 @@ public synchronized void loadPlugin(final JSONArray args, final CallbackContext
plugins.put(pluginName, pluginEntry);
mapCtrl.pluginManager.addService(pluginEntry);

plugin.cordova = null; // avoid failure caused by repreated initialization
plugin.privateInitialize(pluginName, cordova, webView, null);

plugin.initialize(cordova, webView);
Expand Down Expand Up @@ -666,6 +667,7 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
pluginMap = PluginMap.this;
pluginMap.mapCtrl.pluginManager.addService(pluginEntry);

plugin.cordova = null; // avoid failure caused by repreated initialization
plugin.privateInitialize(className, cordova, webView, null);
plugin.initialize(cordova, webView);
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
Expand Down

0 comments on commit 66e8d26

Please sign in to comment.