【问题标题】:Flutter how to solve AndroidX incompatibilityFlutter如何解决AndroidX不兼容问题
【发布时间】:2021-06-24 17:57:30
【问题描述】:

当我在 Flutter 项目中安装 geolocator 包时,我收到第一张图片中的错误。当我将 minSdkVerison 值设置为 21 时,错误发生了变化,我得到了第二个错误。但我猜第二个错误与 geolocator 无关,因为如果我卸载 geolocator 包,当 minSdkVersion 为 21 时我会收到该错误。我尝试 flutter clean 并将 multiDexEnabled 设置为 true 但它没有修复。我该如何解决这个问题?

minsdk16

minsdk21

应用级 build.gradle

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 plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_biasansor"
        multiDexEnabled true
        minSdkVersion 21
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:26.7.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'androidx.multidex:multidex: 2.0.1'




}

项目级 build.gradle

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

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.5'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle.properties

android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
android.enableDexingArtifactTransform=false

【问题讨论】:

    标签: android flutter flutter-packages


    【解决方案1】:

    您使用的是哪个版本的 Firestore? 将 SDK 设置为 21 并保持 multidex 不变,版本 21 处理它。根据您的无效安全状态使用最新版本的地理定位器和 Firestore。

    【讨论】:

    • cupertino_icons: ^0.1.3 provider: ^5.0.0 pedantic: ^1.11.0 firebase_auth: ^1.0.1 google_sign_in: ^5.0.0 get_it: ^6.0.0 flutter_facebook_login: ^3.0.0 firebase_core: ^1.0.1 cloud_firestore: ^1.0.3 clippy_flutter: ^1.1.1 我已经在使用最新版本的 firestore 但它仍然无法工作我删除了地理定位器但仍然出现第二个错误
    • 你得到什么错误?只需将其设置为 minSDK 21,并按原样返回您的 multidex 和其他参数。如果您保持 multiDex 选项默认,您将不会收到错误消息。 v21 sdk的图片中的错误说找不到multidex2.0.1,这意味着它可能已被更改。设置multidex为false,target SDK为29,minSDK 21,看看是否有效
    • multiDex 从一开始就是正确的,我只将 minSDK 值 16 更改为 21。我得到了那个错误`出了什么问题:无法确定任务':app:compileDebugJavaWithJavac'的依赖关系。 > 无法解析配置 ':app:debugCompileClasspath' 的所有任务依赖关系。 > 找不到 androidx.multidex:multidex: 2.0.1。 ....`
    • 如果我将 minsdk 21 更改为 16 并删除地理定位器,那么我的程序运行没有错误。但是在 minsdk 16 中,如果我添加地理定位器包,我会在 minsdk16 的图片中得到错误。当我将 minsdk16 更改为 21 时,我在图片 minsdk21 中出现错误。
    • 在所有这些错误之前,当我将 minsdk 设置为 21 时,我得到了这个错误。[!] Flutter tried to create the file android\settings_aar.gradle, but failed. To manually update settings.gradle , follow these steps: 1. Copy settings.gradle as settings_aar.gradle 2. Remove the following code from settings_aar.gradle: 当我按照颤振说的时候,这个问题得到了解决。这些错误之间是否存在关联?
    猜你喜欢
    • 2019-10-25
    • 2014-05-28
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    相关资源
    最近更新 更多