作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我关注了https://github.com/square/moshi添加对 moshi 和 proguard 规则的 gradle 依赖,然后我编写代码来验证。
data class Car(
@Json(name = "low_speed") val lowSpeed: Int,
@Json(name = "high_speed") val highSpeed: Int
)
val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()
val jsonAdapter = moshi.adapter(Car::class.java)
val json = "{\"low_speed\": 10, \"high_speed\": 20}"
val car = jsonAdapter.fromJson(json)
if (car != null) {
Toast.makeText(this, "${car.lowSpeed}+${car.highSpeed}", Toast.LENGTH_LONG).show()
}
# 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
# Common Stuff to Keep
-keepattributes *Annotation*
-keepattributes JavascriptInterface
# OkHttp
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-dontwarn org.codehaus.mojo.animal_sniffer.*
-dontwarn okhttp3.internal.platform.ConscryptPlatform
# okIo
-dontwarn okio.**
#moshi
# JSR 305 annotations are for embedding nullability information.
-keepclasseswithmembers class * {
@com.squareup.moshi.* <methods>;
}
-keep @com.squareup.moshi.JsonQualifier interface *
# Enum field names are used by the integrated EnumJsonAdapter.
# values() is synthesized by the Kotlin compiler and is used by EnumJsonAdapter indirectly
# Annotate enums with @JsonClass(generateAdapter = false) to use them with Moshi.
-keepclassmembers @com.squareup.moshi.JsonClass class * extends java.lang.Enum {
<fields>;
**[] values();
}
#moshi-kotlin
-keep class kotlin.reflect.jvm.internal.impl.builtins.BuiltInsLoaderImpl
-keepclassmembers class kotlin.Metadata {
public <methods>;
}
// moshi
implementation("com.squareup.moshi:moshi:1.9.2")
implementation("com.squareup.moshi:moshi-kotlin:1.9.2")
// okhttp
implementation "com.squareup.okhttp3:okhttp:3.10.0"
最佳答案
尝试添加:
@JsonClass(generateAdapter = false)
和 将这些行添加到 proguard:
-keepclassmembernames @com.squareup.moshi.JsonClass class * extends java.lang.Enum {
<fields>;
}
信用->
https://github.com/square/moshi/issues/689
关于android - Moshi Json 注释不适用于 proguard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60166217/
我是一名优秀的程序员,十分优秀!