多个dex文件定义了Landroid / support / v4 / accessibilityservice / AccessibilityServiceInfoCompat $ AccessibilityServiceInfoVersionImpl;

时间:2015-07-07 06:36:16

标签: android eclipse gradle

我在多个论坛及其相关答案中看到了这个错误,我尝试了所有,但它似乎并没有在我的情况下工作。让我简要介绍一下我的环境。我在mac osx 10.7.5上使用sunjdk 1.7和androidsdk 21运行Gradle 2.4。我的android项目是在eclipse juno中设置的,我正在尝试使用" gradle clean","在终端中构建它。 gradle build"命令。

以下是build.gradle文件

buildscript {
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
    mavenCentral() // or jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:1.2.3' // 1.3.0-beta3
}
}

apply plugin: 'com.android.application'

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')

compile ('com.android.support:appcompat-v7:21.0.3') {
  exclude module: 'support-annotations'
    }
compile ('com.android.support:recyclerview-v7:21.0.3') {
  exclude module: 'support-annotations'
  exclude module: 'support-v4'
}
 compile 'com.android.support:cardview-v7:21.0.3'

compile "org.igniterealtime.smack:smack-android-extensions:4.1.2"
compile "org.igniterealtime.smack:smack-tcp:4.1.2"
}

android {
compileSdkVersion 21
buildToolsVersion "19.1.0"

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

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


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


}

以下是我输出的命令" ./ gradlew -q dependencies"

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:21.0.3
|    \--- com.android.support:support-v4:21.0.3
+--- com.android.support:recyclerview-v7:21.0.3
+--- com.android.support:cardview-v7:21.0.3
+--- org.igniterealtime.smack:smack-android-extensions:4.1.2
\--- org.igniterealtime.smack:smack-tcp:4.1.2

看起来依赖输出中没有任何重复的jar /模块。但是,在运行" gradle build"时,我得到以下错误

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)

:dexDebug FAILED

FAILURE: Build failed with an exception.

请帮帮我。它看起来我没有永远解决这个错误。

2 个答案:

答案 0 :(得分:1)

最后,我找到了解决方案。问题是由于我的项目的lib文件夹包含android-appcompat-support-v4.jar和android-appcompat-support-v13.jar。我从项目lib文件夹中删除它们,因为这些jar是使用maven通过gradle加载的,因此导致重复。

从项目的lib文件夹中删除以上jar是解决此问题的关键。

答案 1 :(得分:0)

添加func getAttendees(child: String, completion: (result: Bool, name: String?, objectID: String?) -> Void){ //Get event attendees of particular event var attendeesReference = self.eventAttendeesRef.childByAppendingPath(child) println("Loading event attendees") //Get all event attendees attendeesReference.observeEventType(FEventType.ChildAdded, withBlock: { (snapshot) -> Void in let name = snapshot.value.objectForKey("name") as? String let objectID = snapshot.value.objectForKey("objectID") as? String println("Name: \(name) Object ID: \(objectID)") completion(result: true, name: name, objectID: objectID) }) { (error) -> Void in println(error.description) } func getAttendeesPictures(attendees: NSMutableDictionary, completion: (result: Bool, image: UIImage?)-> Void){ println("Attendees Count: \(attendees.count)") for (key, value) in attendees{ let url = NSURL(string: "https://graph.facebook.com/\(key)/picture?type=large") println("URL: \(url)") let urlRequest = NSURLRequest(URL: url!) //Asynchronous request to display image NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue()) { (response:NSURLResponse!, data:NSData!, error:NSError!) -> Void in if error != nil{ println("Error: \(error)") } // Display the image let image = UIImage(data: data) if(image != nil){ completion(result: true, image: image) } } } }

我希望这会有所帮助