错误:程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior

问题描述 投票:112回答:21

我在构建项目时遇到以下错误。在这个项目中没有使用CoordinatorLayout。刚刚在build.gradle中添加为依赖项:

我使用的是Android Studio 3.2 Canary 4。

logcat的

AGPBI:{“kind”:“error”,“text”:“程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior”,“sources”:[{}],“tool”:“D8” }:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED FAILURE:构建因异常而失败。 *出了什么问题:任务执行失败':app:transformDexArchiveWithExternalLibsDexMergerForDebug'。

com.android.builder.dexing.DexArchiveMergerException:合并dex存档时出错:/windows/Other/app/build/intermediates/transforms/dexBuilder/debug/0.jar,/ windows / Other / app / build / intermediates / transforms / dexBuilder / debug / 1.jar,/windows/Other/app/build/intermediates/transforms/dexBuilder/debug/4.jar,。 。 ...................

/Windows/other/app/build/intermediates/transforms/德行builder/debug/294.jar

程序类型已存在:android.support.design.widget.CoordinatorLayout $ Behavior

的build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.dagkot"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "BASE_URL", "\"http://api.openweathermap.org/data/2.5/\""
            buildConfigField "String", "API_KEY", "\"435e9075f348868c2714fe7c6895efa5\""
        }
        debug {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField "String", "BASE_URL", "\"http://api.openweathermap.org/data/2.5/\""
        buildConfigField "String", "API_KEY", "\"xxxx\""
    }
}
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"


    // Dagger dependencies
    compileOnly 'org.glassfish:javax.annotation:10.0-b28'
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"

    //Butterknife dependencies
    implementation 'com.jakewharton:butterknife:8.8.1'
    kapt 'com.jakewharton:butterknife-compiler:8.8.1'

    // Architecture Components Dependencies
    kapt "android.arch.lifecycle:compiler:$rootProject.lifeCycle"
    implementation "android.arch.lifecycle:extensions:$rootProject.lifeCycle"
    implementation "android.arch.lifecycle:reactivestreams:$rootProject.lifeCycle"
    implementation "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"

    // Retrofit/RxJava Dependencies
    implementation "com.squareup.retrofit2:retrofit:$rootProject.retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$rootProject.retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$rootProject.retrofitVersion"
    implementation "io.reactivex.rxjava2:rxandroid:$rootProject.rxAndroidVersion"
    implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'
    implementation 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.1.1'

    // GSON
    implementation "com.google.code.gson:gson:$rootProject.gsonVersion"

    // Rx Location Manager
    implementation 'io.nlopez.smartlocation:library:3.3.3'
    implementation 'io.nlopez.smartlocation:rx:3.3.1'

    //Anko Dependencies
    implementation "org.jetbrains.anko:anko-commons:$rootProject.anko_version"
    implementation "org.jetbrains.anko:anko-design:$rootProject.anko_version"
    implementation 'com.android.support:design:27.0.2'

    implementation("com.github.hotchemi:permissionsdispatcher:3.1.0") {
        // if you don't use android.app.Fragment you can exclude support for them
        exclude module: "support-v13"
    }
    kapt "com.github.hotchemi:permissionsdispatcher-processor:3.1.0"
}
android kotlin dagger-2 android-coordinatorlayout
21个回答
212
投票

当我降级支持qazxsw poi gradle依赖时,它起作用,如下所示:

appcompat

以前是

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

要么

此外,只需将版本27.1.0或更高版本的支持设计依赖项添加到您的应用程序级别implementation 'com.android.support:appcompat-v7:27.1.0' 即可解决此问题,如下所示:

build.gradle

3
投票

Important Update

implementation 'com.android.support:appcompat-v7:27.1.0' implementation 'com.android.support:design:27.1.0' 之后不会更新Android支持库。根据28.0.0 -

这将是android.support包装下的最后一个功能版本,鼓励开发人员使用Support Library Release Notes

因此,请使用migrate to AndroidX 1.0.0支持库。在您的案例中,设计库现在可以在材料包中找到。

AndroidX

我已将最新版本置于依赖关系中,您可以在此处阅读dependencies { implementation 'com.google.android.material:material:1.0.0' // instead of design implementation 'androidx.appcompat:appcompat:1.0.2' // instead of support-v7 }

有用的帖子:

  1. check latest version
  2. AndroidX introduction & integration
  3. Learn about Jetifier (engine behind AndroidX migration)

2
投票

我也有这个问题;我以这种方式解决了这个问题:

Some Do's and Dont's

小心我的最小SDk是26,你必须改变它与你的!


2
投票

我知道这是一个迟到的答案,但我有同样的问题,我的解决方案只是添加configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '26.0.1' } } } } 或任何以上支持设计库!


1
投票

由于android最新更新不支持'compile'关键字,因此在模块build.gradle文件中使用'implementation'。

并使用+符号在build.gradle中彻底检查依赖关系。

implementation 'com.android.support:design:28.0.0

如果有这样的依赖项,只需使用特定版本更新它们。之后:

  1. 同步gradle。
  2. 清理您的项目。
  3. 重建项目。

1
投票

解决方案是删除以下依赖项:

implementation 'com.android.support:support-v4:28.+'

将一般依赖关系放在:

implementation 'com.android.support:design:26.1.0'

1
投票

您的构建脚本应与应用程序build.gradle依赖项匹配。

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-compat:26.1.0'
    implementation 'com.android.support:multidex:1.0.3'    
    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.facebook.android:audience-network-sdk:4.99.1'
}

如果要降级依赖项,则还要降级supportLibVersion和buildToolsVersion。


0
投票

如果此处提到的任何答案不起作用,请转到文件>无效捕获/重新启动


0
投票

ext { buildToolsVersion = "27.0.3" minSdkVersion = 16 compileSdkVersion = 27 targetSdkVersion = 26 supportLibVersion = "27.1.1" } dependencies { ................. ................... implementation 'com.android.support:support-v4:27.1.0' implementation 'com.android.support:design:27.1.0' ................ ........... } 从1.1.0更新到1.1.3之后我收到此错误。也许值得一试。


0
投票

将此添加到项目的com.android.support.constraint:constraint-layout为我们修复它:

gradle.properties

0
投票

“程序类型已存在”删除/ build目录内容,它与生成的二进制文件有一些Dex(?)问题。得到与你一样的答案,他们帮助解决了这个问题,但创造了许多其他问题。构建内容删除适用于所有人。


75
投票

我遇到了同样的问题,我在应用程序级别implementation 'com.android.support:design:27.1.0' 中添加了android支持设计依赖项

添加以下:

build.gradle

在build.gradle中。现在它为我工作。


0
投票

我也面临同样的问题。但后来我意识到我使用支持库的版本并不相同。

一旦我做了同样的事,错误消失了。

在你的情况下

android.enableJetifier=true
android.useAndroidX=true

不一样,所以你只是将appcompat降级为

implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.0.2'

因此,你的问题解决了。

但如果您可以将支持设计版本升级到,那么您也可以解决

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

-2
投票

将所有依赖项更改为编译而不是实现,然后我重建项目而没有错误。然后我切换回实现而不是将其作为编译。


30
投票

这可能是图书馆的原因,我因为Glide而面对它。

它是

implementation 'com.android.support:design:27.1.0'

所以我添加了implementation 'com.github.bumptech.glide:glide:4.7.1' 它变成了

exclude group: "com.android.support"

13
投票

确保这两个版本在您的应用级build.gradle文件中是相同的版本

implementation ('com.github.bumptech.glide:glide:4.7.1') {
        exclude group: "com.android.support"
    }

我认为应该解决问题


12
投票

使用最新的 implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' ,版本supportLibrary来解决问题。为我工作。 (包括许多错误修复 - 27.1.1


9
投票

就个人而言,我将以下行添加到我的app / build.gradle:

see changelog

使用这种语法,版本是动态的。


6
投票

我正在使用android studio 3.0,我将设计模式依赖从26.0.1升级到27.1.1,现在错误消失了。

在gradle implementation "com.android.support:design:${rootProject.ext.supportLibVersion}" 中添加以下内容


5
投票

使用

implementation 'com.android.support:design:27.1.1'

不要使用喜欢

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

它可能会给您一个错误,不要使用比这更旧的版本。

或事件不这样做

implementation 'com.android.support:appcompat-v7:27.+'

等...库的数量然后

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

相同的库,但它有不同的版本,它可以给你一个错误。


4
投票

我降级了支持

implementation 'com.android.support:appcompat-v7:27.+'

用它

previously it was
implementation 'com.android.support:appcompat-v7:27.0.2'

它工作愉快的编码

© www.soinside.com 2019 - 2024. All rights reserved.