Could not find method exclude() for arguments [{mo

2019-06-22 07:51发布

问题:

I am trying to run my application with instant run turned off but I get this error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/view/KeyEventCompatEclair.class

Here is my gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.jua.app"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile project(path: ':app_Data')
    compile files('libs/android-support-v4.jar')
}

I tried the solution from this thread:

compile files('libs/android-support-v4.jar'){
    exclude module: "support-v4"
}

And now I am receiving this error when I try to Sync now gradle.build:

Error:(29, 0) Could not find method exclude() for arguments [{module=support-v4}] on file collection of type org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection. Open File

I am a little lost right now, If anyone has any idea how to solve this I would appreciate it.

EDIT

I removed

compile files('libs/android-support-v4.jar')

completly and I still get the first error.

回答1:

This is a syntax issue. The closure in which you are calling exclude is being interpreted as an argument to the files() method, which is incorrect. Should look like this

compile (files('libs/android-support-v4.jar')){
  exclude module: "support-v4"
}


回答2:

For anyone having the same problem, I deleted android-support-v4.jar from folder and now it works. For some reason, if you remove it from inside the gradle.build file it continues to create problems.