代码之家  ›  专栏  ›  技术社区  ›  Ankit Mehta

错误:程序类型已存在:android。支持设计小部件。CoordinatorLayout$行为

  •  130
  • Ankit Mehta  · 技术社区  · 7 年前

    我在构建项目时遇到以下错误。在此项目中未使用CoordinatorLayout。刚在构建中添加为依赖项。格拉德尔:

    我正在使用Android Studio 3.2 Canary 4。

    LogCat公司

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

    通用域名格式。安卓建设者德兴。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。罐子 。 。 。。。。。。。。。。。。。。。。。。。

    /windows/Other/app/build/intermediates/transforms/dexBuilder/debug/294。罐子

    程序类型已存在:android。支持设计小部件。CoordinatorLayout$行为

    建筑格拉德尔

    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"
    }
    
    22 回复  |  直到 5 年前
        1
  •  214
  •   Ankit Mehta    6 年前

    当我降低支持级别时,它起作用了 appcompat 渐变依赖,如下所示:

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

    以前是

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

    也可以通过以下方式解决此问题 添加支持设计依赖项 版本27.1.0或更高版本到您的应用程序级别 build.gradle 如下所示:

    implementation 'com.android.support:design:27.1.0'
    
        2
  •  78
  •   daniu    6 年前

    我也面临同样的问题, 我将android支持设计依赖项添加到应用程序级别 build.gradle

    添加以下内容:

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

    内置。格拉德尔。现在对我有用了。

        3
  •  32
  •   Kishan Solanki    6 年前

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

    是的

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

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

    implementation ('com.github.bumptech.glide:glide:4.7.1') {
            exclude group: "com.android.support"
        }
    
        4
  •  14
  •   James Idowu    6 年前

    确保这两个版本在应用程序级构建中是相同的。gradle文件

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

    我认为这应该解决问题

        5
  •  12
  •   Marcin Orlowski    6 年前

    使用最新版本 supportLibrary 版本 27.1.1 解决问题。为我工作。(包括许多错误修复- see changelog )

        6
  •  9
  •   Jérôme Legrand    6 年前

    就我个人而言,我在我的应用程序/构建中添加了以下内容。格拉德尔:

    implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
    

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

        7
  •  6
  •   Dhruvisha    6 年前

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

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

        8
  •  6
  •   Shashanth luckyhandler    6 年前

    使用

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

    不要使用like

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

    它可能会给您带来错误,并且不要使用比此版本更旧的版本。

    或事件不这样做

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

    等库的数量,然后

    实现的com。安卓支持:appcompat-v7:27。+'
    

    相同的库,但版本不同,可能会出现错误。

        9
  •  5
  •   Keshav Gera    6 年前

    我降低了支持级别

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

    使用它

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

    它工作得很开心

        10
  •  4
  •   Khemraj Sharma    6 年前

    重要更新

    之后将不会更新Android支持库 28.0.0 。根据 Support Library Release Notes -

    这将是android下的最后一个功能版本。支持 包装,并鼓励开发人员 migrate to AndroidX 1.0.0

    So使用 AndroidX 而是支持库。在您的情况下,设计库现在在material package中可用。

    dependencies {
        implementation 'com.google.android.material:material:1.0.0' // instead of design
        implementation 'androidx.appcompat:appcompat:1.0.2' // instead of support-v7
    }
    

    我已将最新版本置于dependency中,您可以 check latest version 在阅读时间。

    有用的帖子:

    1. AndroidX introduction & integration
    2. Learn about Jetifier (engine behind AndroidX migration)
    3. Some Do's and Dont's
        11
  •  2
  •   محمد    6 年前

    我也有这个问题;我决定这样做:

    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'
            }
        }
      }
    }
    

    小心我的min SDk是26,你必须用你的更改它!

        12
  •  2
  •   Vitali Pom    5 年前

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

        13
  •  1
  •   Raed    6 年前

    我知道这是一个迟来的答案,但我有同样的问题,我的解决方案只是增加 implementation 'com.android.support:design:28.0.0 或以上任何支持设计库!!

        14
  •  1
  •   Дмитрий Гаврилов    5 年前

    当一个库多次加载到gradle中时,就会发生这种情况。通常通过其他连接的库。

    删除实现 此库位于 建筑格拉德尔

    然后 建筑 -&燃气轮机; 清除项目

    您可以运行程序集)

        15
  •  0
  •   amit pandya Faisal Khan    6 年前

    由于android最新更新不支持“compile”关键字,请在模块中使用“implementation” 建筑格拉德尔 文件

    并在内部进行彻底检查。依赖性梯度 + 像这样签名。

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

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

    1. 同步渐变。
    2. 清理项目。
    3. 重建项目。
        16
  •  0
  •   Ssubrat Rrudra    6 年前

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

        17
  •  0
  •   Pradeep Sheoran    6 年前

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

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

    将常规依赖项设置为:

    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'
    }
    
        18
  •  0
  •   Pitel    6 年前

    将此添加到 项目的 gradle.properties 为我们修复了它:

    android.enableJetifier=true
    android.useAndroidX=true
    
        19
  •  0
  •   user3143487    6 年前

    构建脚本应与应用程序构建相匹配。渐变依赖项。

    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'
        ................
        ...........
    }
    

    如果您想降级依赖项,那么也要降级supportLibVersion和buildToolsVersion。

        20
  •  0
  •   Ankush Joshi    5 年前

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

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

    在你的情况下

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

    不一样,所以您将appcompat降级为

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

    因此,您的问题解决了。

    但如果您可以将支持设计版本升级到

    implementation 'com.android.support:design:27.1.0'
    
        21
  •  0
  •   BlackGraper    5 年前

    转到放置其他库的目录并删除重复的库。

        22
  •  -1
  •   Steve White    6 年前

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