【发布时间】:2021-08-10 11:13:35
【问题描述】:
我有一个项目使用 Jackson 进行 JSON 序列化,并且发布版本使用 R8 进行混淆。现在,AGP 4.2.1 一切正常,但更新到 AGP 7.0.0 会在混淆构建中导致此错误:
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Could not compute caller for function:
public final fun setResult(result: com.example.networking.Result?): ud.v defined in com.example.networking.Response[DeserializedSimpleFunctionDescriptor@14aa15e] (member = null)
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(:89)
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(:36)
at kotlin.reflect.jvm.internal.ReflectProperties$LazyVal.invoke(:62)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(:31)
at kotlin.reflect.jvm.internal.KFunctionImpl.getCaller(Unknown Source:7)
at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(:63)
at kotlin.reflect.jvm.ReflectJvmMapping.getKotlinFunction(:136)
at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.hasRequiredMarker(:123)
at com.fasterxml.jackson.module.kotlin.KotlinAnnotationIntrospector.access$hasRequiredMarker(:23)
at com.fasterxml.jackson.module.kotlinAnnotationIntrospector$a.a(:40)
...
(注意:出于隐私原因更改了包和类名。根据映射文件,ud.v 映射到kotlin.Unit)
Response 类看起来像这样:
open class Response {
@JsonSetter
fun setResult(result: Result?) {
// ...
}
}
在 ProGuard / R8 规则中,类保持在这个规则中:
-keep class com.example.networking.** { *: }
更新到 AGP 7.0.0 后会出现什么问题?除了更新 AGP 版本之外,我还有什么需要改变的吗?
编辑:
这是顶层的 build.gradle(不相关的东西省略了):
buildscript {
ext.kotlin_version = '1.5.21'
repositories {
...
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
这是项目级别的 build.gradle(同样,省略了不相关的内容):
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
android {
defaultConfig {
applicationId 'com.example.example'
compileSdkVersion 30
targetSdkVersion 30
minSdkVersion 21
multiDexEnabled true
}
buildFeatures.dataBinding = true
signingConfigs { ... }
buildTypes {
debug {
debuggable true
signingConfig signingConfigs.debugSigning
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.releaseSigning
}
}
dexOptions {
preDexLibraries = false
javaMaxHeapSize "2g"
}
packagingOptions { ... }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
encoding "UTF-8"
}
kotlinOptions {
jvmTarget = "1.8"
}
kapt {
correctErrorTypes true
}
}
dependencies { ... }
【问题讨论】:
-
发布你的 build.gradle
-
@Larrikin 更新了(我希望)build.gradle 文件的相关部分。
-
我在 R8 问题跟踪器中创建了一个issue 196179629。请自行抄送并跟进。
标签: android kotlin jackson android-gradle-plugin android-r8