【问题标题】:Resolved versions for app (26.1.0) and test app (27.1.1) differ应用程序 (26.1.0) 和测试应用程序 (27.1.1) 的已解决版本不同
【发布时间】:2018-10-11 17:25:49
【问题描述】:

这是完整的错误-

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.

我知道这种类型的答案有很多解决方案,但我是 android studio 的绝对初学者,我无法理解这些解决方案,例如与 gradle 交互的命令行界面等等......

如果有的话,我一直在寻找解决此问题的简单方法。 非常感谢!

【问题讨论】:

  • 请附上您的应用build.gradle

标签: android build.gradle


【解决方案1】:

更改构建 gradle 应用程序中的所有实现 例如。

  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.android.support:design:27.1.1'
  implementation 'com.android.support:support-annotations:27.1.1'

将其全部更改为最新版本(27.1.1)并同步项目。

【讨论】:

  • 在哪里进行这些更改?我应该在 build.gradle 文件中添加这些代码吗?
  • @Dev_123 在 build.gradle (Apps) 中并仅更改 version。这些代码来自我的项目,所以你不需要它们。您只需要更改版本,它应该可以工作。
【解决方案2】:

它只需要几个步骤... 1. 转到 module.app 文件。 2.更改目标sdk版本并将sdk版本编译为最新版本(这里是27) 3.然后将appcompact版本更改为27.1.1 4.同步gradle文件

【讨论】:

  • 您还必须编辑 appcompat 版本以针对最新版本,例如: implementation 'com.android.support:appcompat-v7:27.1.1'
【解决方案3】:

您的根 gradle 文件应包含:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

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

模块 gradle 文件应该包含如下库:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
}
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "your.package.name"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}


repositories {
    jcenter()
    mavenCentral()
    maven { url 'https://maven.google.com' } // necessary for Android API 26
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'

    implementation 'com.google.firebase:firebase-ads:15.0.0'

    implementation 'com.google.android.gms:play-services-location:15.0.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.0'
}

这只是典型的简单 gradle 配置示例。按需使用

【讨论】:

    【解决方案4】:
    configurations.all{
        resolutionStrategy {
            force 'com.android.support:support-annotations:26.1.0'
        }
    }
    

    【讨论】:

      【解决方案5】:

      这是真正让我反感 Android Studio 的错误类型。

      但无论如何,对我来说解决方案非常简单:编辑 app.iml 并更改 com.android.support:support-annotations 版本。在这种情况下很容易找到,只需 ctrl+F 并输入“27.1.1”(它应该是唯一的命中)并更改为您的版本“26.1.0”。

      换句话说,把它从

      <orderEntry type="library" scope="TEST" name="com.android.support:support-annotations:27.1.1@jar" level="project" />
      

      <orderEntry type="library" scope="TEST" name="com.android.support:support-annotations:26.1.0@jar" level="project" />
      

      然后,重建项目。 (在我编辑 app.iml 之前,只是重建它对我不起作用)

      【讨论】:

        【解决方案6】:

        转到 build.gradle(Module:app) 文件,将 compile 'com.android.support:support-annotations:27.1.1' 添加到依赖项中,然后再次单击“立即同步”。

        【讨论】:

          【解决方案7】:

          最近我再次收到此错误....我只是去构建->重建项目,它每次都对我有用。

          【讨论】:

          • 每次,当我点击“制作项目”时,它都会提示我同样的错误。有什么解决方法吗?
          【解决方案8】:

          在 gradle 文件中修改下面的行。

          //From 
          androidTestImplementation 'com.android.support.test:runner:1.0.2'
          androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
          //To
          androidTestImplementation 'com.android.support.test:runner:1.0.1'
          androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
          

          【讨论】:

            【解决方案9】:

            使用最新稳定版本的支持库

            在此处跟踪最新版本 https://mvnrepository.com/artifact/com.android.support

            截至 2018 年 9 月 28 日,最新版本为 28.0.0

              implementation 'com.android.support:appcompat-v7:28.0.0'
              implementation 'com.android.support:support-annotations:28.0.0'
            

            【讨论】:

              【解决方案10】:

              使用

              implementation 'com.android.support:appcompat-v7:27.1.1'

              而不是

              implementation 'com.android.support:appcompat-v7:26.1.1'

              并将 compileSdkVersion 26 更改为 27

              【讨论】:

                猜你喜欢
                • 2018-10-11
                • 1970-01-01
                • 2015-05-13
                • 1970-01-01
                • 2016-08-02
                • 2023-03-12
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多