1

Without Proguard enabled, retrofit2 work properly... but when enabled, application crash...

Here is my Proguard rules:

-dontwarn retrofit2.Platform$Java8
-dontwarn okio.**
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*

-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes EnclosingMethod

-keepclasseswithmembers class * {
    @retrofit2.* <methods>;
}

-keepclasseswithmembers interface * {
    @retrofit2.* <methods>;
}
-keepclassmembers class demirci.omer.butun.gazeteler.siteler.newspapers.data.model.** { <fields>; }
-keep class demirci.omer.butun.gazeteler.siteler.newspapers.data.model.** { <fields>; }
-keep class demirci.omer.butun.gazeteler.siteler.newspapers.data.ApiEndPoint { <fields>; }
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-keep class retrofit2.converter.gson.** { *; }

I have read below question: retrofit2 rule

But I have also use retrofit2 converter with POJO. I think problem occur with this...Found this question: gson-converter

There is two contidion for where problem occur.

Retrofit2 proguard rules is not suitable Or Retrofit2 converter GSON with POJO is not convert data if fields obfuscated

I dont know with which condition problem occur...

here is my api interface:

public interface ApiEndPoint {

    @FormUrlEncoded
    @POST("all_newspaper/get_text.php")
    Call<NewsContentClass> getContent(@Field("url") String url);

    @FormUrlEncoded
    @POST("all_newspaper/add_user_url.php")
    Call<Void> addUserUrl(@Field("app_name") String appName,@Field("mobile_url") String mobile_url,@Field("desktop_url") String desktop_url);
}
Community
  • 1
  • 1
Ucdemir
  • 2,852
  • 2
  • 26
  • 44

2 Answers2

0

Try adding

-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
JohnWowUs
  • 3,053
  • 1
  • 13
  • 20
0

try these rules from the retrofit2 site:

    ########--------Retrofit + RxJava--------#########
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
j2emanue
  • 60,549
  • 65
  • 286
  • 456