Android build error: Program type already present: android.support.v7.app.**

人盡茶涼 提交于 2019-12-08 03:39:49

问题


There are quite a few questions like this, but none of them seem to solve my issue, so maybe it's more specific to the library listed in the error message. I have tried just about everything other answers have suggested, but still see the same error.

I also get a Run Tasks error but I have multiDexEnabled true.

Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

Program type already present: android.support.v7.app.ActionBar$LayoutParams

Message{kind=ERROR, text=Program type already present: android.support.v7.app.ActionBar$LayoutParams, sources=[Unknown source file], tool name=Optional.of(D8)}

build.grade

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    //noinspection GradleCompatible
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'

    implementation project(':libs:DobSliding')

    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.soundcloud.android:android-crop:1.0.1@aar'
    implementation 'de.halfbit:pinned-section-listview:1.0.0'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
    implementation 'com.stripe:stripe-android:8.0.0'

    implementation 'com.google.android.gms:play-services:12.0.1'

    //noinspection GradleCompatible
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.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.1.0'
            }
        } else if (requested.group == "com.google.android.gms") {
            details.useVersion '11.8.0'
        } else if (requested.group == "com.google.firebase") {
            details.useVersion '11.8.0'
        }
    }
}

implementation project(':libs:DobSliding')

I only have 1 dependency here, so I am wondering if this is causing conflicts.

dependencies {
    implementation 'com.nineoldandroids:library:2.4.0'
}

./gradlew app:dependencies

Not really sure how to interpret this output: https://gist.github.com/WrightsCS/8888da5725357d62009773cee09997f0


回答1:


Turns out I had copied some .jar files into a libs folder and Android Studio was using them and giving me the error. Once I removed the offending libraries, such as AppCompat.jar and classes.jar, the build was fine.

Check any libs folders to make sure you do not carry over any android libraries that may have been bundled from an IntelliJ project.



来源:https://stackoverflow.com/questions/51902287/android-build-error-program-type-already-present-android-support-v7-app

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