【问题标题】:How to fix AndroidX compatibility for Flutter in Android Studio?如何在 Android Studio 中修复 Flutter 的 AndroidX 兼容性?
【发布时间】:2019-08-13 14:41:10
【问题描述】:

我在尝试flutter build apk 时遇到此错误:

*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.
*******************************************************************************************
Gradle task assembleRelease failed with exit code 1

但我可以让我的代码直接在手机或模拟器上运行... 我已经使用该项目创建了 APK 文件(并将其发送到商店)。最后一个 APK 创建于 2019/07/17。从那以后,我只在列表中添加了一些数据。

我已经尝试在与上次相同的条件下编译:

  • flutter clean等;
  • 使缓存失效;
  • 降级 Flutter 版本;
  • 降级 Kotlin 版本;
  • 降级 Gradle 版本;
  • 降级 Gradle-wrapper 的分发 URL。

这是我的依赖项:

dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: any
  firebase_auth: any
  google_sign_in: ^3.2.4
  flutter_datetime_picker: 1.0.7
  numberpicker: any
  flutter_svg: any
  dio: any
  path_provider: any
  firebase_messaging: any
  charts_flutter: any
  barcode_scan: 1.0.0
  unity_ads_flutter: any
  progress_indicators:

Gradle 文件:

buildscript {
    ext.kotlin_version = '1.3.31'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.2'
        classpath 'com.google.gms:google-services:4.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.firebase:firebase-core:17.0.1'
    implementation 'com.google.firebase:firebase-auth:18.1.0'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

[编辑] 我换了电脑。可能是问题原因?

[编辑 2] 已解决

步骤:

  • 升级包
dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: any
  firebase_auth: any
  google_sign_in: any
  flutter_datetime_picker: 1.0.7
  numberpicker: any
  flutter_svg: any
  dio: any
  path_provider: any
  firebase_messaging: any
  charts_flutter: any
  barcode_scan: 1.0.0
  unity_ads_flutter: any
  progress_indicators:
  • 复制新项目中的所有文件

在向我的新计算机传输过程中,某些文件似乎已损坏或丢失

【问题讨论】:

  • “失败可能是因为..”。您应该通过使用--info 运行任务来找到实际的 Gradle 错误。
  • @F-1 :我按照指南并在 AndroidX 的网站上查找了我需要的最新版本的实现。
  • @creativecreatorormaybenot :没有显示任何问题。只有自动替换过时调用的警告
  • @BarracudApps 执行flutter build 时不显示Gradle 错误。您将不得不手动调试失败的 Gradle 任务。如果你不明白我的意思,应该有足够的信息。

标签: android android-studio flutter compilation androidx


【解决方案1】:

在网上大量阅读github y 发现每个人都通过升级库来解决这个问题。我发现 google_sign_in 有很多最新版本,因此请尝试将 google_sign_in 升级到 4.0.6

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,经过一周的搜索和混合我找到的一些答案,这是最终奏效的答案

    按照以下指南进行操作:https://pub.dev/packages/barcode_scan 但是做这个修改:

    编辑您的项目级 build.gradle 文件,如下所示:

    buildscript {
        ext.kotlin_version = '1.3.30'
        ...
        dependencies {
            ...
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    ...
    

    编辑您的应用级 build.gradle 文件,使其如下所示:

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    ...
    
    dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    ...
    }
    

    如果您在编译应用程序时说明了 androidx appcompat 1.0.0 和 1.0.2 之间的差异 转到您的插件 build.gradle 文件并更改依赖项

    dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.0'
    ...
    }
    

    【讨论】:

    • 我只是按照您的建议尝试降级 Kotlin 版本,但没有任何改变。我似乎问题来自 google_sign_in
    • 我有这个问题是当我添加到我的颤振项目位置插件并将核心升级到颤振 1.5.4 时。但可以通过这些步骤修复它。
    【解决方案3】:

    用这个更新你的 gradle.properties 文件:

    android.enableJetifier=true
    android.useAndroidX=true
    org.gradle.jvmargs=-Xmx1536M
    

    【讨论】:

    • 尝试使用固定的插件分辨率...有些插件是 AndroidX 之前的: • cloud_firestore:0.8.2+3 • firebase_auth:0.7.0 • google_sign_in:3.2.4 • path_provider : 0.4.1 • firebase_messaging: 2.1.0 可能使用“任何”您正在解析不使用 AndroidX 的插件版本
    • 从文档看这里:[link] (flutter.dev/docs/development/packages-and-plugins/…) “AndroidX 可以在编译时以两种方式破坏 Flutter 应用程序:* 该应用程序使用 AndroidX 插件及其主要 build.gradle 文件有一个低于 28 版的 compileSdkVersion。 * 该应用同时使用已弃用的代码和 AndroidX 代码。必须通过手动将代码迁移到同一库或降级到仍使用原始支持的插件版本来解决这些问题图书馆”
    • 固定版本没有任何变化。从现在开始,我对any 包没有任何问题
    猜你喜欢
    • 2019-10-25
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 2019-07-17
    • 2018-11-24
    • 2020-01-25
    • 2019-10-22
    相关资源
    最近更新 更多