2016-03-15 16 views
39

Tôi đã bật Proguard và tôi đang cố gắng tạo APK và tôi nhận được nhiều cảnh báo và không biết cách giải quyết chúng.Nhận Cảnh báo Với Proguard (Với Thư viện Ngoài)

Tôi đang sử dụng Retrofit, Jsoup và thư viện cổ phiếu khác, tôi nhận được những lời cảnh báo sau đây:

Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 
Warning:okio.Okio: can't find referenced class java.nio.file.Files 
Warning:okio.Okio: can't find referenced class java.nio.file.Path 
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption 
Warning:okio.Okio: can't find referenced class java.nio.file.Path 
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption 
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 
Warning:okio.Okio: can't find referenced class java.nio.file.Path 
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption 
Warning:okio.Okio: can't find referenced class java.nio.file.Path 
Warning:okio.Okio: can't find referenced class java.nio.file.OpenOption 
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 
Warning:retrofit2.Platform$Java8: can't find referenced method 'boolean isDefault()' in library class java.lang.reflect.Method 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandle 
Warning:retrofit2.Platform$Java8: can't find referenced class java.lang.invoke.MethodHandles$Lookup 
Warning:retrofit2.Platform$Java8: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 
Note: the configuration keeps the entry point 'android.support.v7.widget.FitWindowsLinearLayout { void setOnFitSystemWindowsListener(android.support.v7.widget.FitWindowsViewGroup$OnFitSystemWindowsListener); }', but not the descriptor class 'android.support.v7.widget.FitWindowsViewGroup$OnFitSystemWindowsListener' 
Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setAccessibilityDelegateCompat(android.support.v7.widget.RecyclerViewAccessibilityDelegate); }', but not the descriptor class 'android.support.v7.widget.RecyclerViewAccessibilityDelegate' 
Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setAdapter(android.support.v7.widget.RecyclerView$Adapter); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$Adapter' 
Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setRecyclerListener(android.support.v7.widget.RecyclerView$RecyclerListener); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$RecyclerListener' 
Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$LayoutManager' 
Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setRecycledViewPool(android.support.v7.widget.RecyclerView$RecycledViewPool); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$RecycledViewPool' 
Note: the configuration keeps the entry point 'android.support.v7.widget.RecyclerView { void setViewCacheExtension(android.support.v7.widget.RecyclerView$ViewCacheExtension); }', but not the descriptor class 'android.support.v7.widget.RecyclerView$ViewCacheExtension' 
Warning:there were 22 unresolved references to classes or interfaces. 
Warning:there were 1 unresolved references to library class members. 
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first. 

Dưới đây là Proguard tôi:

-keep class * implements android.os.Parcelable { 
    public static final android.os.Parcelable$Creator *; 
} 

##---------------Begin: proguard configuration for Gson ---------- 
# Gson uses generic type information stored in a class file when working with fields. Proguard 
# removes such information by default, so configure it to keep all of it. 
-keepattributes Signature 


# Gson specific classes 
-keep class com.abohani.tdroms.SharedPreferencesTools { *; } 
#-keep class com.google.gson.stream.** { *; } 


# Application classes that will be serialized/deserialized over Gson 
-keep class com.abohani.tdroms.** { *; } 
+0

Bạn nên thêm lớp -keep hoặc dontwarn với okio.Okio như cảnh báo cho biết. –

Trả lời

101

Khi bạn sử dụng ProGuard bạn phải luôn luôn giải quyết tất cả cảnh báo.

Những cảnh báo này cho bạn biết rằng các thư viện tham chiếu một số mã và không có nguồn nào cho điều đó. Điều đó có thể và có thể không ổn. Nó phụ thuộc nếu mã có vấn đề bao giờ được gọi.

Trong trường hợp này, cảnh báo cho Okio và Retrofit2 có thể bị bỏ qua. Gói java.nio.* không khả dụng trên Android và sẽ không bao giờ được gọi. Bạn có thể bỏ qua những cảnh báo đó một cách an toàn. Các lớp Java 8 cũng sẽ không được sử dụng.

Thêm này để cấu hình ProGuard của bạn, nó sẽ khắc phục vấn đề của bạn:

-dontwarn okio.** 
-dontwarn retrofit2.Platform$Java8 
+0

SDK Android 7 hỗ trợ Java 8 và java.nio. Câu trả lời này có đúng không? (Disclaimer: Tôi biết rất ít về Okio, xin lỗi nếu đây là một câu hỏi ngu ngốc). – Blaisorblade

+1

Có, nó vẫn giữ. Android SDK chứa một số lớp từ 'java.nio', nhưng nó không chứa bất kỳ thứ gì từ' java.nio.file'. – Tomik

0

trang Retrofit đã lưu ý về Proguard xây dựng:

vBulletin gọi Class.forName trên các loại đó không tồn tại trên Android để xác định nền tảng.

retrofit2.Platform -dontnote

vBulletin sử dụng khi chạy trên Java 8 máy ảo. Sẽ không được sử dụng khi chạy.

-dontwarn retrofit2.Platform $ Java8

Giữ lại thông tin kiểu chung chung để sử dụng bởi sự phản xạ bởi bộ chuyển đổi và bộ điều hợp.

-keepattributes Chữ ký

Giữ lại các trường hợp ngoại lệ đã được khai báo để sử dụng bởi một phiên bản Proxy.

-keepattributes Exceptions

kiểm tra xem nó ở đây: http://square.github.io/retrofit/

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