FutterError:Androidx互換性の問題

実行は、タスクに失敗しました「:アプリ:preDebugBuild」。

Androidの依存関係「androidx.core:コアは、」別のコンパイルのバージョン(1.0.0)とランタイム(1.0.1)クラスパスを持っています。手動でDependencyResolutionを経由して、同じバージョンを設定する必要があります

Androidのコードでは、旧バージョンとの下位互換性を確保するためにAndroid.supportライブラリを使用しています。現在、ライブラリは保守サポートを停止し、AndroidXを交換した、AndroidXは、古いライブラリのいくつかの追加機能と機能を持っており、合格したいのですが、図書館の二組は互換性がありませんので、エラー。将来はAndroidXベース、Androidのサポートライブラリのためになり、もはや推奨されていない、とゆっくり維持しなくなります。また、Androidのメーカー3.4.2から始めて、新しいプロジェクトが使用AndroidXのアーキテクチャを確認することを余儀なくされました。

Launching lib/main.dart on Redmi Note 7 Pro in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) 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 6s
Finished with error: Gradle task assembleDebug failed with exit code 1

ソリューション

現在、2つの主要なオンラインソリューションは最初、使用AndroidXプラグインを避けるAndroidXを使用しないようにすることです、ありますが、明らかにこれは妥協の多くは、間違いない最善の方法を行います。もう一つは、大規模にはあまり適し得るいかなる成功、手動で、その後、非常に面倒でなく、エラーになりやすいが、存在しない理由を、時間によって、私が最初にAS知らない、実際には、ないだけでこのようにAndroidX、統合されています古いプロジェクト。
私の問題のために私は問題を解決することができますプロジェクトレベルのbuild.gradleファイルに次のコードブロックを追加し、解決策を見つけました

subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }
                if (details.requested.group == 'androidx.core'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.1"
                }
               }
            }
        }
    }

完全なコードbuild.gradle

buildscript {
    ext.kotlin_version = '1.3.0'
   repositories {
//        google()
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
       google()
   }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

    subprojects {
        project.configurations.all {
            resolutionStrategy.eachDependency { details ->
                if (details.requested.group == 'com.android.support'
                        && !details.requested.name.contains('multidex') ) {
                    details.useVersion "27.1.1"
                }
                if (details.requested.group == 'androidx.core'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.2"
                }
                if (details.requested.group == 'androidx.appcompat'
                        && !details.requested.name.contains('androidx') ) {
                    details.useVersion "1.0.2"
                }
            }
        }
    }
}

allprojects {
    repositories {
//        google()
//        jcenter()
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }
}

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

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

公開された24元の記事 ウォンの賞賛5 ビュー3942

おすすめ

転載: blog.csdn.net/qq_41345281/article/details/102630710