Flutter url_launcher is not launching url in release mode
Asked Answered
S

11

36

I don't know for some reason url_launcher (https://pub.dev/packages/url_launcher) is not working after downloading app from google playstore. In debug mode it is working the way it should be. But after uploading app on playstore and downloading it from there, url launcher is not launching any url. WHY is that?

import 'package:url_launcher/url_launcher.dart';

 onTap: () {
  launchURL("https://www.google.com");
},
..............
  launchURL(String url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

pubspec.yaml url_launcher: ^5.7.6

I've also added android.permission.INTERNET

I'm not using latest version of url_launcher so may be using latest version will solve the issue BUT problem with it is that latest version of url_launcher needs latest version of flutter. Is it safe to upgrade flutter version? I can't take a risk of causing any more issues as my app is already in production

This is what I get when I try to upgrade to url_launcher: ^5.7.10 which is the latest version and run flutter pub get

[xxxxx] flutter pub get
Running "flutter pub get" in xxxxx...                       
The current Flutter SDK version is 1.22.0-9.0.pre.

Because url_launcher >=5.7.7 <6.0.0-nullsafety depends on url_launcher_platform_interface >=1.0.9 <2.0.0-nullsafety which requires Flutter SDK version >=1.22.0 <2.0.0, url_launcher >=5.7.7 <6.0.0-nullsafety is forbidden.

So, because xxxxx depends on url_launcher ^5.7.10, version solving failed.
pub get failed (1; So, because storeifie depends on url_launcher ^5.7.10, version solving failed.)
exit code 1
Scad answered 25/1, 2021 at 11:26 Comment(1)
Did you fix that issue already?Swanky
T
3

First of all, you are on dev channel of the flutter (1.22.0-9.0.pre is a dev version, released on 2/9/2020). Since your app is in production, please change the channel to stable, since it has no breaking bugs.

flutter channel stable

and then do flutter upgrade.

 flutter upgrade

Now, try to upgrade the url_launcher package to the latest version. It should work.

PS: Don't worry about flutter upgrading, as long as you are upgrading in the stable branch. it is always recommended to run the latest version.

Twoply answered 25/1, 2021 at 11:37 Comment(2)
After upgrading flutter and url launcher version, everything is working fine in debug mode. How can I launch application in release mode? I want to test app before uploading it to google playstore.Scad
" flutter build apk --release " or check the accepted answer of this question #51001369Twoply
C
55

I had the same problems with Android 11 (API level 30) - everything worked well before software update (and on my test device that is running earlier version) - The following seems to have put me on the right track https://developer.android.com/training/basics/intents/package-visibility#all-apps

I solved my problem by adding the following in the AndroidManifest.xml (although it may not be necessary.)

<activity android:name="io.flutter.plugins.urllauncher.WebViewActivity"
           android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
           android:exported="false"/>

That alone did not work, and then I added to the lines just below <manifest ... package="com.example.app":

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
Cookstove answered 23/3, 2021 at 12:0 Comment(6)
Thanks a lot! Adding permission only worked well, had the same issue with API Level 30.Multifarious
Adding the permission worked for me too, however I had to uninstall and re install the app. Flutter clean did not rebuild with manifest changes.Exit
It looks like the url_launcher package now has documentation for this, but recommends a different approach. See @RITTIK 's answer below or check out pub.dev/packages/url_launcher#androidAuria
Google is cracking down on QUERY_ALL_PACKAGES, so this solution is better avoided. Speaking in April 2022.Anybody
did u find the solution.. my app got rejected due to i used QUERY_ALL_PACKAGESRiella
QUERY_ALL_PACKAGES is NOT the way to fix that issue - your app will be rejected. You have to update Flutter to 2+, update url_launcher version and include <queries> tags in Android's manifest file: <queries> <intent> <action android:name="android.intent.action.VIEW" /> <data android:scheme="https" /> </intent> </queries>Surmise
C
16

I skipped calling canLaunch(url) and call launch(url) in try-catch, it's work

Creation answered 24/8, 2021 at 11:47 Comment(1)
I don't want try catch in my release build since it's bad practise to do so, what can I do?Eldwen
D
15

Looks like since API 30 of Android you should need to add explicit the intents you will do. for example if you will open a URL you will need to add the following code to your AndroidManifest.

<queries>
    <!-- to opens https URLs -->
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
</queries>

You can see the update in the url_launcher read.me: https://pub.dev/packages/url_launcher

Diplomacy answered 11/10, 2021 at 14:33 Comment(0)
P
5

If you are trying out the URL launcher in Android and the device API is 30+, try adding the query intent outside of the application tag in the Android Manifest.

<queries>
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
</queries>
Pelson answered 14/1, 2023 at 9:59 Comment(0)
B
4

I directly used launch() in a try-catch block without any condition of canLaunch() and it worked fine

Ballew answered 15/12, 2021 at 22:10 Comment(0)
T
3

First of all, you are on dev channel of the flutter (1.22.0-9.0.pre is a dev version, released on 2/9/2020). Since your app is in production, please change the channel to stable, since it has no breaking bugs.

flutter channel stable

and then do flutter upgrade.

 flutter upgrade

Now, try to upgrade the url_launcher package to the latest version. It should work.

PS: Don't worry about flutter upgrading, as long as you are upgrading in the stable branch. it is always recommended to run the latest version.

Twoply answered 25/1, 2021 at 11:37 Comment(2)
After upgrading flutter and url launcher version, everything is working fine in debug mode. How can I launch application in release mode? I want to test app before uploading it to google playstore.Scad
" flutter build apk --release " or check the accepted answer of this question #51001369Twoply
L
1

It could be due to a lower version of Kotlin Gradle. My old version, 1.6.10, had an issue. After I updated it to 1.7.10, the issue was resolved.

Logician answered 18/10, 2023 at 9:59 Comment(0)
E
0

To begin with AndroidManifest.xml add the below code,

<queries>
  <!-- If your app checks for url support -->
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
</queries>




class MapsUtils
{
  MapsUtils._();

  //latitude and longitude

  static Future<void> openMapWithPosition(double latitude, double longitude) async
  {
    String googleMapUrl = "https://www.google.com/maps/search/?api=1&query=$latitude,$longitude";

    if (await canLaunchUrlString(googleMapUrl))
      {
        await launchUrlString(googleMapUrl, mode: LaunchMode.externalApplication);
      }
    else
      {
        throw "Could not open map.";
      }
  }

  //text address
  static Future<void> openMapWithAddress(String completeAddress) async
  {
    String query = Uri.encodeComponent(completeAddress);
    String googleMapUrl = "https://www.google.com/maps/search/?api=1&query=$query";

    if (await canLaunchUrlString(googleMapUrl))
    {
      await launchUrlString(googleMapUrl, mode: LaunchMode.externalApplication);
    }
    else
    {
      throw "Could not open map.";
    }
  }

}

for More info laucher

Ephemeral answered 10/11, 2022 at 13:34 Comment(0)
G
0

In my case i was creating my Uri : Uri.dataFromString(String) while i should use .parse rather thand .dataFromString example code :

  try {
      // Uri requestedUri = Uri.dataFromString(url); //.dataFromString [wrong method]

  Uri requestedUri = Uri.parse(url);// .parse is the correct method

  if (await canLaunchUrl(requestedUri)) {
    await launchUrl(requestedUri);
  } else {
    throw  Exception('Could not launch $url');
  }
} on PlatformException catch (e) {
debugPrint("PlatformException launchInBrowser : $e");
} on Exception catch (e) {
debugPrint( "Exception launchInBrowser : $e");
}
Gemstone answered 15/1, 2024 at 10:49 Comment(0)
A
0

this is worked for me

add in your android manifest

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
Agadir answered 28/3, 2024 at 10:27 Comment(0)
M
-1

add permission to <AndroidManifest.xml> under the <manifest ... package="com.example.app": Hot restart or you have to uninstall app and install it again

Madame answered 6/2, 2022 at 11:39 Comment(1)
this is a poor explanation :/Australopithecus

© 2022 - 2025 — McMap. All rights reserved.