takk
takk

Reputation: 23

Android proguard Gson Error

An error occurred while trying to make the app as a release. Errors are likely to continue in the coming Gson. While retrofit guard as professional use official But because of what I do not know why.

These libraries are currently in use.

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
apt 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:support-annotations:24.1.1'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'com.trello:rxlifecycle:0.6.1'
compile 'com.trello:rxlifecycle-components:0.6.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.3.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'jp.wasabeef:glide-transformations:2.0.1'
compile 'com.github.captain-miao:autofittextview:0.2.2'
compile 'com.artemzin.rxjava:proguard-rules:1.1.9.0'

and ProGuard also being used as follows:

-libraryjars libs
-keepattributes SourceFile,LineNumberTable
-dontwarn okio.**
-dontnote retrofit2.Platform
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
-dontwarn retrofit2.Platform$Java8
-keepattributes Signature
-keepattributes Exceptions
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.examples.android.model.** { *; }
-keep class com.google.gson.** { *; }

apk is made well. However, if you run the following error occurs.

STACK_TRACE=java.lang.AssertionError: java.lang.NoSuchFieldException: OPTION
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.<init>       (TypeAdapters.java:808)
at com.google.gson.internal.bind.TypeAdapters$30.create(TypeAdapters.java:834)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at d.b.a.a.a(GsonConverterFactory.java:63)
at d.at.a(Retrofit.java:325)
at d.at.b(Retrofit.java:308)
at d.ax.c(ServiceMethod.java:704)
at d.ax.a(ServiceMethod.java:167)
at d.at.a(Retrofit.java:166)
at d.au.invoke(Retrofit.java:145)
at java.lang.reflect.Proxy.invoke(Proxy.java:393)
at $Proxy2.b(Unknown Source)

Retro -fit are using this.

            net = new Retrofit.Builder()
                .baseUrl(SERVER_URL)
                .addConverterFactory(GsonConverterFactory.create()) //Json Parser
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) //Rxandroid
                .client(client)
                .build()
                .create(xxx.class);

Upvotes: 2

Views: 1246

Answers (1)

Geralt_Encore
Geralt_Encore

Reputation: 3771

You need to change this line

-keep class com.google.gson.examples.android.model.** { *; }

to actual package in your application where your models, which you serialize/deserialize via GSON are.

Upvotes: 4

Related Questions