kamikat / moshi-jsonapi

JSON API v1.0 Specification in Moshi.
MIT License
156 stars 34 forks source link

Run onFailure in Signed apk #53

Closed mirmousaviii closed 7 years ago

mirmousaviii commented 7 years ago

I used moshi-jsonapi and I have error in build signed apk (release mode), I used dontwarn in proguard-rules.pro for pass the build signed apk, But my application in signed mode every time run onFailure from Callback. Throwable message: platform java.util.LinkedHashMap<java.lang.String,a.a.a.j> annotated [] requires explicit JsonAdapter to be registered I never have used LinkedHashMap, But when use moshi-jsonapi I have error in build. proguard-rules.pro:

-dontwarn okio.**
-keep class okio.** { *; }

-dontwarn retrofit2.**
-dontwarn org.codehaus.mojo.**
-dontnote retrofit2.Platform
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
-dontwarn retrofit2.Platform$Java8

-keep class retrofit2.** { *; }

-keepattributes Exceptions
-keepattributes Signature
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes EnclosingMethod
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
-keepclasseswithmembers interface * {
    @retrofit2.* <methods>;
}
kamikat commented 7 years ago

Investigated into my project using moshi-jsonapi. Seems that the project is obfuscated completely and everything works just ok...

screen shot 2017-03-03 at 12 42 07 pm

With the library obfuscated as well... (actually, I have no idea about why it's obfuscated after I added these proguard rules)

image

kamikat commented 7 years ago

BTW, the message

platform java.util.LinkedHashMap<java.lang.String,a.a.a.j> annotated [] requires explicit JsonAdapter to be registered

is to say that moshi is trying to deserialize someclass that have a field type of a.a.a.j but moshi could not find an adapter for that type. In most cases, it's a case of Enum that you've ever defined a JsonAdapter for. And maybe you need these proguard rules for moshi if you've defined a custom JsonAdapter:

-keepclassmembers class ** {
    @com.squareup.moshi.FromJson *;
    @com.squareup.moshi.ToJson *;
}
mirmousaviii commented 7 years ago

I use this code in proguard and resolved.

-keepclassmembers public abstract class moe.banana.jsonapi2.** {
   *;
}

Thank you

kamikat commented 7 years ago

But I have no idea why it works 😥😥😥

Anyway, I'll add that to README, thanks.