当前位置: 首页 > 知识库问答 >
问题:

java.lang.NoClassDefFoundError:升级Gradle和Android Gradle插件时无法解决:Ljava/lang/Math8

林英朗
2023-03-14

我正在开发一个带有Gradle版本的7.1.1和Android Gradle Plugin版本的7.0.0的Android应用程序。当我升级到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()

构建。gradle文件被设置为目标JVM 1.8,并使用desugaring。

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"

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

共有1个答案

潘皓
2023-03-14

Desugaring会影响“java.time的一个子集”,因此升级到最新版本的desugar_jdk_libs应该可以解决这个问题。发帖时,最新版本是1.1.5

工具书类

  • Java 8 API desugaring支持(Android Gradle插件4.0.0)
 类似资料: