Android Flutter AndroidX incompatibilities报错处理

报错信息:The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app

原因:AndroidX 不兼容

解决方案:

AndroidStudio中提示网址  https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

  1. In android/gradle/wrapper/gradle-wrapper.properties change the line starting with distributionUrl like this:

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
    
  2. In android/build.gradle, replace:

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
    

    by

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
    }
    
  3. In android/gradle.properties, append

    android.enableJetifier=true
    android.useAndroidX=true
    
  4. In android/app/build.gradle:

    Under android {, make sure compileSdkVersion and targetSdkVersion are at least 28.

  5. Replace all deprecated libraries with the AndroidX equivalents. For instance, if you’re using the default .gradle files make the following changes:

    In android/app/build.gradle

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    by

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    

     

  6. Finally, under dependencies {, replace

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    

    by

    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    

Avoiding AndroidX

If you want or need to avoid migrating to AndroidX, you’ll need to pin your plugin dependencies in your pubspec.yaml to the last major version from before they were migrated.

These are the last available versions of all the flutter/plugins packages that are pre AndroidX:

  • android_alarm_manager: 0.2.3
  • android_intent: 0.2.1
  • battery: 0.3.0
  • camera: 0.2.9+1
  • cloud_firestore: 0.8.2+3
  • cloud_functions: 0.0.5
  • connectivity: 0.3.2
  • device_info: 0.3.0
  • firebase_admob: 0.7.0
  • firebase_analytics: 1.1.0
  • firebase_auth: 0.7.0
  • firebase_core: 0.2.5+1
  • firebase_database: 1.0.5
  • firebase_dynamic_links: 0.1.1
  • firebase_messaging: 2.1.0
  • firebase_ml_vision: 0.2.1
  • firebase_performance: 0.0.8+1
  • firebase_remote_config: 0.0.6+1
  • firebase_storage: 1.0.4
  • google_maps_flutter: 0.1.0
  • google_sign_in: 3.2.4
  • image_picker: 0.4.12+1
  • local_auth: 0.3.1
  • package_info: 0.3.2+1
  • path_provider: 0.4.1
  • quick_actions: 0.2.2
  • sensors: 0.3.5
  • share: 0.5.3
  • shared_preferences: 0.4.3
  • url_launcher: 4.1.0+1
  • video_player: 0.9.0
  • webview_flutter: 0.2.0

Note that this is not an exhaustive list of all Flutter plugins that use AndroidX, and the AndroidX dependency in your app might be coming from another plugin besides these.

 

修改后,仍然报错:根据提示查得 android / build.gradle 中 ext.kotlin_version不能低于 1.3.0

所以解决办法:

buildscript {
    ext.kotlin_version = '1.3.0'

将版本更改为1.3.0,再次运行程序运行成功

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值