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

Ank*_*hta 127 android kotlin dagger-2 android-coordinatorlayout

我在构建项目时遇到以下错误.在这个项目中没有使用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/dexBuilder/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"
}
Run Code Online (Sandbox Code Playgroud)

非常感谢帮助.谢谢 :)

Ank*_*hta 214

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

implementation 'com.android.support:appcompat-v7:27.0.2'
Run Code Online (Sandbox Code Playgroud)

以前是

implementation 'com.android.support:appcompat-v7:27.1.0'
Run Code Online (Sandbox Code Playgroud)

要么

此外,只需 版本27.1.0或更高版本的支持设计依赖添加到您的应用程序级别即可解决此问题build.gradle,如下所示:

implementation 'com.android.support:design:27.1.0'
Run Code Online (Sandbox Code Playgroud)

  • 一旦他们发布新版本,他们就会因为奇怪的错误而让我们发疯.:| (43认同)
  • 在新版本中将其更改为`compile'c​​om.android.support:design:27.1.0'` (2认同)

小智 77

我遇到了同样的问题,我在应用程序级别添加了android支持设计依赖项 build.gradle

添加以下:

implementation 'com.android.support:design:27.1.0'
Run Code Online (Sandbox Code Playgroud)

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

  • 为我工作。在应用程序仍在使用26.xx的库开始使用27.1.0后,发生了此问题 (2认同)

Kis*_*nki 31

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

它是

implementation 'com.github.bumptech.glide:glide:4.7.1'
Run Code Online (Sandbox Code Playgroud)

所以我补充exclude group: "com.android.support"说它变成了

implementation ('com.github.bumptech.glide:glide:4.7.1') {
        exclude group: "com.android.support"
    }
Run Code Online (Sandbox Code Playgroud)


小智 13

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

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
Run Code Online (Sandbox Code Playgroud)

我认为应该解决问题


LOG*_*TAG 12

使用最新的supportLibrary版本27.1.1来解决问题.为我工作.(包括许多错误修复 - 请参阅changelog)


小智 9

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

implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
Run Code Online (Sandbox Code Playgroud)

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


Dev*_*ven 6

使用

implementation 'com.android.support:appcompat-v7:27.1.1'
Run Code Online (Sandbox Code Playgroud)

不要使用喜欢

implementation 'com.android.support:appcompat-v7:27.+'
Run Code Online (Sandbox Code Playgroud)

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

或事件不这样做

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1' 
Run Code Online (Sandbox Code Playgroud)

等...库的数量然后

implementation 'com.android.support:appcompat-v7:27.+'
Run Code Online (Sandbox Code Playgroud)

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


小智 6

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

在gradle中添加以下内容 implementation 'com.android.support:design:27.1.1'


Kes*_*era 5

我降级了支持

previously it was
implementation 'com.android.support:appcompat-v7:27.0.2'
Run Code Online (Sandbox Code Playgroud)

用它

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

implementation 'com.android.support:design:27.1.0'
Run Code Online (Sandbox Code Playgroud)

其工作愉快的编码

  • 从27.0.2升级到27.1.0似乎更像是升级 (5认同)