2014-04-05 31 views
14

Aynı konuya değinen daha yeni sürümler buldum, ancak en son sürümler mevcut cevapların hiçbiri için işe yaramıyor.Proguard artık çalışmıyor Retrofit

Projemde Retrofit kullanıyorum.

Uyarı: retrofit.client.OkClient: Ben araya çalıştığımda aşağıdaki hatayı alıyorum ben kullanıyorum başvurulan sınıf com.squareup.okhttp.OkHttpClient aşağıdaki ancak

bulamıyorum hiçbiri yardımcı oluyor:

-keepattributes Signature 

-keep class retrofit.** { *; } 
-keep class retrofit.http.** { *; } 
-keep class retrofit.client.** { *; } 
-keep class com.squareup.okhttp.** { *; } 
-keep interface com.squareup.okhttp.** { *; } 
-keep class com.google.gson.** { *; } 
-keep class com.google.inject.* { *; } 
-keep class org.apache.http.* { *; } 
-keep class org.codehaus.mojo.** { *; } 
-keep class org.apache.james.mime4j.* { *; } 
-keep class javax.inject.* { *; } 
-keep class sun.misc.Unsafe { *; } 

-libraryjars libs/acra-4.5.0.jar 
-libraryjars libs/radial-menu-v4.jar 

-dontwarn javax.xml.stream.events.** 
-dontwarn rx.** 
-dontwarn org.apache.lang.** 

# Application classes that will be serialized/deserialized over Gson 
-keep class com.example.package.network.** { *; } 

Bu sorunun yakın zamanda herhangi biri vardı ve çözümlendi mi?

cevap

5

Şaşırtıcı görünebilir, ancak bu satırı eklemeyi denediniz mi? (Eğer okhttp kullanmıyorsanız).

-dontwarn com.squareup.okhttp.** 

Şey kendi kütüphaneleri kullanılıyor ne Projeniz bunu kullanmıyorsa, güvenle yok sayabilirsiniz bazı varsayımlar yapabilir ederken böylece Kare, içten ProGuard kullanmaz olduğunu. Picasso ile aynı sorunu yaşadım ve bu benim için düzeltildi.

+0

gibi

-keep class com.google.gson.examples.android.model.** { *; } -keep class com.packagename.your.pojo.models.** { *; } 

keepattributes Bu derleme yapar ancak söz ettik gibi kullanmadığınız eminseniz sadece güvenlidir işlevsellik. Bu cevabı pek çok kişi için olduğu gibi işaretleyeceğim doğru bir –

+0

Model sınıflarını da saklamayı unutma, bu benim için kırdı. – wkarl

46
-keepattributes Signature 
-keepattributes *Annotation* 
-keep class com.squareup.okhttp.** { *; } 
-keep interface com.squareup.okhttp.** { *; } 
-dontwarn com.squareup.okhttp.** 

-dontwarn rx.** 
-dontwarn retrofit.** 
-keep class retrofit.** { *; } 
-keepclasseswithmembers class * { 
    @retrofit.http.* <methods>; 
} 

-keep class sun.misc.Unsafe { *; } 
#your package path where your gson models are stored 
-keep class com.example.models.** { *; } 

Yukarıdaki proguard metnini OKHTTP ile ek donanım için kullandım.

DÜZENLEME: Güzel repo Bu yapılandırma GSON ile güçlendirme için çalışmış birçok popüler kütüphaneler https://github.com/krschultz/android-proguard-snippets

+0

Hey, işiniz hakkında küçük bir açıklama ekleyebilirsiniz. – Runcorn

+0

Benim için '-keepclasseswithmember' önemliydi - eklemeden önce @Path değişkenlerim değiştirilmedi. Teşekkürler! :) – DanielGrech

+0

Benim için -keep sınıfı com.squareup.okhttp olmadan bile çalıştı. ** {*; } -keep arabirimi com.squareup.okhttp. ** {*; } ben de okhttp – netimen

2

için başvurmak için.

#Using for retrofit & gson 
-keep class com.google.gson.** { *; } 
-keep class com.google.inject.** { *; } 
-keep class org.apache.http.** { *; } 
-keep class org.apache.james.mime4j.* { *; } 
-keep class javax.inject.** { *; } 
-keep class retrofit.** { *; } 
-keep class sun.misc.Unsafe { *; } 
-keep class com.google.gson.stream.** { *; } 
-keepclassmembernames interface * { 
    @retrofit.http.* <methods>; 
} 
-keep interface retrofit.** { *;} 
-keep interface com.squareup.** { *; } 
-dontwarn rx.** 
-dontwarn retrofit.** 

artı sadece aşağıdaki gibi PMS mevcut kullanılan tüm POJO sınıfları eklemeniz gerekir. Aşağıda

-keepattributes Exceptions 
-keepattributes InnerClasses 
-keepattributes Signature 
-keepattributes Deprecated 
-keepattributes SourceFile 
-keepattributes LineNumberTable 
-keepattributes *Annotation* 
-keepattributes EnclosingMethod 

A nice discussion about proguard with retrofit goes here