android - 从 Flutter App 启动 Whatsapp 时出现问题

标签 android flutter flutter-dependencies

我正在创建一个应用程序,我需要启动 Whatsapp。我尝试了此处描述的内容:pub.dartlang.org/packages/flutter_launch并且我在我的项目中粘贴了相同的代码。这是问题所在:

What went wrong:
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'flutter_launch' is using version 1.1.51.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org

这是我的代码:

import 'package:flutter/material.dart';
import 'package:flutter_launch/flutter_launch.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  initState() {
    super.initState();
  }

  void whatsAppOpen() async {
    await FlutterLaunch.launchWathsApp(phone: "3381559137", message: "Hello");
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body: new Center(
          child: FlatButton(
            child: Text("Open WhatsApp"),
            onPressed: () {
              whatsAppOpen();
            },
          )
        ),
      ),
    );
  }
}

最佳答案

The Android Gradle plugin supports only Kotlin Gradle plugin version 1.2.51 and higher. Project 'flutter_launch' is using version 1.1.51.

如果您正在关注此 example ,问题解决了:

buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()

为此:

buildscript {
    ext.kotlin_version = '1.2.51'
    repositories {
        google()

build.gradle文件中

编辑

您可以查看此 thread有问题,他们必须重建插件。 一个人提议使用旧版本

var whatsappUrl ="whatsapp://send?phone=${_numberController.text}&text=${_textController.text}";
    await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");

使用这个 url_launcher 而不是 flutter_launch

url_launcher: 4.0.0 in pubspec.yml

import 'package:url_launcher/url_launcher.dart';

试一试,否则您可以查看如何从库中排除版本并使用您的版本,就像这个人所做的那样,但我没有测试过 replace kotlin plugin from flutter on runtime

关于android - 从 Flutter App 启动 Whatsapp 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55363174/

相关文章:

Flutter重复文件包和依赖项

android - Flutter 版本解决此特定应用程序上的失败错误

android - IDE 无法打开库依赖对话框(Maven 依赖)

android - 在 Android 模拟器上运行 Cordova 错误 : "android: Command failed with exit code 2"

dart - Flutter Stepper - 显示所有内容

json - flutter 下拉刷新

android - 哪个是适用于 Android 的最佳 SIP 兼容编解码器类型

java - 为什么我的单例是同步的,但它被创建了很多次?

Flutter:光滑的圆角

debugging - 错误 : Access denied finding property "vendor.gralloc.disable_ahardware_buffer"