首页 > 解决方案 > Flutter url_launcher 未在发布模式下启动 url

问题描述

我不知道由于某种原因url_launcherhttps://pub.dev/packages/url_launcher)从谷歌 Playstore 下载应用程序后无法正常工作。在调试模式下,它按应有的方式工作。但是在 Playstore 上上传应用程序并从那里下载后,url 启动器没有启动任何 url。这是为什么?

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';
    }
  }

发布规范.yaml url_launcher: ^5.7.6

我也加了android.permission.INTERNET

我没有使用最新版本,url_launcher所以可能使用最新版本可以解决问题,但问题是最新版本 url_launcher需要最新版本的颤振。升级flutter版本安全吗?由于我的应用程序已经投入生产,我不能冒险引发更多问题

这是我尝试升级到 url_launcher: ^5.7.10最新版本并运行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

标签: flutterdarturllauncher

解决方案


我在使用 Android 11(API 级别 30)时遇到了同样的问题——在软件更新之前一切正常(以及在我运行早期版本的测试设备上)——以下似乎让我走上了正确的轨道 https://developer。 android.com/training/basics/intents/package-visibility#all-apps

我通过在 AndroidManifest.xml 中添加以下内容解决了我的问题(尽管可能没有必要。)

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

仅此一项不起作用,然后我添加到 <manifest ... package="com.example.app" 正下方的行中:

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

推荐阅读