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

折月煮酒 提交于 2019-12-23 09:56:55

问题


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.



来源:https://stackoverflow.com/questions/41770540/could-not-find-method-exclude-for-arguments-module-support-v4

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