android - 多个support-v4 jar导致问题

标签 android android-studio gradle android-gradle-plugin

我已经从eclipse中导出了一个项目-但是现在我无法将支持库添加到我的项目compile 'com.android.support:support-v4:21.0.0'中,因为该项目中使用的库具有相同库的副本(但它们在libs中的jar文件中夹)。现在,当我添加compile 'com.android.support:support-v4:21.0.0'时,出现以下问题:

Error:Execution failed for task ':Athan:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/annotation/IntDef.class

有人可以帮我解决这个问题吗?

这是我的应用程序build.gradle
apply plugin: 'android'


dependencies {


    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services_lib')
    compile project(':library_viewpager')
    compile project(':sliding_library')
    compile project(':android-support-v7-appcompat')
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:support-v4:21.0.0'
}

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    dexOptions {
        preDexLibraries = false
    }

    defaultConfig {
        multiDexEnabled true
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['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')
    }
}

最佳答案

仅在库项目中添加支持jar。无需在主项目中添加它,请记住所有支持库应为同一版本

关于android - 多个support-v4 jar导致问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29698579/

相关文章:

Android _ import android.support.v7.graphics 无法解决?

java - 如何将本地管理面板与 Android Studio 中的 Android 应用程序连接?

gradle - 如何备份和恢复gradle

c# - Azure 通知中心 : Schedule Mobile App API

java - 安卓 : youtube player has been released

android - 使用 MVVM Cross 将运行时格式化的 XML 字符串绑定(bind)到 Android TextView

android - 无法解决Android Studio 3.1.3中的Gradle同步失败(4.4级)

Android Gradle 排除 Debug BuildType 的类

java - 如果sonarqube中的主要问题数量大于50,要使我们的本地构建失败

gradle - 在gradle函数中执行bash命令