Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchMethodError: getNOT_NULL_ANNOTATIONS() when using KSP for Hilt – Possible Version Incompatibility Issue #2330

Open
tungnk123 opened this issue Feb 9, 2025 · 0 comments

Comments

@tungnk123
Copy link

Hi Dagger Hilt Team,

I am encountering an issue when switching Hilt’s annotation processing from KAPT to KSP in my project. My setup uses KSP for Room, and I attempted to also use KSP for Hilt’s compiler by replacing:

kapt(libs.hilt.android.compiler)

with

ksp(libs.hilt.android.compiler)

However, this change causes the build to fail with the following error during KSP processing:

> Task :app:kspDebugKotlin
e: java.lang.NoSuchMethodError: 'java.util.List org.jetbrains.kotlin.load.java.JvmAnnotationNamesKt.getNOT_NULL_ANNOTATIONS()'
    at com.google.devtools.ksp.symbol.impl.java.KSTypeReferenceJavaImpl.resolve(KSTypeReferenceJavaImpl.kt:134)
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspTypeElement$superInterfaces$2$1.invoke(KspTypeElement.kt:123)
    at dagger.spi.internal.shaded.androidx.room.compiler.processing.ksp.KspTypeElement$superInterfaces$2$1.invoke(KspTypeElement.kt:122)
    ...

It appears that a required method (getNOT_NULL_ANNOTATIONS()) is missing from the Kotlin runtime, which suggests a potential version incompatibility between the following components:

  • Android Gradle Plugin (AGP)
  • Kotlin
  • Dagger Hilt (and Hilt Android Compiler)
  • KSP

Project Configuration:

  • ViewModel & Application:
    I have a minimal MainViewModel annotated with @HiltViewModel:

    package com.tungnk123.orpheus.ui
    
    import androidx.lifecycle.ViewModel
    import dagger.hilt.android.lifecycle.HiltViewModel
    import javax.inject.Inject
    
    @HiltViewModel
    class MainViewModel @Inject constructor() : ViewModel() { }

    My Application class is annotated with @HiltAndroidApp:

    package com.tungnk123.orpheus
    
    import android.app.Application
    import dagger.hilt.android.HiltAndroidApp
    
    @HiltAndroidApp
    class OrpheusApplication : Application() { }
  • Gradle Configuration:
    In my module’s build.gradle.kts, I use both KAPT and KSP plugins:

    plugins {
        alias(libs.plugins.android.application)
        alias(libs.plugins.kotlin.android)
        alias(libs.plugins.kotlin.compose)
        id("dagger.hilt.android.plugin")
        id("org.jetbrains.kotlin.plugin.serialization")
        id("com.google.devtools.ksp")
        id("org.jetbrains.kotlin.kapt")
    }
    
    dependencies {
        // Dagger Hilt
        implementation(libs.hilt.android)
        // Attempting to use KSP for Hilt’s annotation processing:
        ksp(libs.hilt.android.compiler)
        
        // Room dependencies (using KSP):
        implementation(libs.androidx.room.runtime)
        ksp(libs.androidx.room.compiler)
        implementation(libs.androidx.room.ktx)
        
        // Other dependencies...
    }
    
    kapt {
        correctErrorTypes = true
        useBuildCache = false
    }
  • Versions (from my version catalog):

    [versions]
    hiltAndroidCompiler = "2.51.1"
    hiltAndroid = "2.55"
    kotlin = "2.0.0"
    roomRuntime = "2.6.1"
    agp = "8.8.0"
    
    // ... other versions as defined in the catalog

Thank you for your time and assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant