如何在Android Studio中修复Flutter的AndroidX兼容性?

时间:2019-08-13 14:41:10

标签: android android-studio flutter compilation androidx

尝试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:
  • 将所有文件复制到新项目中

在传输到我的新计算机期间,某些文件似乎已损坏或丢失

3 个答案:

答案 0 :(得分: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'
...
}

答案 1 :(得分:1)

使用以下命令更新gradle.properties文件:

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

答案 2 :(得分:1)

在互联网上大量阅读github,大家可以通过升级库解决此问题。我发现google_sign_in的最新版本很多,因此请尝试将google_sign_in升级到4.0.6