Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method exclude() for arguments [{module=support-v4}]

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.

like image 582
Student Avatar asked Jan 20 '17 18:01

Student


People also ask

How do you exclude specific classes in dependency Gradle?

Just specify the group , the module and the version , like you do for dependencies. If you just want to exclude one class for a dependency jar, take a look at the jar jar links tool and its Gradle plugin. It allows you to alter included jars, e.g. to change packages or remove classes.

How do you remove transitive dependency in Gradle?

Using configuration we can exclude transitive dependency for module and group. Find the separate example of module and group. First find the example which will use module dependency as below. Run the command gradle eclipse, you will see that dom4j and its dependency JAR will not be available in classpath.

What is group and module in Gradle?

Group and module are properties for looking up libraries within maven repositories. For your dependency com.google.http-client:google-http-client:1.20.0. Group is com.google.http-client , module is google-http-client and the version is 1.20.0 .


2 Answers

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"
}
like image 197
Gideon Kitili Avatar answered Sep 20 '22 16:09

Gideon Kitili


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.

like image 31
Student Avatar answered Sep 22 '22 16:09

Student