【问题标题】:How to exclude the support v4 library from the studio?如何从工作室中排除 support v4 库?
【发布时间】:2017-01-12 21:50:42
【问题描述】:

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务“:transformClassesWithJarMergingForDebug”执行失败。

    com.android.build.api.transform.TransformException: java.util.zip.ZipException:重复条目:android/support/v4/content/Loader$OnLoadCompleteListener.class

build.gradle 文件中的代码

   apply plugin: 'com.android.application'


dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    //compile project(':ActionBarSherlock-4.1.0')
    compile project(':GooglePlayServicesLibrary')
    compile files('libs/eventbus-2.4.0.jar')
    compile (project(':AndroidBetterPickers')){ exclude module: 'support-v4' }
    compile (project(':ZxingFragmentLib')){ exclude module: 'support-v4' }
    compile (project(':RobotoTextView')){ exclude module: 'support-v4' }
    compile (project(':PanesLibrary')){ exclude module: 'support-v4' }
    compile (project(':ShowCaseViewLibrary')){ exclude module: 'support-v4' }
    compile (project(':ActionBarSherlock-4.1.0')){ exclude module: 'support-v4' }



}

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'
    }



}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}



android {
    packagingOptions {

        exclude  'META-INF/maven/com.nineoldandroids/library/pom.xml'
        exclude  'META-INF/maven/com.nineoldandroids/library/pom.properties'
        exclude  'META-INF/services/javax.annotation.processing.Processor'

    }



    dexOptions {
        javaMaxHeapSize "4g"
    }
    compileSdkVersion 19
    buildToolsVersion '22.0.1'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }




    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['.apt_generated','res','src']
            resources.srcDirs = ['.apt_generated','res','src']
            aidl.srcDirs = ['.apt_generated','res','src']
            renderscript.srcDirs = ['.apt_generated','res','src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }




}

【问题讨论】:

  • 让我们看看你的 Gradle 文件是什么样子的。错误指向重复条目 - 表明您可能包含了两次或更多内容。
  • @ishmaelMakitla 以上是我的 build.gradle 文件。

标签: android-studio gradle dependencies support-v4


【解决方案1】:

我已经这样做了

dependencies {
    api('com.android.support:recyclerview-v7:22.2.0') {
       exclude module: 'support-v4'
    }
 }

【讨论】:

  • 我对它支持的所有库都做了同样的事情。但这对我没有帮助。
  • 请注意,google play 服务 api [非常大] (developers.google.com/android/guides/setup) 也许您只需要一些 api。回到你的问题:尝试命令 gradle dependencies。这将以树格式显示项目依赖项。
  • +--- 项目:GooglePlayServicesLibrary +--- 项目:AndroidBetterPickers +--- 项目:ZxingFragmentLib +--- 项目:RobotoTextView +--- 项目:PanesLibrary | \--- project :ActionBarSherlock-4.1.0 +--- project :ShowCaseViewLibrary \--- project :ActionBarSherlock-4.1.0 下面是gradle依赖的树
  • 一些库也使用支持 v4 jar 作为其中的依赖项。这是图书馆的问题吗?
  • 借助 gradle 依赖项,您可以确定哪个库使用/需要支持 v4。因此,如果您这样做了,您可以像之前所做的那样排除该库上的支持 v4,例如编译(项目(':GooglePlayServicesLibrary')){排除模块:'support-v4'}
【解决方案2】:
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    // compile project(':ActionBarSherlock-4.1.0')
    compile project(':GooglePlayServicesLibrary')
    compile files('libs/eventbus-2.4.0.jar')
    compile (project(':AndroidBetterPickers'))
    compile (project(':ZxingFragmentLib'))
    compile (project(':RobotoTextView'))
    compile (project(':PanesLibrary'))
    compile (project(':ShowCaseViewLibrary'))
    compile (project(':ActionBarSherlock-4.1.0'))
compile files('libs/support-v4-19.0.1.jar')

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,重置实现编译后,它工作正常,但我不知道为什么...... 也许这是“实施”的错误

    【讨论】:

      猜你喜欢
      • 2015-03-23
      • 1970-01-01
      • 2013-01-17
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      相关资源
      最近更新 更多