我在从 Android Gradle Plugin (AGP) 7.4.2 迁移到 8.2 以及 Java 11 迁移到 17 时遇到混淆问题:Unable to create @Body converter for class package.api.data.device.DevicesBody (parameter #1) for method a.a
除了 API 调用之外,一切都运行良好。我将 Retrofit 2 与 Kotlin 序列化 (kotlinx.serialization) 结合使用。
// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0" // Retrofit
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2" // OkHttp Logging Interceptor
// Kotlin Serialization
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1" // Kotlin Serialization JSON
implementation "com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:0.8.0" // Retrofit 2 Kotlin Serialization Converter
Run Code Online (Sandbox Code Playgroud)
它正在禁用混淆minifyEnabled false或添加混淆规则-keep class ** { *; },但这当然不是一个可接受的解决方案。
private …Run Code Online (Sandbox Code Playgroud)