使用 flutter_local_notifications 和位置包时出现 flutter 错误“Android dependency 'androidx.core:core' has different version”

2023-11-21

美好的一天,我尝试制作一个带有 Android 和 ios 通知的简单天气应用程序,为此我使用基础 flutter 应用程序和库flutter_local_notifications: ^0.5.1+2 and location: ^2.0.0,但是同时使用它们我得到一个错误:

Launching lib\main.dart on SM A520F in debug mode...
Initializing gradle...
Resolving dependencies...
Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0-rc01) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution

* 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

BUILD FAILED in 2s
Finished with error: Gradle task assembleDebug failed with exit code 1

颤振医生输出:

C:\src\flutter\bin\flutter.bat doctor --verbose
[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.17134.590], locale ru-RU)
    • Flutter version 1.0.0 at C:\src\flutter
    • Framework revision 5391447fae (3 months ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\zande\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[√] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] VS Code (version 1.31.0)
    • VS Code at C:\Users\zande\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[√] Connected device (1 available)
    • SM A520F • 5200291746c1b485 • android-arm64 • Android 8.0.0 (API 26) (emulator)

! Doctor found issues in 1 category.
Process finished with exit code 0

我的 pubspec.yaml:

name: flutter_app
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.0.0-dev.68.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  flutter_local_notifications: ^0.5.1+2
  location: ^2.0.0

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.io/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.io/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.io/custom-fonts/#from-packages

我的 main.dart:

import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:location/location.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
            RaisedButton(
                onPressed: () {
                  setState(() {
                    _counter = 0;
                  });
                },
                child: Text('to 0')),
            new Padding(
              padding: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 8.0),
              child: new Text(
                  'Tap on a notification when it appears to trigger navigation'),
            ),

          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  Future onSelectNotification(String payload) async {
    showDialog(
      context: context,
      builder: (_) {
        return new AlertDialog(
          title: Text("PayLoad"),
          content: Text("Payload : $payload"),
        );
      },
    );
  }
}

My build.gradle file:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutterapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我尝试使用其他地理定位库,但经常遇到类似错误

D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

for 地理位置查找器 library

or WARNING: This version of device_info will break your Android build if it or its dependencies aren't compatible with AndroidX.

for 地理定位器图书馆

我应该做什么来制作我的天气应用程序?


不是开玩笑,我最近遇到了同样的问题(我收到了很多关于 AndroidX 的各种依赖项的投诉,以 -rc01 版本结尾),并且强制解决策略的各种解决方案不起作用。

我通过升级 android/build.gradle 文件中的 gradle 依赖项解决了这个问题: classpath 'com.android.tools.build:gradle:3.3.1' (我之前使用的是版本 3.2.1)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 flutter_local_notifications 和位置包时出现 flutter 错误“Android dependency 'androidx.core:core' has different version” 的相关文章

  • Sqlite 查询检查 - 小于和大于

    return mDb query DATABASE TABLE new String KEY ROWID KEY LEVEL KEY LEVEL gt 3 lt 5 null null null null 我究竟做错了什么 它返回的值全部高
  • 为网络和/或持久存储序列化 Android Bundle?

    我需要序列化一个全面的应用程序 游戏 状态 以便通过网络传输或保存到磁盘并在以后检索 当然 捆绑包用于在多个用例中保存 恢复状态 因此使用它们将是理想的选择 但是 由于某种原因 Bundle 不可序列化 寻找解决方案只发现了将 Bundle
  • Android 上通过 JSCH 的基本 SSH 连接

    作为来自此的用户question https stackoverflow com questions 14323661 simple ssh connect with jsch和这个tutorial http eridem net andr
  • 如何在 Android 中创建刮刮卡?

    我需要为我在学校的期末项目创建一个 刮刮卡 应用程序 但找不到如何实现刮刮事件的方法 如何创建背景图像并在其上放置灰色矩形 所以当我刮刮这些矩形时我会看到他们下面的图片 实现必须在 Android 中 因为我还不知道如何在 Objectiv
  • 如何在 android-studio 0.3.6 中运行 Gradle 1.9?

    我只是花了一些时间尝试将现有的 android studio 项目从 gradle 1 8 迁移到 gradle 1 9 Final 昨天发布 但失败了19th Nov 我在这里阅读了大多数其他与 gradle 相关的帖子 但没有一个对我有
  • 不使用 CookieManager 的 Android 会话 cookie

    我的应用程序进行多次网络调用以获得身份验证 我需要将此会话存储在 cookie 中 我想使用 Cookie Manager 但经过一些研究后 我发现它仅适用于 API 9 及更高版本 并且我的应用程序需要向后兼容 我使用 HTTPURLCo
  • 使用 POST 将数据从 Android 发送到 AppEngine Datastore

    抱歉 如果这是一个简单的问题 但我只是不知道我应该做什么 而且我认为我有点超出了我的深度 我想将数据从 Android 应用程序发送到在 Google App Engine 上运行的应用程序 数据必须从那里写入数据存储区 我的数据主要采用对
  • 用于代码生成的 ANTLR 工具版本 4.7.1 与当前运行时版本 4.5.3 不匹配

    我正在开发一个 Android 应用程序 当前使用 DSL 和一些库 突然构建给了我这个错误 任务 app kaptDebugKotlin 失败 用于代码生成的 ANTLR 工具版本 4 7 1 与当前运行时版本 4 5 3 不匹配 用于解
  • Android Studio——清除Instrumentation Test的应用程序数据

    如何让 Android Studio AndroidJunitRunner 在仪器测试之前清除应用程序数据而无需手动运行adb命令 我发现android support test runner AndroidJUnitRunner有点作弊
  • 来自外部 XML 的 Android 本地化

    是否可以使用从服务接收到的 XML 在运行时翻译 Android 应用程序 如果可能的话 请有人指出我正确的方向 谢谢 Warning 我读到的所有内容都表明 让您的应用程序更改语言不是一个好主意 因为 Android 框架不支持它 并且可
  • ImageButton 拉伸背景图像

    我正在尝试创建一个没有边框的 ImageButton 但遇到了图像按钮大小的问题 我使用 Eclipse ADT 将 ImageButton 拖到布局中并选择背景图像 图像按钮显示如下 正如您所看到的 背景图像和图像按钮周边之间有一个边框
  • Android 依赖项:apklib 与 aar 文件

    据我了解 apklib包含代码 共享资源Maven aar文件由以下人员分发Gradle The aar与 apklib 的主要区别在于 类被编译并包含在 aar 根目录下的classes jar 中 然而apklib不能包含已编译的类文件
  • UnsupportedOperationException:特权进程中不允许使用 WebView

    我在用android sharedUserId android uid system 在我的清单中获得一些不可避免的权利 从 HDMI 输入读取安卓盒子 http eweat manufacturer globalsources com s
  • 使用 eclipse 配置mockito 时出现问题。给出错误:java.lang.verifyError

    当我将我的mockito库添加到类路径中 并使用一个简单的mockito示例进行测试时 我尝试使用模拟对象为函数add返回错误的值 我得到java lang verifyerror 以下是用于测试的代码 后面是 logcat Test pu
  • Android 视图和视图组

    在安卓中ViewGroup继承自View A ViewGroup是一个容器 里面装有Views ViewGroup LinearLayout View TextView 为什么 Android 的人们将这种关系定义为Inheritance而
  • 在 TextView onTextChanged 上设置文本

    我有一个定义为类属性的文本视图 以便我可以在整个类中访问它 在 onCreate 方法中我执行以下操作 chars TextView findViewById R id chars chars setText 300 之后 public v
  • 使用 onAuthStateChanged 通过 Flutter 登录 Firebase

    在 Flutter 之外 当我实现 firebase 身份验证时 我总是使用 firebase 提供的 onAuthStateChanged 侦听器来确定用户是否登录并做出相应响应 我正在尝试使用 flutter 做类似的事情 但我可以找到
  • 如何用 XML 制作双渐变(类似 iphone)

    如何使用 XML 制作这种可绘制渐变 我可以做一个从颜色 A 到颜色 B 的简单渐变 但我不知道如何在同一个可绘制对象中组合两个渐变 我终于找到了一个带有图层列表的解决方案 这对我来说已经足够好了
  • Admob - 没有广告可显示

    你好 我尝试制作一些在 Android 手机上显示广告的示例程序 并尝试在 v2 2 的模拟器上测试它 代码中的一切似乎都很好 但调试器中的 AdListener 表示 响应消息为零或空 onFailedToReceiveAd 没有广告可显
  • 如何手动添加Android Studio依赖

    我多次尝试向我的项目添加依赖项 但每次都会出现错误 我想添加它们的依赖项是 de hdodenhof circleimageview 1 3 0 and com github bumptech glide glide 3 6 1 所以我想下

随机推荐

  • 如何使用JS和传单层控件更改基础层

    我必须修改现有的应用程序 其中使用传单图层控件 我需要在启动地图时显示基础图层之一 有没有办法 如何从 JS 脚本调用层控件中的某些函数 比如 control select 1 如果没有 如何以与控件相同的方式添加图块图层 当我在地图初始化
  • Three.js - 鱼眼效果

    所以 我搞砸了three js 效果很好 我唯一不明白的是如何制作具有真正鱼眼效果的相机 这怎么可能 camera setLens 鱼眼效果可以使用 Giliam de Carpentier 的镜头畸变着色器来实现 着色器代码 functi
  • 如何使用Excel VBA制作外部日志?

    代码已更新以引用以下更改 该日志系统为 Excel 创建一个名为 Log txt 的外部文档 它将在 log txt 文件中创建一行 如下所示 11 27 20 AM Matthew Ridge 将单元格 N 55 从 ss 更改为 这不会
  • JDK8 无法与 JDK8(WS 客户端)一起使用

    我有一个非常简单的 现有的 Web 服务 我想使用 JDK8 生成一个 Web 服务客户端 我使用的是纯 JDK8 工具链 这意味着我使用 JDK8 目录中的 wsimport 工具 现在问题来了 JDK8 中的 wsimport 工具生成
  • Angular2 异常没有字符串提供者

    我有一个使用 ng cli 创建的全新应用程序 用这个非常简单的代码 import Component from angular core Component selector app root templateUrl app compon
  • 替换字符串中字符的所有实例的最快方法[重复]

    这个问题在这里已经有答案了 在 JavaScript 中替换字符串中字符串 字符的所有实例的最快方法是什么 Awhile a for loop 正则表达式 最简单的方法是使用正则表达式g替换所有实例的标志 str replace foo g
  • 连接管理器 unregisterNetworkCallBack 已取消注册

    在我的 Android 应用程序中 我正在取消注册活动的网络回调 onPause 有时我会遇到错误 原因是 java lang IllegalArgumentException NetworkCallback was already unr
  • Django 中的 URL 路径参数与查询参数

    我已经环顾了一段时间 似乎找不到任何涉及差异的东西 正如标题所述 我试图找出通过 url 路径参数获取数据的区别 例如 content 7然后在 urls py 中使用正则表达式 并从查询参数中获取它们 例如 content num 7 u
  • ASP.NET -- IIS7 -- IBM DB2 问题

    我正在开发一个调用 DB2 数据库的 ASP NET 网站 我在将托管该站点的 Windows 2008 服务器上安装了 Visual Studio 当我使用集成 Web 服务器在 Visual Studio 中调试站点时 我可以连接到数据
  • 将 NSAttributedString 添加到 UIBarButtonItem

    我正在尝试在后栏按钮项目上设置属性字符串 这是我第一次尝试属性字符串 这是代码 self navigationItem hidesBackButton true let barButtonBackStr lt Back var attrib
  • 用作索引器键的打字稿文字类型

    有没有什么方法可以定义可以用作索引器中的字符串键的打字稿文字类型 type TColorKey dark light interface ColorMap period TColorKey Color 这会引发错误 An index sig
  • 在执行shell中获取Jenkins环境变量

    我想知道是否可以在配置构建中的执行 shell 内访问 Jenkins 环境变量 如果是这样 你能给我举个例子吗 我需要将环境信息与测试的一些输出结合起来 以提供完整的运行报告 不使用插件 Please check http yourjen
  • 使用 HTML5 和 JavaScript 从视频中捕获帧

    我想每 5 秒从视频中捕获一帧 这是我的 JavaScript 代码 video addEventListener loadeddata function var duration video duration var i 0 var in
  • 如何在猫鼬模型上使用partialFilterExpression

    我创建了一个带有电子邮件字段的猫鼬模型 如果用户提供了值 我希望它是唯一的 但如果用户未提供任何值 我希望它为空 我在这里找到了一个很好的 mongodb 参考 https docs mongodb com manual core inde
  • Python Pandas 动态创建 Dataframe

    下面的代码将生成所需的输出ONEdataframe 但是 我想在 FOR 循环中动态创建数据帧 然后将移位后的值分配给该数据帧 例如 数据帧 df lag 12 将仅包含column1 t12 和column2 12 任何想法将不胜感激 我
  • Android 蓝牙socket非阻塞通信教程

    我正在寻找 Android 上的蓝牙示例代码来进行非阻塞套接字通信 我找到了几个例子 例如BluetoothChat或BluetoothSocket java 但没有一个是non blocking socket communication
  • keybd_event KEYEVENTF_EXTENDEDKEY 需要解释

    In 文档它说 KEYEVENTF EXTENDEDKEY 0x0001 如果指定 则扫描码前面有一个值为 0xE0 224 的前缀字节 有人可以解释这是什么意思吗 这有什么区别 keybd event RIGHT 0 0 0 keybd
  • 确保 C# 中的多播委托执行列表顺序?

    经过一些阅读后 我了解到处理程序调用顺序与订阅顺序相同 但不能保证 所以可以说我有 public event MYDEl ev 订阅者会 ev GetPaper ev Print ev EjectPaper 保留 确保执行列表顺序的最佳实践
  • Android studio 3.0 无法上传仅测试的 apk

    我刚刚将我的旧项目更新为 as3 0 并构建并签署了我的应用程序 当我想上传到谷歌播放后 您不能上传仅测试 apk 有什么帮助吗 这是Android Studio 3 0的新功能 当您在 Android Studio 中按 运行 按钮执行任
  • 使用 flutter_local_notifications 和位置包时出现 flutter 错误“Android dependency 'androidx.core:core' has different version”

    美好的一天 我尝试制作一个带有 Android 和 ios 通知的简单天气应用程序 为此我使用基础 flutter 应用程序和库flutter local notifications 0 5 1 2 and location 2 0 0 但