Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

时间秒杀一切 提交于 2019-11-26 09:07:31

问题


I am getting the following error while building the project. haven\'t used CoordinatorLayout in this project. just added as a dependency in build.gradle :

I am using Android Studio 3.2 Canary 4.

LogCat

AGPBI: {\"kind\":\"error\",\"text\":\"Program type already present: android.support.design.widget.CoordinatorLayout$Behavior\",\"sources\":[{}],\"tool\":\"D8\"} :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task \':app:transformDexArchiveWithExternalLibsDexMergerForDebug\'.

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /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

Program type already present: 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\"
}

回答1:


It worked when I downgrade the support appcompat gradle dependency, like follwing :

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

previously it was

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

OR

Also this can be fixed by just adding support design dependency of version 27.1.0 or above to your app level build.gradle as following :

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



回答2:


I faced the same problem, I added android support design dependencies to the app level build.gradle

Add following:

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

in build.gradle. Now its working for me.




回答3:


It might be cause of a library, I faced it because of Glide.

It was

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

So I added exclude group: "com.android.support" And it becomes

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



回答4:


Make sure these two are the same version in your app level build.gradle file

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

I think that should solve the problem




回答5:


Use the latest supportLibrary, version 27.1.1 to solve the problem. worked for me. (many bug fixes included - see changelog)




回答6:


Personally, I add the following line to my app/build.gradle:

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

With this syntax, version is dynamical.




回答7:


I m using android studio 3.0 and i upgrade the design pattern dependency from 26.0.1 to 27.1.1 and the error is gone now.

Add Following in gradle implementation 'com.android.support:design:27.1.1'




回答8:


Use

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

Don't use like

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

It may give you an error and don't use an older version than this.

or event don't do like this

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

etc... numbers of libraries and then

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

the same library but it has a different version, it can give you an error.




回答9:


I downgrade the support

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

Use it

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

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

Its Working Happy Codng




回答10:


Important Update

Android support libraries will not be updated after 28.0.0. According to Support Library Release Notes -

This will be the last feature release under the android.support packaging, and developers are encouraged to migrate to AndroidX 1.0.0.

So use AndroidX support libraries instead. In your case design library is now available in 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
}

I have put latest versions in dependency, you can check latest version here at read time.

Useful Posts :

  1. AndroidX introduction & integration
  2. Learn about Jetifier (engine behind AndroidX migration)
  3. Some Do's and Dont's



回答11:


I had this problem too; and i resolved that in this way:

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

be careful my min SDk was 26 , you have to change it with yours!




回答12:


I know it's a late answer but I had the same problem and my solution was just adding implementation 'com.android.support:design:28.0.0 or any above support design libraries !!




回答13:


"Program type already exists" Remove your /build directory contents, it has some Dex(?) problem with the generated binary files. Got to those answers just like you, they helped to resolve this problem but created many others. Build contents removal works for all.




回答14:


As android latest update doesn't support 'compile' keyword use 'implementation' in place inside your module build.gradle file.

And check thoroughly in build.gradle for dependancy with + sign like this.

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

If there are any dependencies like this, just update them with a specific version. After that:

  1. Sync gradle.
  2. Clean your project.
  3. Rebuild the project.



回答15:


The solution for this is that remove this following dependency:

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

put general dependencies as:

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



回答16:


I got this error after update com.android.support.constraint:constraint-layout from 1.1.0 to 1.1.3. Maybe worth to try.




回答17:


Adding this to project's gradle.properties fixed it for us:

android.enableJetifier=true
android.useAndroidX=true



回答18:


Your build script should match with application build.gradle dependencies.

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

if you want to downgrade dependencies then also downgrade supportLibVersion and buildToolsVersion .




回答19:


I also faced same problem. But then I realised that the versions I am using of support libraries was not same.

Once I made it same, the error gone.

In your case

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

are not same, so you just downgraded appcompat to

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

hence, your problem solved.

But you could also have solved if you could have upgraded support design version to

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



回答20:


This can happens when one library is loaded into gradle several times. Most often through other connected libraries.

Remove a implementation this library in build.gradle

Then Build -> Clear project

and you can run the assembly)




回答21:


If any of the answers mentioned here doesn't work then go to File > Invalidate Catches/Restart




回答22:


Go to the directory where you put additional libraries and delete duplicated libraries.




回答23:


Changed all dependencies to compile rather than implementation, then I rebuild the project without errors. Then I switched back to implementation rather than leaving it as compile.



来源:https://stackoverflow.com/questions/49112190/error-program-type-already-present-android-support-design-widget-coordinatorl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!