0

Android Studio 0.8.2에서 Spring을 사용하여 Twitter와 통합되는 앱을 만들려고합니다. 무수한 빌드 문제가 생길 때까지 그냥 빈 테스트를 사용하고 있습니다.Android 용 스프링 스프링 - 사회 - 트위터 포함시 실패

스프링 - 사회 - 트위터에 연결할 때마다 빌드가 실패합니다. 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' 
} 

오류 :

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) 
+0

일부 종속성은 'BeansException' 클래스와 동일합니다. –

답변

3

내가 더 함께 당신을 얻을 수 있지만, 당신은 다음 문제에 붙어 얻을 수 있습니다.

Screen shot of "Open class" dialog, showing multiple BeansException classes

당신 :

내가 빌드 파일을로드 (및 빌드 오류를 재현) 내가 IDE에 갈 때, 그리고 BeansException 클래스에 데려다을 요구하는 경우에,이를 얻을 수 BeansException은 Android 빌드에서 허용되지 않는 두 개의 다른 위치에 정의되어 있음을 알 수 있습니다. 따라서보고있는 오류입니다. 각 클래스가 한 곳에서 정의되도록 빌드를 설정해야합니다.

더 많은 sleuthing을 수행하면이 명령을 사용하여 종속성 트리를 볼 수 있습니다.

../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:spring-beans:4.0.2.RELEASE가 포함되어 있는지 볼 수있는 당신을 당신이 빌드 문제를 야기하는 줄로 분리했기 때문에 알게되었지만, 그것은 스프링 앤드 로이드 코어 병에 이미 번들되어 있다면, 그것은 중복됨을 의미합니다. 봄 - 안드로이드 코어의 봄 콩에 대한 또 다른 의존성은 보이지 않는다. 아마도 그 클래스는 단지에 패키지되어 있고 심지어 의존성이 아닙니다. 나는이 작업을 수행 할 경우, 더 이상 덱스 여러 파일을-정의하지-A를

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

: 하여간

, 당신은 이적 의존성을 선택하지 Gradle을 알려 의존성이 구문을 사용할 수 있습니다 - 클래스 오류. 그러나 지금은 유사하지만 다른 중복 파일 오류가 발생합니다.이 오류는 다소 혼란 스럽지만 Spring을 인스턴스화하는 테스트 응용 프로그램을 작성하지 않고도 문제를 해결할 수 있을지 확신 할 수 없습니다. SO 대답 원치에서 할 것이다)

: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 

이것이 의미하는 것은 허용되지 않습니다 두 개의 서로 다른 장소에서 포함되는 두 META-INF/spring.schemas 파일이 있다는 것입니다.그러나 dex에게 그 중 하나만 무시하도록하는 유연성은 없습니다. 당신은을 통해 그들 모든를 무시하도록 지시 할 수 있습니다 빌드 파일에

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

합니다. Spring이 스키마 파일을 필요로한다는 느낌이 들었습니다. (어느 것인가 ???) 이렇게하면 앱이 여전히 작동하지 않을 수 있습니다. 실험을하고 주위를 때리고, 여전히 문제가 있다면, 다른 질문을 올리거나 더 전문적인 도움을받을 수 있습니다.

이 문제의 근본 원인을 잘 모르겠습니다. Spring 라이브러리에 여러 스키마 파일이있는 패키지 오류입니까? 아니면 이것을 해결할 것으로 예상됩니까? 아니면 다른 빌드 시스템으로 올바른 작업을 수행합니까? 나는 잘 모르겠다.

+0

몇 가지 질문이 있습니다. 첫째, 어떻게 당신은 "gradlew dependencies"에 나타나도록 그 트리 구조를 얻었습니까? 내 시스템이 그렇게하지 않습니다. 둘째, 어떤 버전의 gradle을 사용하고 있습니까? 내 것은 "{exclude module : 'spring-bean'} '을 허용하지 않습니다. 어딘가에 구성이 누락되었습니다. – Baracus

+1

의존성 트리가 최상위 프로젝트 디렉토리가 아닌 모듈의 디렉토리에서 실행되면 나를 위해 작동합니다. Gradle/Plugin 버전은 플러그인의 0.12이고 Gradle의 1.12 일 수도 있습니다. 그 제외는 당신이 가진 것과 함께 일해야합니다. –

+0

좋아요, 의존성 트리가 작동하고 있습니다. exclude 문으로 어떤 일이 일어나고 있는지 확실하지 않습니다. 그것은 "빌드 스크립트 오류, 지원되지 않는 Gradle DSL 방법을 찾았습니다"라는 말을 계속합니다. 걱정할 필요가 없습니다. 왜냐하면 저는 거의 작동했기 때문에 걱정 스럽지만 여전히 이상합니다. – Baracus

0

좋아요, 이것은 만족스러운 해결책이라고 할 수있는 것과는 거리가 멀지 만 그 일은 컴파일되므로 기쁘게 생각합니다.

문제의 근원이 무엇이든, 스프링 - 사회 - 트위터 버전 1.1.0에만 해당되는 것으로 보입니다. 나는 읽을 build.gradle 라인을 변경 :

compile 'org.springframework.social:spring-social-twitter:1.0.5.RELEASE' 

오히려 ... 봄 - 사회 - 트위터보다 더 : 1. + '내가 전에했고 지금 잘 컴파일합니다. 아직 작업 측면을 테스트하지는 않았지만 그것은 완전히 다른 질문들로 구성됩니다.

이 방법은 실제 "솔루션"보다 덜 우스꽝 스럽다.