gradle 使用GSON和GoogleMap需要哪些ProGuard规则?

6rvt4ljy  于 2023-10-19  发布在  Go
关注(0)|答案(1)|浏览(90)

这是在我升级Gradle之后开始的。创建我的应用的测试版本工作正常。当我创建Release Build时,我的应用崩溃并显示以下错误消息:
致命异常:主要
Process:com.richmondgamesstudio.foraging,PID:22275

java.lang.ClassCastException:com.google.gson.internal.l无法转换为com.google.android.gms.maps.model.LatLng

at com.richmondgamesstudio.foraging.Helper.l.B(未知来源:37)
at y2.d.f(未知源:448)at s2.b.onTransact(未知源:89)
在android.os.Binder.transact(Binder.java:1164)
在fc.c(:com.google.android.gms.dynamite_mapsdynamite@email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)(190800-0):2)
在com.google.maps.api.android.lib6.impl.bg.run(:com.google.android.gms.dynamite_mapsdynamite@email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)(190800-0):1)
在android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
在android.os.Looper.loopOnce(Looper.java:201)在android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
如果我在www.example.com文件中注解掉minifyEnabledshrinkResourcesgradle.build,那么我的发布版本就可以正常工作。我想我需要在我的预备规则里增加一些东西

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
-keep class * implements com.google.gson.GsonBuilder

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken

##---------------End: proguard configuration for Gson  ----------
jv4diomz

jv4diomz1#

添加以下行到我的proguard文件修复了我的问题

-keep class com.yourpackage.datatypes.* { <fields>; }

这篇文章帮助了我:ProGuard for Android and GSON

相关问题