Flutter: 'com.android.support:appcompat-v7' 具有不同版本的编译(26.1.0)和运行时(27.0.1)类路径

创建于 2018-01-10  ·  19评论  ·  资料来源: flutter/flutter

我在运行 flutter run 时收到错误消息

flutter run
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...                                0.7s
Resolving dependencies...                             0.9s
Running 'gradlew assembleDebug'...                        
Configuration 'debugCompile' in project ':app' is deprecated. Use 'debugImplementation' instead.
Configuration 'profileCompile' in project ':app' is deprecated. Use 'profileImplementation' instead.
Configuration 'releaseCompile' in project ':app' is deprecated. Use 'releaseImplementation' instead.
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
Configuration 'debugProvided' in project ':apn_fb_login' is deprecated. Use 'debugCompileOnly' instead.
Configuration 'releaseProvided' in project ':apn_fb_login' is deprecated. Use 'releaseCompileOnly' instead.
Configuration 'debugProvided' in project ':firebase_messaging' is deprecated. Use 'debugCompileOnly' instead.
Configuration 'releaseProvided' in project ':firebase_messaging' is deprecated. Use 'releaseCompileOnly' instead.
Configuration 'debugProvided' in project ':google_sign_in' is deprecated. Use 'debugCompileOnly' instead.
Configuration 'releaseProvided' in project ':google_sign_in' is deprecated. Use 'releaseCompileOnly' instead.
Configuration 'debugProvided' in project ':image_picker' is deprecated. Use 'debugCompileOnly' instead.
Configuration 'releaseProvided' in project ':image_picker' is deprecated. Use 'releaseCompileOnly' instead.
Configuration 'debugProvided' in project ':share' is deprecated. Use 'debugCompileOnly' instead.
Configuration 'releaseProvided' in project ':share' is deprecated. Use 'releaseCompileOnly' instead.
Configuration 'debugProvided' in project ':shared_preferences' is deprecated. Use 'debugCompileOnly' instead.
Configuration 'releaseProvided' in project ':shared_preferences' is deprecated. Use 'releaseCompileOnly' instead.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.android.support:appcompat-v7' has different version for the compile (26.1.0) and runtime (27.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.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
Gradle build failed: 1

我的 gradle.build 文件是:

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withInputStream { stream ->
        localProperties.load(stream)
    }
}

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.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.3'

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.shuttertop.app"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

apply plugin: 'com.google.gms.google-services'

颤振医生:

[✓] Flutter (on Linux, locale en_US.UTF-8, channel alpha)
    • Flutter at /home/luca/Programs/flutter
    • Framework revision 8f65fec5f5 (4 weeks ago), 2017-12-12 09:50:14 -0800
    • Engine revision edaecdc8b8
    • Tools Dart version 1.25.0-dev.11.0
    • Engine Dart version 2.0.0-edge.d8ae797298c3a6cf8dc9f4558707bd2672224d3e

[✓] Android toolchain - develop for Android devices (Android SDK 26.0.3)
    • Android SDK at /home/luca/Android/Sdk
    • Android NDK at /home/luca/Android/Sdk/ndk-bundle
    • Platform android-26, build-tools 26.0.3
    • ANDROID_HOME = /home/luca/Android/Sdk
    • Java binary at: /home/luca/Programs/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[✓] Android Studio (version 3.0)
    • Android Studio at /home/luca/Programs/android-studio
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-915-b01)

[✓] Connected devices
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.0.0 (API 26) (emulator)

最有用的评论

是这样的

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }
    }
}

所有19条评论

我通过添加解决了

resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }

到 android/build.gradle 文件中的子项目部分

我有完全一样的问题。 你能发布你的整个代码吗? 我很难将您的解决方案添加到正确的 build.gradle 文件中。

谢谢

是这样的

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}
subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }
    }
}

这对我有用。谢谢。
虽然我不明白它的作用。请您简要解释一下它的功能吗?

对不起,我不记得为什么会发生这种情况,我认为当您将项目从旧版本(例如 2.0.1)迁移到最新版本(例如 3.0.1)时,您需要确保您有下载了适当的依赖项。

检查此以获取更多信息。 https://stackoverflow.com/questions/47448502/could-not-resolve-com-android-supportappcompat-v726-1-0-in-android-studio-new

我对颤振 map_view 插件有同样的问题,添加

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

到 android/build.gradle 结束,它解决了这个问题。
谢谢@lalukz

想象一下当我们迁移到 android jetpack androidx 包时的麻烦

工作,
我在同时使用 clodfirestore 和 firebase 消息传递 plgin 时遇到了错误,现在通过添加上述行而消失了
还在应用级 gradle 文件中添加以下行

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true 

同样的错误,但反对

> Android dependency 'com.android.support:support-v4' has different version for the compile (27.0.1) and runtime (27.1.1) classpath. You should manually set the same version via DependencyResolution

添加了这个来解决。

        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.0.1"
            }
        }

当我这样做时,我的应用程序编译,但它在应用程序启动时崩溃,日志中没有错误

我也做了 27.1.0 修复,它在应用程序启动时崩溃。

有没有什么办法可以解决这个问题而不用货物培养?

我能够以不同的方式解决这个问题。 也许它对一些仍然遇到困难的人有用@dannnnthemannnn

android/app/build.gradle添加这一行:
implementation "com.android.support:support-v4:27.1.1"

所以它现在看起来像:

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation "com.android.support:support-v4:27.1.1" // added this
}

来自react-community 上的帖子

当我添加如下

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

该解决方案工作正常。

我对颤振 map_view 插件有同样的问题,添加

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

到 android/build.gradle 结束,它解决了这个问题。
谢谢@lalukz

谢谢它对我有用

我能够以不同的方式解决这个问题。 也许它对一些仍然遇到困难的人有用@dannnnthemannnn

android/app/build.gradle添加这一行:
implementation "com.android.support:support-v4:27.1.1"

所以它现在看起来像:

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation "com.android.support:support-v4:27.1.1" // added this
}

来自react-community 上的帖子

只有这个解决方案适用于我的情况。 更改 android/build.gradle 的那个不起作用。

我也有同样的问题并通过添加解决了

子项目{
project.configurations.all {
resolutionStrategy.eachDependency { 详细信息 ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}
}

在 android/build.gradle 文件的末尾

我也有同样的问题并通过添加解决了

子项目{
project.configurations.all {
resolutionStrategy.eachDependency { 详细信息 ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}
}

在 android/build.gradle 文件的末尾

这个解决方案适用于我的情况。

此页面是否有帮助?
0 / 5 - 0 等级