1

我正在开发一个带有 Gradle 版本7.1.1和 Android Gradle Plugin 版本的Android 应用程序7.0.0。当我升级到 Gradle 版本7.2和 Android Gradle Plugin 版本7.1.1时,我收到以下错误。

2022-03-02 17:15:47.072 25300-25300/... E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ..., PID: 25300
    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/Math8;
        at j$.time.Instant.ofEpochSecond(Instant.java:328)
        at j$.time.Instant.<clinit>(Instant.java:232)
        at j$.time.Instant.ofEpochMilli(Instant.java:344)
        ...
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.Math8" on path: DexPathList[[zip file "/data/app/...-NbMXeOj8LumN03n4IMK5Cw==/base.apk"],nativeLibraryDirectories=[/data/app/...-NbMXeOj8LumN03n4IMK5Cw==/lib/x86, /data/app/...-NbMXeOj8LumN03n4IMK5Cw==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at j$.time.Instant.ofEpochSecond(Instant.java:328) 
        at j$.time.Instant.<clinit>(Instant.java:232) 
        at j$.time.Instant.ofEpochMilli(Instant.java:344) 
        ...
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

错误来自此代码:

fun toLocalStartOfDay(date: Long): Instant = Instant.ofEpochMilli(date)
    .atZone(ZoneId.systemDefault())
    .withHour(0)
    .withMinute(0)
    .withSecond(0)
    .withNano(0)
    .toInstant()

build.gradle文件设置为针对 JVM 1.8 并进行了脱糖。

compileOptions {
    coreLibraryDesugaringEnabled = true
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

desugar_jdk_libs版本设置1.0.9为。

versions.androidDesugaringVersion = '1.0.9'
support.android_desugaring = "com.android.tools:desugar_jdk_libs:$versions.androidDesugaringVersion"

为什么升级会导致此错误?

4

1 回答 1

0

脱糖效果“的一个子集java.time”,所以升级到最新版本desugar_jdk_libs应该可以解决这个问题。在发布时,最新版本是1.1.5.

参考

于 2022-03-03T16:01:16.257 回答