尝试将应用程序发布为版本时发生错误。 错误可能会在即将到来的 Gson 中继续出现。 同时 retrofit 守卫作为专业使用官方 但不知道为什么。
这些库当前正在使用中。
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'
ProGuard 的使用方式如下:
-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制作得很好。但是,如果运行会出现以下错误。
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)
复古健身正在使用这个。
net = new Retrofit.Builder()
.baseUrl(SERVER_URL)
.addConverterFactory(GsonConverterFactory.create()) //Json Parser
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) //Rxandroid
.client(client)
.build()
.create(xxx.class);
最佳答案
您需要更改此行
-keep 类 com.google.gson.examples.android.model.** { *; }
到您的应用程序中的实际包,您通过 GSON 序列化/反序列化的模型所在的位置。
关于Android proguard Gson 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39220366/