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

添加Room Compiler后Android项目编译失败:NoClassDefFoundError问题

解决Room Compiler编译时ClassNotFoundException: org.jetbrains.annotations.NotNull异常

问题场景

我在Android项目中集成Room组件后,编译过程频繁抛出ClassNotFoundException: org.jetbrains.annotations.NotNull异常,导致编译失败无法完成。

当时我的app/build.gradle相关配置如下:

android{
 compileSdkVersion 27
 buildToolsVersion '27.0.2'
}
dependencies {
 roomVersion = '1.0.0'
 implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
 annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
 implementation "android.arch.persistence.room:rxjava2:$rootProject.roomVersion"
}

排查与解决过程

经过仔细检查项目配置,我发现app/build.gradle中存在一段全局依赖排除配置:

configurations {
    all*.exclude module: 'annotations'
}

这段配置会强制移除所有依赖中的annotations模块,而Room Compiler在运行时需要依赖org.jetbrains.annotations.NotNull注解类,该类恰好属于被排除的annotations模块,这就是导致编译异常的根本原因。

解决方法:直接移除上述configurations代码块,重新执行编译操作,问题即可顺利解决。

内容的提问来源于stack exchange,提问作者MARWAN AMEEN

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 03:34:22