Describe the bug
When attempting to build a project using Room with KSP enabled (in version 3.9.0), the KSP source generation task crashes during the annotation processing phase.
To Reproduce
Enable the KSP plugin/feature in the IDE settings.
Add Room dependencies (room-runtime, room-ktx, room-compiler) version 2.8.4 (or 2.6.x).
Add basic Room annotations (@entity, @dao, @database) to the project.
Run the build process (generateSourcesDebug).
Expected behavior
KSP should successfully generate the Room implementation sources on-device.
Actual behavior
The build fails during ksp: crashed for app with a NoSuchMethodError:
Caused by: java.lang.NoSuchMethodError: No virtual method trySetAccessible()Z in class Ljava/lang/reflect/Constructor; or its super classes (declaration of 'java.lang.reflect.Constructor' appears in /apex/com.android.art/javalib/core-oj.jar)
at androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.typeVarNameConstructor_delegate$lambda$6(KSTypeJavaPoetExt.kt:259)
...
Root Cause Analysis
Newer versions of room-compiler invoke Java Reflection APIs (specifically Constructor.trySetAccessible()) when executed inside the KSP processing environment.
While trySetAccessible() exists in the desktop Java Virtual Machine (JVM), it is missing in Android's runtime environment (ART / Dalvik).
When KSP runs on-device inside ART, calling this reflection method causes an unhandled NoSuchMethodError, preventing KSP from successfully compiling Room databases on mobile.
Environment:
App Version: 3.9.0
Android OS: Android 16
Room Version: 2.8.4 (also reproducible on 2.6.1)
Describe the bug
When attempting to build a project using Room with KSP enabled (in version 3.9.0), the KSP source generation task crashes during the annotation processing phase.
To Reproduce
Enable the KSP plugin/feature in the IDE settings.
Add Room dependencies (room-runtime, room-ktx, room-compiler) version 2.8.4 (or 2.6.x).
Add basic Room annotations (@entity, @dao, @database) to the project.
Run the build process (generateSourcesDebug).
Expected behavior
KSP should successfully generate the Room implementation sources on-device.
Actual behavior
The build fails during ksp: crashed for app with a NoSuchMethodError:
Caused by: java.lang.NoSuchMethodError: No virtual method trySetAccessible()Z in class Ljava/lang/reflect/Constructor; or its super classes (declaration of 'java.lang.reflect.Constructor' appears in /apex/com.android.art/javalib/core-oj.jar)
at androidx.room.compiler.processing.ksp.KSTypeJavaPoetExtKt.typeVarNameConstructor_delegate$lambda$6(KSTypeJavaPoetExt.kt:259)
...
Root Cause Analysis
Newer versions of room-compiler invoke Java Reflection APIs (specifically Constructor.trySetAccessible()) when executed inside the KSP processing environment.
While trySetAccessible() exists in the desktop Java Virtual Machine (JVM), it is missing in Android's runtime environment (ART / Dalvik).
When KSP runs on-device inside ART, calling this reflection method causes an unhandled NoSuchMethodError, preventing KSP from successfully compiling Room databases on mobile.
Environment:
App Version: 3.9.0
Android OS: Android 16
Room Version: 2.8.4 (also reproducible on 2.6.1)