question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: phonegap-launch-navigator plugin navigate method stopped working after migrating to capacitor 4

See original GitHub issue

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/android: 4.3.0
  @capacitor/ios: 4.3.0

Installed Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/ios: 4.3.0
  @capacitor/android: 4.3.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

Android

Current Behavior

Invoking phonegap-launch-navigator plugin navigate method with an address param (start param - see https://github.com/dpa99c/phonegap-launch-navigator#navigate-to-a-destination-with-specified-start-location) started to always fail after migration to Capacitor 4. The problem is that the plugin tries to geocoder the address to coordinates (see https://github.com/dpa99c/phonegap-launch-navigator/blob/master/src/android/lib/LaunchNavigator.java#L1698) by sending http request and it always fails with android.os.NetworkOnMainThreadException because the plugin method is executed on the main thread.

My assumption is that this is because in Capacitor 4 there was the change made which executes postMessage on the main thread (https://github.com/ionic-team/capacitor/pull/5427/files#diff-7d14ff84aa5a03137668f3f22aa00981610317e3afbf5dcee8bb2c41bb31591bR30). The problem does not exist with Capacitor 3 so my assumption is that this is kind of a breaking change, which might make some plugins stop working

Expected Behavior

The existing plugins must work as before after migration to Capacitor 4

Code Reproduction

I hope that the above description is self explanatory however, i can create the required github repository showing the issue.

Additional Context

N/A

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jcesarmobilecommented, Oct 19, 2022

We changed the bridge to use a new bridge provided by google, it’s the new bridge what executes code in the main thread while the old one did it in a background thread (because the call came from js and calls from js to native use a background thread). It was google’s decision to change the bridge to use the ui thread, to be honest, I didn’t even realized until you brought this issue, because all our core plugins kept working with the new bridge. Not sure what’s their reasoning for doing that or if it would be a good idea to use a background thread where google wants to use the ui thread.

We will discuss internally, but options are a) provide a config option to use the old bridge b) use background thread only for Cordova plugins c) use background thread for all plugins (potentially breaking change)

a and b can happen in a minor or patch releases respectively, c might need to wait for a major release, but both a and b should fix this problem

1reaction
jcesarmobilecommented, Oct 18, 2022

Thanks for the sample app, I’ve been able to reproduce. Calling postMessage in a background thread like this fixes the issue, but not sure if adding that now could be considered breaking.

bridge.execute(() -> {
    postMessage(message.getData());
});

We have a feature request for allowing to configure the bridge so people can keep using the old one, that should solve this issue too for now https://github.com/ionic-team/capacitor/issues/5949

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot finish Capacitor 4 migration due to build error
I'm trying to migrate our Capacitor version from 2 to 4. After making the necessary upgrades and updates listed on the docs, I'm...
Read more >
Migrating Cordova Plugins to Capacitor (Android) - Elite Ionic
In this tutorial, we will be investigating how to configure existing Cordova plugins to work with Capacitor that don't work out of the...
Read more >
Converting a Cordova Application to Capacitor - Ionic
Converting a Cordova application to a Capacitor application is a multi-step process ... Proper plugin management will make migration easier.
Read more >
[Done]-How to use cordova-waze-navigator plugin
WazeNavigator.navigateByPosition({ lat: 50, // latitude lng: -4 // longitude });. Or you could use the updated version 3 of phonegap-launch-navigator plugin, ...
Read more >
How Capacitor Migrates Cordova Plugins - YouTube
In this video, we investigate how Capacitor takes a Cordova plugin and makes it work in Capacitor. We also discuss how we might...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found