You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

旧Android应用使用Corretto 1.8.0_402编译触发编译器异常求助

旧Android应用使用Corretto 1.8.0_402编译时AssertionError问题解决

问题详情

维护一款无法升级的旧Android应用,目标Java版本为1.8,使用Java Corretto 1.8.0_402编译时触发如下编译器异常:

An exception has occurred in the compiler (1.8.0_402). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
    at com.sun.tools.javac.util.Assert.error(Assert.java:133)
    at com.sun.tools.javac.code.TypeAnnotations.annotationType(TypeAnnotations.java:231)
    at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.separateAnnotationsKinds(TypeAnnotations.java:294)
    at com.sun.tools.javac.code.TypeAnnotations$TypeAnnotationPositions.visitMethodDef(TypeAnnotations.java:1066)

项目Gradle核心配置如下:

compileSdkVersion 33
buildToolsVersion "33.0.0"
defaultConfig {
    minSdkVersion 19
    targetSdkVersion 33
    versionCode 20114
    versionName "2.2.2"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

已尝试相关社区解决方案但无效,需新的解决思路。

解决方案

  • 降低Corretto版本至1.8.0_301及以下:高版本Corretto 1.8引入了Java模块相关注解的处理逻辑,旧项目依赖中可能携带MODULE属性注解,导致编译器无法识别。切换到1.8.0_301或更早的稳定版本(如1.8.0_292)可规避该断言错误。
  • 添加Gradle编译参数禁用模块注解检查:在app模块的build.gradle中补充编译配置,跳过相关注解的校验逻辑:
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
        compilerArgs.add("-Xlint:-options")
        compilerArgs.add("-J-Dsun.lang.ClassLoader.allowArraySyntax=true")
    }
}
  • 排查并替换冲突依赖:检查项目依赖库,若存在引入Java 9+ MODULE注解的第三方库,尝试降级到兼容Java 8的版本,或直接排除该依赖的模块注解相关部分。
  • 切换至Oracle JDK 1.8旧版本:若Corretto高版本兼容性问题无法解决,尝试使用Oracle官方JDK 1.8的旧版本(如1.8.0_281),部分场景下可解决此类编译器断言异常。

内容的提问来源于stack exchange,提问作者Dinitha Nishadya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:01:20