【问题标题】:Android Studio - Gradle compilation failedAndroid Studio - Gradle 编译失败
【发布时间】:2018-07-21 16:37:53
【问题描述】:

我的编译由于某种原因失败了,但之前它工作得很好。

这是我在尝试编译项目时遇到的错误:

Program type already present: android.support.design.widget.CoordinatorLayout$Behavior
Message{kind=ERROR, text=Program type already present: android.support.design.widget.CoordinatorLayout$Behavior, sources=[Unknown source file], tool name=Optional.of(D8)}

(构建)app.iml:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "appjoe.wordpress.com.testdemo"
        minSdkVersion 23
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:26.1.0'
    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:design:26.1.0'

    // picasso and volley
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'eu.the4thfloor.volley:com.android.volley:2015.05.28'

    // retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    // rxjava & rxandroid
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.16'

    // glide
    implementation 'com.github.bumptech.glide:glide:4.7.1'

    // android views
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
}

我还收到了依赖项区域中第二个依赖项的错误:

所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 27.1.1、27.1.0、26.1.0。示例包括 com.android.support:support-compat:27.1.1 和 com.android.support:exifinterface:27.1.0 less... (Ctrl+1)

有些库或工具和库的组合不兼容,或者可能导致错误。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本进行编译(或者特别是低于您的 targetSdkVersion 的版本)。

【问题讨论】:

  • 把你的 glide 依赖改成这个 -- implementation 'com.github.bumptech.glide:glide:4.0.0'
  • 更改您的支持库版本 27.1.1 并更改 compile sdk 版本 27。
  • @RohitSuthar 谢谢,它成功了。我该如何结束这个问题?

标签: android android-gradle-plugin gradlew


【解决方案1】:

这是因为在依赖项中,某些库(支持库除外)使用的支持库版本与您的不同,这就是您收到此错误的原因。你有混合支持库依赖版本 26 和 27。

因此,您需要使用版本 27.1.1 的匹配支持库。将您的 build.gradle 更改为以下内容:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27 // use version 27
    defaultConfig {
        applicationId "appjoe.wordpress.com.testdemo"
        minSdkVersion 23
        targetSdkVersion 27 // targeting api version 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-v4:27.1.1'
    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:design:27.1.1'

    // picasso and volley
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'eu.the4thfloor.volley:com.android.volley:2015.05.28'

    // retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'

    // rxjava & rxandroid
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.16'

    // glide
    implementation 'com.github.bumptech.glide:glide:4.7.1'

    // android views
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
}

将您的库版本升级到新版本。只需将光标放在每个库上。 Android studio 会自己告诉你这个库有新版本可用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2018-08-05
    • 2021-08-29
    • 1970-01-01
    • 2016-05-18
    • 2020-10-16
    • 2023-04-09
    相关资源
    最近更新 更多