Android studio Spring for Android构建在包含Spring社交推特时失败

Android studio Spring for Android构建在包含Spring社交推特时失败,android-studio,android-gradle-plugin,spring-android,spring-social-twitter,Android Studio,Android Gradle Plugin,Spring Android,Spring Social Twitter,在Android Studio 0.8.2上,我试图创建一个应用程序,使用Spring与Twitter集成。有无数的构建问题,直到我创建了一个空白的活动,我只是使用测试我的Gradle构建 每次我尝试连接到spring社交twitter时,构建都会失败。如果我注释掉Twitter依赖项,应用程序就会编译。我很确定这与应用程序本身无关,因为我正在一个空白的应用程序上测试它 我做错了什么 我的build.gradle文件: apply plugin: 'com.android.application

在Android Studio 0.8.2上,我试图创建一个应用程序,使用Spring与Twitter集成。有无数的构建问题,直到我创建了一个空白的活动,我只是使用测试我的Gradle构建

每次我尝试连接到spring社交twitter时,构建都会失败。如果我注释掉Twitter依赖项,应用程序就会编译。我很确定这与应用程序本身无关,因为我正在一个空白的应用程序上测试它

我做错了什么

我的build.gradle文件:

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'
}

我可以让你走得更远,但你可能会陷入下一个问题

如果我加载了您的构建文件(并再现了您的构建错误),当我进入IDE并要求它将我带到
BeansException
类时,我会得到以下结果:

您可以看到,
BeansException
在两个不同的位置定义,这在Android版本中是不允许的,因此您看到的错误是。您需要设置构建,以便在一个位置定义每个类

再进行一点调查,您可以使用此命令查看依赖关系树。从应用程序的模块目录中,运行以下命令:

../gradlew dependencies
输出的相关部分如下所示:

_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 (*)
从中我们可以看到,
org.springframework.social:spring-social-twitter:1.+
最终通过其可传递的依赖项(您发现了这一点,因为您将其隔离为导致构建问题的行)包括
org.springframework:springbeans:4.0.2.RELEASE
),但这意味着,如果它已经被捆绑到SpringAndroid核心jar中,那么它是多余的。我没有看到SpringAndroid内核对SpringBeans的另一种依赖;也许那个类只是打包到jar中,甚至不是依赖项

无论如何,您可以在依赖项中使用此语法来告诉Gradle不要选择可传递依赖项:

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'
}
如果我这样做,那么就不会再有dex多文件定义类错误。然而,我现在得到了这个类似但不同的重复文件错误,我可以想一想,但我不确定如果不编写一个实例化Spring的测试应用程序是否可以修复它,这超出了我将在SO回答中所做的范围;)

这意味着有两个
META-INF/spring.schema
文件包含在两个不同的位置,这也是不允许的。然而,在这里,你不能灵活地告诉dex忽略其中一个;您可以通过以下方式告知it忽略所有这些内容:

android {
  packagingOptions {
    exclude 'META-INF/spring.schemas'
  }
}
在构建文件中。我觉得Spring需要这个模式文件(不过是哪一个?),所以如果你这样做,你的应用程序可能仍然无法工作。尝试并反复讨论,如果你仍然有问题,你可以发布另一个问题,也许可以得到更专业的帮助


我不确定这个问题的根源是什么。Spring库中存在多个模式文件是否是打包错误?还是希望你解决这个问题?或者其他构建系统只是做了正确的事情?我不确定。

我可以让你走得更远,但你可能会遇到下一个问题

如果我加载了您的构建文件(并再现了您的构建错误),当我进入IDE并要求它将我带到
BeansException
类时,我会得到以下结果:

您可以看到,
BeansException
在两个不同的位置定义,这在Android版本中是不允许的,因此您看到的错误是。您需要设置构建,以便在一个位置定义每个类

再进行一点调查,您可以使用此命令查看依赖关系树。从应用程序的模块目录中,运行以下命令:

../gradlew dependencies
输出的相关部分如下所示:

_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 (*)
从中我们可以看到,
org.springframework.social:spring-social-twitter:1.+
最终通过其可传递的依赖项(您发现了这一点,因为您将其隔离为导致构建问题的行)包括
org.springframework:springbeans:4.0.2.RELEASE
),但这意味着,如果它已经被捆绑到SpringAndroid核心jar中,那么它是多余的。我没有看到SpringAndroid内核对SpringBeans的另一种依赖;也许那个类只是打包到jar中,甚至不是依赖项

无论如何,您可以在依赖项中使用此语法来告诉Gradle不要选择可传递依赖项:

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'
}
如果我这样做,那么就不会再有dex多文件定义类错误。然而,我现在得到了这个类似但不同的重复文件错误,我可以想一想,但我不确定如果不编写一个实例化Spring的测试应用程序是否可以修复它,这超出了我将在SO回答中所做的范围;)

这意味着有两个
META-INF/spring.schema
文件包含在两个不同的位置,这也是不允许的。然而,在这里,你不能灵活地告诉dex忽略其中一个;您可以通过以下方式告知it忽略所有这些内容:

android {
  packagingOptions {
    exclude 'META-INF/spring.schemas'
  }
}
在构建文件中。我觉得Spring需要这个模式文件(不过是哪一个?),所以如果你这样做,你的应用程序可能仍然无法工作。尝试并反复讨论,如果你仍然有问题,你可以发布另一个问题,也许可以得到更专业的帮助


我不确定这个问题的根源是什么。Spring库中存在多个模式文件是否是打包错误?还是希望你解决这个问题?或者其他构建系统只是做了正确的事情?我不确定。

我可以让你走得更远,但你可能会遇到下一个问题

如果我加载了您的构建文件(并再现了您的构建错误),当我进入IDE并要求它将我带到
BeansException
类时,我会得到以下结果:

您可以看到,
BeansException
在两个不同的位置定义,这在Android构建中是不允许的,因此会出现错误