Để tìm phụ thuộc trùng lặp hoặc phụ thuộc bắt buộc của nó, bạn có thể trực quan hóa các phụ thuộc thư viện trong cây. Thực hiện lệnh gradle như dưới đây.
gradle -q dependencies yourProject:dependencies --configuration compile
Lưu ý rằng, chạy gradlew
trong Windows như dưới đây.
gradlew -q dependencies yourProject:dependencies --configuration compile
Kết quả lệnh sẽ cho bạn thấy hệ thống phân cấp cây có thể đọc được của tất cả các phụ thuộc như dưới đây.
compile - Classpath for compiling the main sources.
+--- org.androidannotations:androidannotations-api:3.2
+--- com.android.support:support-annotations:22.1.1
+--- com.squareup:otto:1.3.6
+--- in.srain.cube:grid-view-with-header-footer:1.0.10
+--- com.nostra13.universalimageloader:universal-image-loader:1.9.3
+--- com.github.chrisbanes.photoview:library:1.2.3
+--- org.simpleframework:simple-xml:2.7.1
+--- com.google.android.gms:play-services-base:6.5.+ -> 6.5.87
+--- project :yourProject
| +--- com.loopj.android:android-async-http:1.4.6
| +--- org.apache.httpcomponents:httpmime:4.2.5
| | \--- org.apache.httpcomponents:httpcore:4.2.4
| \--- com.google.code.gson:gson:2.3.1
+--- project :facebook
| \--- com.android.support:appcompat-v7:22.1.1
| \--- com.android.support:support-v4:22.1.1
| \--- com.android.support:support-annotations:22.1.1 -> 22.2.0
Bạn có thể thấy phụ thuộc quá mức và quyết định nên tránh những phụ thuộc nào. Trong ví dụ trên, dòng cuối cùng com.android.support:support-annotations
quà được ghi đè từ 22.1.1
đến 22.2.0
nội bộ.
Để tránh trùng lặp, bạn có thể thêm exclude
mệnh đề trong mỗi dự án build.gradle
tệp.
compile('com.github.chrisbanes.photoview:library:1.2.3') {
exclude group: 'com.android.support'
}
compile('org.simpleframework:simple-xml:2.7.1') {
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
}
compile('com.google.android.gms:play-services-base:6.5.+')
{
exclude module: 'support-v4'
}
Để biết thêm thông tin, bạn có thể xem hướng dẫn tại https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies
Perfect. Trong trường hợp của tôi nó mang lại cho tôi quá nhiều đầu ra, vì vậy Bạn nên thêm một cái gì đó giống như '--configuration compile' tại và. – anber
@anber // đề xuất của bạn được áp dụng. cảm ơn. – Youngjae
Cảm ơn câu trả lời, tiết kiệm thời gian của tôi. –