【问题标题】:Flutter Gradle failure cause by AndroidX incompatibilitiesAndroidX 不兼容导致 Flutter Gradle 失败
【发布时间】:2019-11-07 22:18:27
【问题描述】:

我只是将 firebase_messaging 添加到 pubspec.yaml 并运行应用程序。在那之后,我得到了一个错误,描述它可能是由于 AndroidX 不兼容而导致的 gradle 问题。这里似乎有什么问题,是 AndroidX 还是依赖项?谢谢

调试控制台

Launching lib/main.dart on LUNA V55 in debug mode...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.appcompat:appcompat' has different version for the compile (1.0.0) and runtime (1.0.2) 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 19s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See goo.gl/CP92wY for more information on the problem and how to fix it.
*******************************************************************************************
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

pubspec.yaml

name: flutter_notification
description: A new Flutter project.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  firebase_messaging: ^5.0.4
  http: ^0.12.0+2
  shared_preferences: ^0.5.3+1
  intl: ^0.15.8
  image_picker: ^0.6.0+9 
  share: ^0.6.1+1
  flutter_calendar: ^0.0.8
  swipedetector: ^1.2.0
  barcode_scan: ^1.0.0
  carousel_pro: ^0.0.13
  carousel_slider: ^1.3.0
  shimmer: ^1.0.0
  flutter_search_panel: ^1.0.1
  percent_indicator: ^2.1.0
  after_layout: ^1.0.7+1
  url_launcher: ^5.0.3
  table_calendar: ^1.2.2
  flutter_datetime_picker: ^1.2.1
  email_validator: '^1.0.0'
  dio: ^2.1.7
  path_provider: ^1.1.0
  flutter_html: ^0.10.1+hotfix.1

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

【问题讨论】:

  • 检查您的库...如果其中一些有 AndroidX 而另一些没有,则会引入类似这样的问题。遗憾的是,如果这是问题所在,您将无法修改库。有一个要避免的小部件列表,如果您要使用完整的 AndroidX,那么一切都应该是。
  • 在不提供具体版本的情况下尝试运行可能是低版本不依赖AndroidX。
  • 使用firebase_messaging: 2.1.0,而不是使用最新版本的firebase_messaging: 5.0.4,因为该软件包是在2.1.0版本之后迁移到AndroidX的。所以 2.1.0 以外的任何其他版本都需要 AndroidX

标签: flutter dart cross-platform


【解决方案1】:

转到C:\Users\Pcname\projectname\android 打开 gradle.properties 并添加这个

android.useAndroidX=true
android.enableJetifier=true

【讨论】:

    猜你喜欢
    • 2020-04-08
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 2021-07-10
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    相关资源
    最近更新 更多