Gradle 使用 appcompact 库在 android studio 中构建错误

Gradle build error in android studio with appcompact library

我遇到了这个错误

Error:Execution failed for task ':yourapp:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v7/recyclerview/BuildConfig.class

这是我的 build.gradle 文件

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 15
        multiDexEnabled true
        targetSdkVersion 22
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }

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

dependencies {
    compile (project(':library_slidingmenu')) {
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}
    compile project(':library')
    compile 'com.android.support:appcompat-v7:22.2.1'
    androidTestCompile 'com.android.support:multidex-instrumentation:1.0.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
    compile 'org.projectlombok:lombok:1.16.6'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.android.support:cardview-v7:22.1.0'
    compile 'com.android.support:recyclerview-v7:22.1.0'

知道如何解决吗?

如果您有一个依赖项也声明了 recyclerview 库,那么只需将它从依赖项中排除。例如假设你的库 library_slidingmenu 包含 recyclerview 依赖项,那么我们需要做这样的事情

dependencies {
    compile project(':library_slidingmenu') {
        exclude group: 'com.android.support', module: 'recyclerview-v7'
    }
    // the rest of your dependecies
}