java - 找不到参数 [{module=support-v4}] 的方法 exclude()

标签 java android gradle build.gradle

我试图在关闭即时运行的情况下运行我的应用程序,但出现此错误:

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

这是我的 gradle 文件:

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')
}

我尝试了 this 中的解决方案主题:

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

现在我在尝试同步 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

我现在有点迷茫,如果有人知道如何解决这个问题,我将不胜感激。

编辑

我删除了

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

完全正确,我仍然得到第一个错误。

最佳答案

这是语法问题。您调用 exclude 的闭包被解释为 files() 方法的参数,这是不正确的。应该是这样的

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

关于java - 找不到参数 [{module=support-v4}] 的方法 exclude(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41770540/

相关文章:

java - 我的继承代码正确吗?

java - 尝试在空对象引用上调用虚拟方法 'void android.widget.ImageView.setVisibility(int)'

android - View 未附加到窗口

android - 在未连接 USB 的情况下运行 UiAutomator 2.0 测试用例

java - ZoneId ID 的本地化名称

java - Final String mainViewPaths[]={}; 有什么用吗?

java - 从 Fabric 迁移到 Firebase

java - XML 解析失败

firebase - Firebase Auth导致Gradle失败

android-studio - 安卓工作室 : How to remove or disable javadoc generation from project build?