【问题标题】:Android dependency 'com.android.support:support-v4' has different versionAndroid 依赖 'com.android.support:support-v4' 有不同的版本
【发布时间】:2018-09-30 17:27:36
【问题描述】:

我刚刚升级到 Dart 2 和最新版本的 Flutter,现在我无法构建我的应用程序。我在互联网上环顾四周,但仍然不明白为什么会发生这种情况。

我得到的错误是:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.android.support:support-v4' has different version for the compile (26.1.0) and runtime (27.1.0) classpath. You should manually set the same version via DependencyResolution

项目构建等级:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

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
}

pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  google_sign_in: ^3.0.2
  firebase_auth: ^0.5.5
  firebase_database: ^0.4.5
  firebase_core: ^0.2.3

  flutter_blue: ^0.3.3

dev_dependencies:
  flutter_test:
    sdk: flutter


# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

我已将我的包更新到最新版本,并且正在运行最新版本的 Dart 和 Flutter。

我真的不明白是什么导致了这个错误。

有人可以帮忙吗?

【问题讨论】:

标签: android firebase dart flutter


【解决方案1】:

将以下内容添加到 Android 项目级别 build.gradle 文件的“子项目”部分(在评论中 Günter Zöchbauer 提供的 link 中也提到过):

   subprojects {

    project.evaluationDependsOn(':app')
//[PART TO ADD START]
    project.configurations.all {

        resolutionStrategy.eachDependency { details ->

            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.0"
            }
        }
    }
//[PART TO ADD END]
    }

【讨论】:

  • 为此损失了半天!!!!!!!正准备打自己!!!你拯救了这一天。感谢所有得到这个的人。
  • 这对我也有帮助!
【解决方案2】:

我在 Flutter 中制作“QR 扫描仪应用程序”时遇到了同样的问题,我刚刚更改了 demoapp->android 中的“minSdkVersion 21” ->app->build.gradle->minSdkVersion,效果很好。 发生这种情况是因为 Flutter 中的某些依赖项不支持低于 21 的 minSdk。

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

【讨论】:

    【解决方案3】:

    打开您的项目级别 build.gradle 文件并添加以下 sn-p。

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

    添加后,您的项目级 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"
                }
            }
        }
    }
    

    Günter Zöchbauer 提供的解决方案。 link。这个对我有用。希望对您有所帮助。

    【讨论】:

      【解决方案4】:

      试试这个 在 android studio 中打开您的项目,然后等待使其同步,然后

      更新 build.gradile 到这个 在构建脚本下添加 google() in repositories 使其看起来像这样

      repositories {
              jcenter()
              google()
          }
      update classpath
      classpath 'com.android.tools.build:gradle:3.1.1'
      Update distributionUrl in gradle-wrapper.properties
      distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
      
      implementation "com.android.support:support-v4:27.1.1"  // In case your targetting. 
      

      【讨论】:

      • 能否请您格式化您的答案,以明确哪些部分是文本,哪些是代码?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-10
      • 2018-11-20
      • 2019-04-07
      • 1970-01-01
      • 2023-03-16
      • 2019-03-17
      • 1970-01-01
      相关资源
      最近更新 更多