春季为Android构建包括Spring - 社会 - 微博时失败 [英] Spring for Android Build Failing when Including spring-social-twitter

查看:272
本文介绍了春季为Android构建包括Spring - 社会 - 微博时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的工作室0.8.2,我试图创建一个与Twitter使用Spring集成的应用。曾无数建的问题,直到我创建的,我只是用我的测试建立摇篮空白的活动。

我每次尝试连接到弹簧社会叽叽喳喳,构建失败。如果我注释掉Twitter的依赖,应用程序编译。我是pretty肯定这无关与应用程序本身,因为我上的一个空白的应用程序测试。

我在做什么错了?

我的build.gradle文件:

 应用插件:'com.android.application安卓{
    compileSdkVersion 20
    buildToolsVersion20.0.0    defaultConfig {
        的applicationIDcom.example.testapplication
        8的minSdkVersion
        targetSdkVersion 20
        版本code 1
        的versionName1.0
    }
    buildTypes {
        发布 {
            runProguard假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }    packagingOptions {
        排除META-INF / ASL2.0
        排除META-INF / LICENSE
        排除META-INF / LICENSE.TXT
        排除META-INF /注意事项
        排除META-INF / notice.txt
    }
}configurations.compile {
    排除模块:春芯
    排除模块:春天的web'
    排除模块:'的​​commons-logging
}依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:appcompat-v7:20.+
    编译org.springframework.android:spring-android-rest-template:1.+
    编译org.springframework.android:spring-android-auth:1.+
    编译org.springframework.android:spring-android-core:1.+
    编译org.springframework.security:spring-security-crypto:3.+
    编译org.springframework.social:spring-social-core:1.+
    编译org.springframework.social:spring-social-twitter:1.+'//< - 有问题的行
    编译com.fasterxml.jackson.core:杰克逊 - 数据绑定:2.3.2
}

错误:

 错误:执行失败的任务:应用程序:dexDebug。
    > com.android.ide.common.internal.LoggedErrorException:无法运行命令:
    C:\\ Android的\\ Android的工作室\\ SDK \\集结TOOLS \\ Android为4.4W \\ dx.bat --dex --num线程= 4 --output C:\\工作区\\ TestApplication \\程序\\建立\\中间体\\ DEX \\调试C:\\工作区\\ TestApplication \\程序\\建立\\中间体\\类\\调试C:\\工作区\\ TestApplication \\程序\\建立\\中间体\\依赖缓存\\调试C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\aopalliance-1.0-b64c80122d373c2ee241b55db78eac4c4c550a82.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\classes-528f16ed29eae5d85d8c6f1ee7d32d83803e6e6d.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\classes-fa1cd323aa3b243f3f4157cb5e43b3768ee49e9b.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\internal_impl-20.0.0-d4c263ffd0c244f7b9af8079e5d62faa86242454.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\jackson-annotations-2.3.0-c8c500c4e2e271888f48319f1d0f4ee141245e21.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\jackson-core-2.3.2-5a10979c76ddf0300365195ed3dcdf3bbf65dba0.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\jackson-databind-2.3.2-a027503e6b72a7b1487e8e935334766d26725e1b.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\javax.inject-1-e86c6ad046940b581fcf8f69e7965f8f5d1cfaf6.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-android-auth-1.0.1.RELEASE-d09921850d19080abfdeefe1fde904485c1b37c8.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-android-core-1.0.1.RELEASE-d006eb074ec6bcaf01f1fcb65dcc840f72c538d1.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-android-rest-template-1.0.1.RELEASE-f254c94632ca185a2fee85575fea1e4e9e68766f.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-aop-4.0.2.RELEASE-87af05a1d636417a8a1c074a0d93dbc6c5902550.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-beans-4.0.2.RELEASE-5afb5560550de06352f4871e0c5351c296555245.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-context-4.0.2.RELEASE-ae3ec0e430000b49e6dabc34fb702e4db3ab96ad.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-ex$p$pssion-4.0.2.RELEASE-1cfe445710559e2affa6317c573db04b9638c918.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-security-crypto-3.2.4.RELEASE-e5c641be2ba64d1b5bda6b6e9778a6043726fc96.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-social-config-1.1.0.RC1-0646da07e81cc32f0ff7a641a47b589c6ee71ed6.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-social-core-1.1.0.RC1-f762fce97f3b62664de8e04d427fea101bc74da1.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-social-twitter-1.1.0.RC1-66dcadc997a346a9caac49e5e66d0d6d60d6e684.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-social-web-1.1.0.RC1-753970492ed13f57671662ceb587dd9aa4f2c882.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\spring-webmvc-4.0.2.RELEASE-a6c8053426ad57c5e0b1eb2de9405ef3c0e118b1.jar C:\\Workspace\\TestApplication\\app\\build\\intermediates\\$p$p-dexed\\debug\\support-annotations-20.0.0-bab26a85db10fdf51a5bd499a182514bd4080ed4.jar
错误code:
2
输出:
意外的顶级例外:
com.android.dex.DexException:多DEX文件定义Lorg / springframework的/豆/ BeansException;
在com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
在com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
在com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
在com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
在com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
在com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
在com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
在com.android.dx.command.dexer.Main.run(Main.java:230)
在com.android.dx.command.dexer.Main.main(Main.java:199)
在com.android.dx.command.Main.main(Main.java:103)


解决方案

我可以帮你一起更远,但你可能会停留在一个问题。

如果我加载生成文件(和复制你的生成错误),当我去到IDE,并要求它带我到 BeansException 类,我得到这样的:

您可以看到 BeansException 在两个不同的地方,这是不是在允许的Andr​​oid版本,因此错误,您现在看到的定义。您需要设置您的构建,使得每个类在一个地方定义。

做多一点侦探,你可以使用这个命令来查看你的依赖关系树。从应用程序的模块目录,运行以下命令:

  ../ gradlew依赖

输出的相关部分是在这里:

  _debugApk  -  ##内部使用,不手动配置##
+ --- com.android.support:appcompat-v7:20.+ - > 20.0.0
| \\ --- com.android.support:support-v4:20.0.0
| \\ --- com.android.support:support-annotations:20.0.0
+ --- org.springframework.android:spring-android-rest-template:1.+ - > 1.0.1.RELEASE
| \\ --- org.springframework.android:spring-android-core:1.0.1.RELEASE
+ --- org.springframework.android:spring-android-auth:1.+ - > 1.0.1.RELEASE
| + --- org.springframework.android:spring-android-core:1.0.1.RELEASE
| + --- org.springframework.android:spring-android-rest-template:1.0.1.RELEASE(*)
| + --- org.springframework.security:spring-security-crypto:3.1.3.RELEASE - > 3.2.4.RELEASE
| \\ --- org.springframework.social:spring-social-core:1.0.2.RELEASE - > 1.1.0.RC1
+ --- org.springframework.android:spring-android-core:1.+ - > 1.0.1.RELEASE
+ --- org.springframework.security:spring-security-crypto:3.+ - > 3.2.4.RELEASE
+ --- org.springframework.social:spring-social-core:1.+ - > 1.1.0.RC1
+ --- org.springframework.social:spring-social-twitter:1.+ - > 1.1.0.RC1
| + --- com.fasterxml.jackson.core:杰克逊 - 数据绑定:2.3.0 - > 2.3.2
| | + --- com.fasterxml.jackson.core:杰克逊的注解:2.3.0
| | \\ --- com.fasterxml.jackson.core:杰克逊核心:2.3.2
| + --- org.springframework.security:spring-security-crypto:3.2.0.RELEASE - > 3.2.4.RELEASE
| + --- org.springframework.social:spring-social-core:1.1.0.RC1
| + --- org.springframework.social:spring-social-config:1.1.0.RC1
| | + --- org.springframework.social:spring-social-web:1.1.0.RC1
| | | + --- javax.inject:javax.inject:1
| | | + --- org.springframework:弹簧w​​ebmvc:4.0.2.RELEASE
| | | | + --- org.springframework:春豆:4.0.2.RELEASE
| | | | + --- org.springframework:春天上下文:4.0.2.RELEASE
| | | | | + --- org.springframework:弹簧AOP:4.0.2.RELEASE
| | | | | | + --- aopalliance:aopalliance:1.0
| | | | | | \\ --- org.springframework:春豆:4.0.2.RELEASE
| | | | | + --- org.springframework:春豆:4.0.2.RELEASE
| | | | | \\ --- org.springframework:弹簧前pression:4.0.2.RELEASE
| | | | \\ --- org.springframework:弹簧前pression:4.0.2.RELEASE
| | | \\ --- org.springframework.social:spring-social-core:1.1.0.RC1
| | \\ --- org.springframework.social:spring-social-core:1.1.0.RC1
| + --- com.fasterxml.jackson.core:杰克逊核心:2.3.0 - > 2.3.2
| \\ --- com.fasterxml.jackson.core:杰克逊的注解:2.3.0
\\ --- com.fasterxml.jackson.core:杰克逊 - 数据绑定:2.3.2(*)

从这里我们可以看出, org.springframework.social:spring-social-twitter:1 + 最终包括 org.springframework:春天-beans:4.0.2.RELEASE 通过其传递依赖(你发现了,因为你隔离这是导致你的构建问题就行),但是这意味着,如果它已经被捆绑成弹簧的Andr​​oid -core罐子,它是多余的。我没有看到从春天的Andr​​oid核心春豆另一个依赖;也许这类只是包装成罐子,甚至不是一个依赖。

在任何情况下,你可以使用这个语法在你的依赖,告诉摇篮不要拿起传递依赖:

  {相关性
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:appcompat-v7:20.+
    编译org.springframework.android:spring-android-rest-template:1.+
    编译org.springframework.android:spring-android-auth:1.+
    编译org.springframework.android:spring-android-core:1.+
    编译org.springframework.security:spring-security-crypto:3.+
    编译org.springframework.social:spring-social-core:1.+
    编译('org.springframework.social:spring-social-twitter:1.+'){
        排除模块:春豆
    }
    编译com.fasterxml.jackson.core:杰克逊 - 数据绑定:2.3.2
}

如果我这样做,那么没有更多的DEX多文件 - 确定 - 一类错误。不过,现在我得到这个类似,但不同的重复,文件的错误,我可以好好思考一下,但我不知道我是否可以修复它​​,而无需编写一个测试应用程序实例化春,这超出了我的'范围会做一个SO回答;)

 :应用:packageDebug
错误:APK /Users/sbarta/AndroidStudioProjects/MyApplication/app/build/outputs/apk/app-debug-unaligned.apk的包装过程中重复的文件
    META-INF / spring.schemas:在归档路径
    原产地1: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.social/spring-social-config/1.1.0.RC1/7afae4a4f83c64c4fd382c77708866e82900e799/spring-social-config-1.1.0.RC1.jar
    原产地2: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/4.0.2.RELEASE/6d6a781d99215990da8b398e1cdf09594a683209/spring-context-4.0.2.RELEASE.jar
您可以忽略你的build.gradle这些文件:
    安卓{
      packagingOptions {
        排除META-INF / spring.schemas
      }
    }
:应用:packageDebug失败故障:建立失败,一个例外。* 什么地方出了错:
执行失败的任务:应用程序:packageDebug。
>在重复APK META-INF / spring.schemas复制的文件
    文件1: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.social/spring-social-config/1.1.0.RC1/7afae4a4f83c64c4fd382c77708866e82900e799/spring-social-config-1.1.0.RC1.jar
    文件2: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.social/spring-social-config/1.1.0.RC1/7afae4a4f83c64c4fd382c77708866e82900e799/spring-social-config-1.1.0.RC1.jar

这意味着有两个 META-INF / spring.schemas被包括来自两个不同的地方,这也是不允许的文件。不过,你不必在这里告诉DEX的灵活性无视只是其中之一;你可以告诉它忽略 所有 号通过的:

 安卓{
  packagingOptions {
    排除META-INF / spring.schemas
  }
}

在您的构建文件。我有一种感觉,春天需要一个架构文件(其中之一,尽管???),所以如果你这样做,你的应用程序可能仍然无法正常工作。试验和鞭打与它周围,如果你仍然有问题,不过,你可以张贴另一个问题,也许获得更多的专业帮助。

我不知道这个问题的根源是什么。它是在Spring库包装错误,有多个模式文件?或者,您希望解决这个问题?或者做其他的编译系统只是做对了吗?我不知道。

On Android Studio 0.8.2, I am trying to create an app that integrates with Twitter using Spring. Had innumerable build problems until I created a blank activity that I'm just using the test my Gradle build.

Every time I try to connect to spring-social-twitter, the build fails. If I comment out the Twitter dependency, the app compiles. I'm pretty sure this has nothing to do with the app itself, because I'm testing it on a blank app.

What am I doing wrong?

My build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.example.testapplication"
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
}

configurations.compile {
    exclude module: 'spring-core'
    exclude module: 'spring-web'
    exclude module: 'commons-logging'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'org.springframework.android:spring-android-rest-template:1.+'
    compile 'org.springframework.android:spring-android-auth:1.+'
    compile 'org.springframework.android:spring-android-core:1.+'
    compile 'org.springframework.security:spring-security-crypto:3.+'
    compile 'org.springframework.social:spring-social-core:1.+'
    compile 'org.springframework.social:spring-social-twitter:1.+' // <- The offending line
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
}

The error:

Error:Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Android\android-studio\sdk\build-tools\android-4.4W\dx.bat --dex --num-threads=4 --output C:\Workspace\TestApplication\app\build\intermediates\dex\debug C:\Workspace\TestApplication\app\build\intermediates\classes\debug C:\Workspace\TestApplication\app\build\intermediates\dependency-cache\debug C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\aopalliance-1.0-b64c80122d373c2ee241b55db78eac4c4c550a82.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\classes-528f16ed29eae5d85d8c6f1ee7d32d83803e6e6d.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\classes-fa1cd323aa3b243f3f4157cb5e43b3768ee49e9b.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\internal_impl-20.0.0-d4c263ffd0c244f7b9af8079e5d62faa86242454.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\jackson-annotations-2.3.0-c8c500c4e2e271888f48319f1d0f4ee141245e21.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\jackson-core-2.3.2-5a10979c76ddf0300365195ed3dcdf3bbf65dba0.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\jackson-databind-2.3.2-a027503e6b72a7b1487e8e935334766d26725e1b.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\javax.inject-1-e86c6ad046940b581fcf8f69e7965f8f5d1cfaf6.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-android-auth-1.0.1.RELEASE-d09921850d19080abfdeefe1fde904485c1b37c8.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-android-core-1.0.1.RELEASE-d006eb074ec6bcaf01f1fcb65dcc840f72c538d1.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-android-rest-template-1.0.1.RELEASE-f254c94632ca185a2fee85575fea1e4e9e68766f.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-aop-4.0.2.RELEASE-87af05a1d636417a8a1c074a0d93dbc6c5902550.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-beans-4.0.2.RELEASE-5afb5560550de06352f4871e0c5351c296555245.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-context-4.0.2.RELEASE-ae3ec0e430000b49e6dabc34fb702e4db3ab96ad.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-expression-4.0.2.RELEASE-1cfe445710559e2affa6317c573db04b9638c918.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-security-crypto-3.2.4.RELEASE-e5c641be2ba64d1b5bda6b6e9778a6043726fc96.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-social-config-1.1.0.RC1-0646da07e81cc32f0ff7a641a47b589c6ee71ed6.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-social-core-1.1.0.RC1-f762fce97f3b62664de8e04d427fea101bc74da1.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-social-twitter-1.1.0.RC1-66dcadc997a346a9caac49e5e66d0d6d60d6e684.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-social-web-1.1.0.RC1-753970492ed13f57671662ceb587dd9aa4f2c882.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\spring-webmvc-4.0.2.RELEASE-a6c8053426ad57c5e0b1eb2de9405ef3c0e118b1.jar C:\Workspace\TestApplication\app\build\intermediates\pre-dexed\debug\support-annotations-20.0.0-bab26a85db10fdf51a5bd499a182514bd4080ed4.jar
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/springframework/beans/BeansException;
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)

解决方案

I can get you farther along, but you may get stuck at the next problem.

If I load up your build file (and reproduce your build error), when I go into the IDE and ask it to take me to the BeansException class, I get this:

You can see that BeansException is defined in two different places, which isn't allowed in Android builds, thus the error you're seeing. You need to set up your build such that each class is defined in one place.

Doing a little more sleuthing, you can use this command to see your dependency tree. From your application's module directory, run this command:

../gradlew dependencies

The relevant part of the output is here:

_debugApk - ## Internal use, do not manually configure ##
+--- com.android.support:appcompat-v7:20.+ -> 20.0.0
|    \--- com.android.support:support-v4:20.0.0
|         \--- com.android.support:support-annotations:20.0.0
+--- org.springframework.android:spring-android-rest-template:1.+ -> 1.0.1.RELEASE
|    \--- org.springframework.android:spring-android-core:1.0.1.RELEASE
+--- org.springframework.android:spring-android-auth:1.+ -> 1.0.1.RELEASE
|    +--- org.springframework.android:spring-android-core:1.0.1.RELEASE
|    +--- org.springframework.android:spring-android-rest-template:1.0.1.RELEASE (*)
|    +--- org.springframework.security:spring-security-crypto:3.1.3.RELEASE -> 3.2.4.RELEASE
|    \--- org.springframework.social:spring-social-core:1.0.2.RELEASE -> 1.1.0.RC1
+--- org.springframework.android:spring-android-core:1.+ -> 1.0.1.RELEASE
+--- org.springframework.security:spring-security-crypto:3.+ -> 3.2.4.RELEASE
+--- org.springframework.social:spring-social-core:1.+ -> 1.1.0.RC1
+--- org.springframework.social:spring-social-twitter:1.+ -> 1.1.0.RC1
|    +--- com.fasterxml.jackson.core:jackson-databind:2.3.0 -> 2.3.2
|    |    +--- com.fasterxml.jackson.core:jackson-annotations:2.3.0
|    |    \--- com.fasterxml.jackson.core:jackson-core:2.3.2
|    +--- org.springframework.security:spring-security-crypto:3.2.0.RELEASE -> 3.2.4.RELEASE
|    +--- org.springframework.social:spring-social-core:1.1.0.RC1
|    +--- org.springframework.social:spring-social-config:1.1.0.RC1
|    |    +--- org.springframework.social:spring-social-web:1.1.0.RC1
|    |    |    +--- javax.inject:javax.inject:1
|    |    |    +--- org.springframework:spring-webmvc:4.0.2.RELEASE
|    |    |    |    +--- org.springframework:spring-beans:4.0.2.RELEASE
|    |    |    |    +--- org.springframework:spring-context:4.0.2.RELEASE
|    |    |    |    |    +--- org.springframework:spring-aop:4.0.2.RELEASE
|    |    |    |    |    |    +--- aopalliance:aopalliance:1.0
|    |    |    |    |    |    \--- org.springframework:spring-beans:4.0.2.RELEASE
|    |    |    |    |    +--- org.springframework:spring-beans:4.0.2.RELEASE
|    |    |    |    |    \--- org.springframework:spring-expression:4.0.2.RELEASE
|    |    |    |    \--- org.springframework:spring-expression:4.0.2.RELEASE
|    |    |    \--- org.springframework.social:spring-social-core:1.1.0.RC1
|    |    \--- org.springframework.social:spring-social-core:1.1.0.RC1
|    +--- com.fasterxml.jackson.core:jackson-core:2.3.0 -> 2.3.2
|    \--- com.fasterxml.jackson.core:jackson-annotations:2.3.0
\--- com.fasterxml.jackson.core:jackson-databind:2.3.2 (*)

From this we can see that org.springframework.social:spring-social-twitter:1.+ eventually includes org.springframework:spring-beans:4.0.2.RELEASE through its transitive dependencies (which you found out because you isolated this as the line causing your build problem), but that means if it's already being bundled into the spring-android-core jar, it's redundant. I don't see another dependency on spring-beans from spring-android-core; perhaps that class is just packaged into the jar and isn't even a dependency.

At any rate, you can use this syntax in your dependencies to tell Gradle to not pick up a transitive dependency:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'org.springframework.android:spring-android-rest-template:1.+'
    compile 'org.springframework.android:spring-android-auth:1.+'
    compile 'org.springframework.android:spring-android-core:1.+'
    compile 'org.springframework.security:spring-security-crypto:3.+'
    compile 'org.springframework.social:spring-social-core:1.+'
    compile('org.springframework.social:spring-social-twitter:1.+') {
        exclude module: 'spring-beans'
    }
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
}

If I do this, then no more dex multiple-files-define-a-class error. However, I now get this similar but different duplicate-files error, which I can muse about a bit but I'm not sure if I could fix it without writing a test app that instantiates Spring, which is beyond the scope of what I'll do in a SO answer ;)

:app:packageDebug
Error: duplicate files during packaging of APK /Users/sbarta/AndroidStudioProjects/MyApplication/app/build/outputs/apk/app-debug-unaligned.apk
    Path in archive: META-INF/spring.schemas
    Origin 1: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.social/spring-social-config/1.1.0.RC1/7afae4a4f83c64c4fd382c77708866e82900e799/spring-social-config-1.1.0.RC1.jar
    Origin 2: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework/spring-context/4.0.2.RELEASE/6d6a781d99215990da8b398e1cdf09594a683209/spring-context-4.0.2.RELEASE.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/spring.schemas'
      }
    }
:app:packageDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/spring.schemas
    File 1: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.social/spring-social-config/1.1.0.RC1/7afae4a4f83c64c4fd382c77708866e82900e799/spring-social-config-1.1.0.RC1.jar
    File 2: /Users/sbarta/.gradle/caches/modules-2/files-2.1/org.springframework.social/spring-social-config/1.1.0.RC1/7afae4a4f83c64c4fd382c77708866e82900e799/spring-social-config-1.1.0.RC1.jar

What this means is that there are two META-INF/spring.schemas files being included from two different places, which is also not permitted. However, you don't have the flexibility here of telling dex to ignore just one of them; you can tell it to ignore all of them via:

android {
  packagingOptions {
    exclude 'META-INF/spring.schemas'
  }
}

in your build file. I have a feeling that Spring needs that schemas file (which one, though???), so if you do this, your app may still not work. Experiment and thrash around with it, and if you're still having problems, though, you can post another question and maybe get more specialized help.

I'm not sure what the root of this problem is. Is it a packaging error in the Spring libraries that there are multiple schema files? Or are you expected to resolve this? Or do other build systems just Do The Right Thing? I'm not sure.

这篇关于春季为Android构建包括Spring - 社会 - 微博时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆