簡體   English   中英

java.lang.NoClassDefFoundError:在 Android 6

[英]java.lang.NoClassDefFoundError: on Android 6

應用程序在運行 android 9 的 Nexus6P 上運行良好。我正在嘗試在 Nexus 5 (Android 6) 上運行應用程序,但出現以下錯誤:

Caused by: java.lang.NoClassDefFoundError: org.openmined.syft.networking.datamodels.syft.AuthenticationResponseSerializer$deserialize$data$1$1
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at org.openmined.syft.networking.datamodels.syft.AuthenticationResponseSerializer$deserialize$data$1.invoke(AuthenticationDataModels.kt:66)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at org.openmined.syft.networking.datamodels.syft.AuthenticationResponseSerializer$deserialize$data$1.invoke(AuthenticationDataModels.kt:55)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at kotlinx.serialization.json.JsonElementBuildersKt.json(JsonElementBuilders.kt:14)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at org.openmined.syft.networking.datamodels.syft.AuthenticationResponseSerializer.deserialize(AuthenticationDataModels.kt:65)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at org.openmined.syft.networking.datamodels.syft.AuthenticationResponseSerializer.deserialize(AuthenticationDataModels.kt:55)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:34)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at kotlinx.serialization.json.internal.StreamingJsonInput.decodeSerializableValue(StreamingJsonInput.kt:33)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at kotlinx.serialization.CoreKt.decode(Core.kt:80)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at kotlinx.serialization.json.Json.parse(Json.kt:126)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at kotlinx.serialization.json.Json$Companion.parse(Json.kt:178)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at com.jakewharton.retrofit2.converter.kotlinx.serialization.Serializer$FromString.fromResponseBody(Serializer.kt:18)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at com.jakewharton.retrofit2.converter.kotlinx.serialization.DeserializationStrategyConverter.convert(DeserializationStrategyConverter.kt:11)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at com.jakewharton.retrofit2.converter.kotlinx.serialization.DeserializationStrategyConverter.convert(DeserializationStrategyConverter.kt:7)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at retrofit2.OkHttpCall.execute(OkHttpCall.java:188)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:45)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.Observable.subscribe(Observable.java:12267)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.Observable.subscribe(Observable.java:12267)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.Single.subscribe(Single.java:3603)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
05-08 12:57:26.776 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
05-08 12:57:26.777 15456-15592/org.openmined.syft.demo W/System.err:     at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
05-08 12:57:26.777 15456-15592/org.openmined.syft.demo W/System.err:    ... 6 more

數據模型

@Serializer(forClass = AuthenticationResponse::class)
internal class AuthenticationResponseSerializer : KSerializer<AuthenticationResponse> {
    private val json = Json(JsonConfiguration.Stable)
    override val descriptor: SerialDescriptor
        get() = SerialClassDescImpl("AuthResponseSerializer")

    override fun deserialize(decoder: Decoder): AuthenticationResponse {
        val input = decoder as? JsonInput
                    ?: throw SerializationException("This class can be loaded only by Json")
        val response = input.decodeJson() as? JsonObject
                       ?: throw SerializationException("Expected JsonObject")
        val data = json {
            response.forEach { key, value ->
                if (key != "status")
                    key to value
            }
        }
        return if (response.getPrimitive("status").content == AUTH_SUCCESS)
            json.parse(
                AuthenticationResponse.AuthenticationSuccess.serializer(),
                data.toString()
            )
        else
            json.parse(AuthenticationResponse.AuthenticationError.serializer(), data.toString())
    }

    override fun serialize(encoder: Encoder, obj: AuthenticationResponse) {
        val output = encoder as? JsonOutput
                     ?: throw SerializationException("This class can be saved only by Json")
        when (obj) {
            is AuthenticationResponse.AuthenticationSuccess -> output.encodeJson(
                json.toJson(
                    AuthenticationResponse.AuthenticationSuccess.serializer(),
                    obj
                )
            )
            is AuthenticationResponse.AuthenticationError ->
                output.encodeJson(
                    json.toJson(
                        AuthenticationResponse.AuthenticationError.serializer(),
                        obj
                    )
                )
        }
    }
}

任何人都可以評論可能是什么問題嗎? kotlinx.serialization庫?

謝謝

嘗試將注釋@Keep添加到您的 Serializable class。

@Serializable
@Keep
class AuthenticationResponse {
// ...
}...

編譯器可能認為代碼未使用。 @Keep 表示在構建時縮小代碼時不應刪除帶注釋的元素

另一種解決方案

  1. 到您的 proguard-rules.pro (更多信息):

kotlinx-serialization-json 特定的。 如果您有 java.lang.NoClassDefFoundError kotlinx.serialization.json.JsonObjectSerializer,請添加此內容

-keepclassmembers class kotlinx.serialization.json.** {
    *** Companion;
}
-keepclasseswithmembers class kotlinx.serialization.json.** {
    kotlinx.serialization.KSerializer serializer(...);
}
  1. Kotlin 和 Kotlinx.serialization 之間的不匹配
  2. 和另一個鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM