2015-08-04 25 views
17

Tôi đang cố gắng tích hợp espresso vào ứng dụng của mình để kiểm tra ui. Dưới đây là các phụ thuộc của tôi trong GradleVấn đề về Espresso Android - Xung đột phụ thuộc

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:22.2.0' 
    compile 'com.android.support:design:22.2.1' 
    compile 'com.github.bumptech.glide:okhttp-integration:[email protected]' 
    compile 'com.squareup.okhttp:okhttp:2.0.0' 
    compile 'de.hdodenhof:circleimageview:1.3.0' 
    compile 'com.android.support:cardview-v7:21.+' 
    compile 'com.android.support:recyclerview-v7:21.+' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' 
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2' 
    compile 'com.android.support:support-annotations:22.2.0' 
    androidTestCompile 'com.android.support.test:runner:0.3' 
    compile project(':common') 
    compile project(':service') 
} 

Vì vậy, tất cả các phụ thuộc espresso của tôi được bao gồm. Tuy nhiên khi tôi cố gắng xây dựng tôi nhận được lỗi này:

Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (22.2.0) differ.

Có ai gặp phải điều này? Tôi đã tìm thấy nó báo cáo here tuy nhiên không có độ phân giải. Có ai có một sửa chữa cho điều này?

+1

Giải pháp là sử dụng 'configurations.all { resolutionStrategy.force' com .android.support: hỗ trợ-chú thích: 22.1.0 ' }' –

+1

Xin chào, bạn phải xóa phụ thuộc android.support khỏi mỗi phụ thuộc của espresso. kiểm tra: http://stackoverflow.com/questions/29857695/android-tests-build-error-multiple-dex-files-define-landroid-support-test-build –

Trả lời

10

Vì vậy, sau nhiều lần khám phá xung quanh, tôi thấy tôi cần phải thay đổi phụ thuộc cho chú thích hỗ trợ.

Vì vậy, tôi cần phải thay đổi compile 'com.android.support:support-annotations:22.2.0' để androidTestCompile 'com.android.support:support-annotations:22.+'

+0

tôi sẽ đề xuất thay vì sử dụng cách tiếp cận tôi đã viết trong http://stackoverflow.com/questions/31807182/android-espresso-issue-dependency-conflict/41160902#41160902 vì sử dụng "+" cho phiên bản được khuyến khích – Noya

1

Vấn đề là trong tập tin này: android-sdk \ extras \ android \ m2repository \ com \ android \ support \ test \ Á hậu \ 0.3 \ Á hậu -0.3.pom

đây:

<dependency> 
     <groupId>com.android.support</groupId> 
     <artifactId>support-annotations</artifactId> 
     <version>22.2.0</version> 
     <scope>compile</scope> 
</dependency> 

nếu bạn thiết lập 22.2.1 thay vì 22.2.0 nó sẽ làm việc

4

tôi phải kết hợp các phiên bản sau cho L phát hành sau khi nhận được một cuộc xung đột phụ thuộc tương tự giữa dự án và ứng dụng thử nghiệm:

android { 
    useLibrary 'org.apache.http.legacy' 
    compileSdkVersion 23 
    buildToolsVersion '23.0.1' 
    defaultConfig {  
     minSdkVersion 14 
     targetSdkVersion 23 
    } 
} 
dependencies { 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:support-v4:23.0.1' 

    androidTestCompile 'com.android.support.test:runner:0.4' 
    androidTestCompile 'com.android.support.test:rules:0.4' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' 
} 

useLibrary là cần thiết vì chúng ta sử dụng org.apache.http nhập khẩu, xem https://github.com/bitstadium/HockeySDK-Android/issues/80

7

trong Jake Wharton U2020 application nó được giải quyết theo cách tiếp

Thêm vào bạn gradle.build nộp

configurations.all { 
    resolutionStrategy { 
     force 'com.android.support:support-annotations:23.0.1' 
    } 
} 
8

Phiên bản mới nhất của phụ thuộc androidTest phụ thuộc vào phiên bản thích hợp của support-annotations lib. Trong trường hợp của tôi là:

androidTestCompile 'com.android.support.test:runner:0.4' 
androidTestCompile 'com.android.support.test:rules:0.4' 
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' 
androidTestCompile 'org.mockito:mockito-core:2.0.31-beta' 

Ngoài ra, như một cách giải quyết bạn có thể thêm các mã tiếp theo trong build.gradle, android{} phần của bạn:

configurations.all { 
    resolutionStrategy { 
     force 'com.android.support:support-annotations:23.0.1' 
    } 
} 
+0

Thêm cấu hình.all {..} hoạt động hoàn hảo. Cảm ơn – kevinkl3

+0

Tôi biết rằng câu trả lời này sẽ giải quyết được vấn đề. Nhưng mọi phiên bản chú thích hỗ trợ đều có thể dựa vào các phương thức khác nhau, Vì vậy, hãy rất cẩn thận vì các libs phụ thuộc vào chú thích hỗ trợ có thể hoạt động lạ. – sagits

34

Phiên bản mới của espresso-contrib 2.2.2 thư viện có hiện sự phụ thuộc vào com.android.support:appcompat-v7:23.1.1 dẫn đến xung đột khi sử dụng phiên bản khác nhau của appcompat-v7 trong phụ thuộc thời gian compile của chúng tôi như sau:

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 

    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2' 
} 

Để tránh xung đột khi chúng tôi loại trừ appcompat-v7 sự phụ thuộc từ espresso-contrib như dưới đây, vi phạm một lần nữa do một số phụ thuộc giá trị trên design support lib.

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'support-v13' 
    exclude module: 'recyclerview-v7' 
    exclude module: 'appcompat-v7' 
} 

Lỗi:

Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.

Vì vậy, giải pháp cho vấn đề trên là để loại trừ 'thiết kế hỗ trợ' depedency lib từ espresso-contrib như dưới đây:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){ 
    exclude module: 'support-annotations' 
    exclude module: 'support-v4' 
    exclude module: 'support-v13' 
    exclude module: 'recyclerview-v7' 
    exclude module: 'design' 
} 

Đó giải quyết vấn đề xung đột !

Để biết thêm phiên bản chi tiết của câu trả lời, bạn có thể kiểm tra khác answer

+1

đây phải là câu trả lời đúng. – WenChao

+0

@Droidwala là câu trả lời hay nhất – mks

0

chỉ cần thay đổi biên dịch 'com.android.support:support-annotations:22.2.0' để 23.0.1 nếu muốn sử dụng 2.2 của tôi. 1 phiên bản

1

Như đã trình bày trong tài liệu google: https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK

cách giải quyết là để thiết lập một cách rõ ràng các thư viện hỗ trợ trong androidTestCompile lên phiên bản bạn đang sử dụng trong dự án.

nếu ví dụ bạn đang sử dụng thư viện hỗ trợ phiên bản 25.0.1 chỉ cần thêm

androidTestCompile 'com.android.support:support-annotations:25.0.1' 

trong cấu hình build.gradle bạn

Các vấn đề liên quan