Google Play服务与Android Studio上的HoloEverywhere依赖关系之间的冲突

时间:2014-01-15 12:53:49

标签: android android-studio android-support-library android-holo-everywhere android-gradle

我刚刚开始使用Android Studio和Gradle,当我尝试运行我的应用时,我遇到了冲突错误。我已经做了一些研究,问题是HoloEverywhere使用自定义support-v4库(某些内部类的可见性已更改),这与其他lib(在本例中为Google Play Services)使用的support-v4库不同。我在一些帖子中读过像here那样在所有模块中使用相同的support-v4库,但是在这种情况下我不能这样做,因为没有自定义support-v4库,HoloEverywhere不起作用我无法触及Google Play服务使用的support-v4库。我希望有人已经经历过这个并找到了解决方案,因为这让我疯狂:)

以下是错误日志:

Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/diego/Documents/android-sdk-macosx/build-tools/19.0.1/dx --dex --output 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/libs/app-debug.dex 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/classes/debug 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/dependency-cache/debug 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/classes-2c9d7b640eaa13481d9d1c220b95094b847d6825.jar 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/classes-2edf2d8c7b1a7575431e0269a325d54bdc9fc798.jar 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/classes-bc16442b2fdfdfc88911109da1e6baf89a7938a0.jar 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/nineoldandroids-2.4.0-1e541581bdb9515af0d791ecbc51193b05f1c93a.jar 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/support-v4-13.0.0-2f3822466a4631d8fa7d69b3fd104b27f4df0298.jar 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/support-v4-19.0.1-a98845f591723a85fad8ed448a9cc0ced3cb3194.jar 
/Users/diego/Documents/WorkspaceAndroid/WorkspaceTest/app/build/pre-dexed/debug/support-v4-19.0.1a-f1f3d357780dd5b4d33c6ca1830109136769ef22.jar
    Error Code:
    2
    Output:
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) 
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
    at com.android.dx.command.dexer.Main.run(Main.java:230)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)

settings.gradle:

include ':app'
include 'Volley'
include 'Facebook'
include 'ViewPagerIndicator'
include 'HoloEverywhere'

project(':Volley').projectDir = new File(settingsDir, 'libraries/volley')
project(':Facebook').projectDir = new File(settingsDir, 'libraries/facebook-android-sdk/facebook')
project(':ViewPagerIndicator').projectDir = new File(settingsDir, 'libraries/Android-ViewPagerIndicator/library')
project(':HoloEverywhere').projectDir = new File(settingsDir, 'libraries/HoloEverywhere/library')
'app'目录中

build.gradle:

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

apply plugin: 'android'

repositories {
        mavenCentral()
}

android {
        compileSdkVersion 19
        buildToolsVersion '19.0.1'

        defaultConfig {
                minSdkVersion 10
                targetSdkVersion 19
        }
}

dependencies {
        compile 'com.google.android.gms:play-services:4.0.30'
        compile project(':Volley')
        compile project(':Facebook')
        compile project(':ViewPagerIndicator')
        compile project(':HoloEverywhere')
}
'HoloEverywhere / library'目录中的

build.gradle:

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

apply plugin: 'android-library'

dependencies {
        compile files ('libs/support-v4-19.0.1.jar')
        compile files ('libs/nineoldandroids-2.4.0.jar')
}

android {
        compileSdkVersion 19
        buildToolsVersion '19.0.1'

        defaultConfig {
                minSdkVersion 7
                targetSdkVersion 19
        }

        sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src']
                    res.srcDirs = ['res']
                }
        }
}

2 个答案:

答案 0 :(得分:1)

需要进行这些更改,如果存储库在maven上可用,请避免使用本地项目:

对于截击使用:

 compile 'com.mcxiaoke.volley:library-aar:1.0.0'

在app模块的build.gradle文件中,删除与settings.gradle中的Volley相关的所有内容。

根据此处的holoeverywhere图书馆

https://github.com/Prototik/HoloEverywhere/blob/master/library/build.gradle

正在使用这些依赖

 dependencies {
    compile 'com.android.support:support-v4:19.0.+'
   compile 'com.nineoldandroids:library:2.4.0@jar'
 }

下载此内容并通过替换已有的内容添加到您的项目中。

如果支持依赖项在一个gradle项目模块(例如holoeverywhere或viewpageindicator)中,则不需要将其包含在任何其他模块中,因此如果有,则删除。

完成所有这些更改后,使用此按钮将项目与gradle同步。

答案 1 :(得分:0)

经过一些试验和错误,感谢@ pyus13和@Prototik提示,我能够使用Android Studio运行我的项目。除了ViewPagerIndicator之外,我删除了依赖库的所有本地副本。以下是工作的gradle文件:

<强> settings.gradle:

include ':app'
include 'ViewPagerIndicator'

project(':ViewPagerIndicator').projectDir = new File(settingsDir, 'libraries/Android-ViewPagerIndicator/library')
'app'目录中

build.gradle:

buildscript {
        repositories {
                mavenCentral()
        }
        dependencies {
                classpath 'com.android.tools.build:gradle:0.7.+'
                classpath 'org.holoeverywhere:plugin:0.2.+'
        }
}

apply plugin: 'holoeverywhere'
apply plugin: 'android'

repositories {
        mavenCentral()
}

holoeverywhere {
        addons {
                create 'preferences'
                create 'slider'
        }
        library {
                version '2.1.0'
        }
}

android {
        compileSdkVersion 19
        buildToolsVersion '19.0.1'

        defaultConfig {
                minSdkVersion 10
                targetSdkVersion 19
        }
}

dependencies {
        compile 'com.google.android.gms:play-services:4.0.30'
        compile 'com.google.code.gson:gson:2.2.+'
        compile 'com.mcxiaoke.volley:library-aar:1.0.+@aar'
        compile 'fr.avianey:facebook-android-api:3.6.+@aar'

        compile project(':ViewPagerIndicator')
}