google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.86k stars 268 forks source link

Dagger hilt options were not recognized by ksp #2002

Closed petukhoudzmitry closed 3 months ago

petukhoudzmitry commented 3 months ago

During my application build I'm getting this warning:

The following options were not recognized by any processor: '[dagger.fastInit, dagger.hilt.android.internal.disableAndroidSuperclassValidation, dagger.hilt.android.internal.projectType, dagger.hilt.internal.useAggregatingRootProcessor]'

I got it after migration from KAPT to KSP and it seems to be a problem with KSP since the related issue was closed with no solution provided.

My project level build.gradle.kts file:

plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.jetbrains.kotlin.android) apply false
    alias(libs.plugins.dagger.hilt.android) apply false
    alias(libs.plugins.jetbrainsCompose) apply false
    alias(libs.plugins.compose.compiler) apply false
    alias(libs.plugins.ksp) apply false
}

buildscript {
    ...
    dependencies {
    }
}
...

My module level buid.gradle.kts file:

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
    alias(libs.plugins.dagger.hilt.android)
    alias(libs.plugins.jetbrainsCompose)
    alias(libs.plugins.compose.compiler)
    alias(libs.plugins.ksp)
}
...
dependencies {
...
    implementation(libs.hilt.android)
    ksp(libs.hilt.android.compiler)
...
}

My libs.versions.toml file:

[versions]
ksp-version = "2.0.0-1.0.21"
agp = "8.5.1"
kotlin = "2.0.0"
hilt = "2.51.1"
jetbrains-compose = "1.7.0-alpha01"
...

[libraries]
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
...

[plugins]
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp-version" }
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }
jetbrainsCompose  = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

The warning appears during compileFullDebugJavaWithJavac process. There are no warnings with KAPT.

peteragurto commented 1 month ago

Is there any solutions to this warning with ksp?

petukhoudzmitry commented 1 month ago

Is there any solutions to this warning with ksp?

It happens if you use both KAPT and KSP tools at the same time. If you want to use KSP and get rid of this warning, you need to migrate all your KAPT to KSP compatible dependencies and remove KAPT from your imports. Also make sure to use the latest versions of KSP, its dependencies and gradle/maven

peteragurto commented 1 month ago

I have all my dependencies working with KSP, I am suspicious with the alpha support of KSP for dagger and hilt, which are dependencies that I am using in my project.

By the way, would you like to help me with my dependencies? I can show you the code of my gradle.

Waiting for your response.

petukhoudzmitry commented 1 month ago

I have all my dependencies working with KSP, I am suspicious with the alpha support of KSP for dagger and hilt, which are dependencies that I am using in my project.

By the way, would you like to help me with my dependencies? I can show you the code of my gradle.

Waiting for your response.

Sure, I can check your code as soon as I'll have free time. I also used dagger and hilt but I managed to get rid off this warning while keeping them in the project.

peteragurto commented 1 month ago

Ok, here are the libs and gradle codes:

[versions]
agp = "8.4.1"
kotlin = "2.0.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.8.2"
activityCompose = "1.9.0"
composeBom = "2024.06.00"
navComposeVersion = "2.7.7"
room = "2.6.1"
ksp = "2.0.0-1.0.21"
hilt = "2.48.1"
hiltNav = "1.2.0"
dataStore = "1.1.1"
workVersion = "2.9.1"
hiltAndroidx = "1.2.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-material-icons-extended = { group = 'androidx.compose.material', name = 'material-icons-extended', version = '1.7.0-beta03' }
# Navegación
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navComposeVersion" }
hilt-navigation = { group = "androidx.hilt", name = "hilt-navigation", version.ref = "hiltNav" }
hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNav" }
# Room - Base de datos
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
androidx-room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" }
# Dagger Hilt - DI
android-dagger-hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
dagger-compiler = { group = "com.google.dagger", name = "dagger-compiler", version.ref = "hilt" }
dagger-hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
# DataStore
androidx-datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "dataStore" }
# WorkManager
androidx-work-runtime = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workVersion" }
dagger-hilt-androidx = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltAndroidx" }
androidx-hilt-work = { group = "androidx.hilt", name = "hilt-work", version.ref = "hiltAndroidx" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp-processor = { id = "com.google.devtools.ksp", version.ref = "ksp" }
dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }

Also

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
    alias(libs.plugins.compose.compiler)
    alias(libs.plugins.dagger.hilt.android)
    alias(libs.plugins.ksp.processor)
}

android {
    namespace = "com.--------------"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.-----------"
        minSdk = 30
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    configurations {
        create("cleanedAnnotations")
        implementation {
            exclude(group = "org.jetbrains", module = "annotations")
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    testImplementation(libs.junit)
    testImplementation(libs.androidx.room.testing)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    androidTestImplementation(platform(libs.androidx.compose.bom))
    androidTestImplementation(libs.androidx.ui.test.junit4)
    debugImplementation(libs.androidx.ui.tooling)
    debugImplementation(libs.androidx.ui.test.manifest)
    implementation(libs.androidx.material.icons.extended)
    // Navegación
    implementation(libs.androidx.navigation.compose)
    implementation(libs.hilt.navigation)
    implementation(libs.hilt.navigation.compose)
    // Room
    implementation(libs.androidx.room.runtime)
    annotationProcessor(libs.androidx.room.compiler)
    implementation(libs.androidx.room.ktx)
    // Dagger Hilt
    implementation(libs.android.dagger.hilt)
    // DataStore
    implementation(libs.androidx.datastore.preferences)
    // Work Manager
    implementation(libs.androidx.work.runtime)
    implementation(libs.androidx.hilt.work)

    ksp(libs.dagger.compiler)
    ksp(libs.dagger.hilt.android.compiler)
    ksp(libs.androidx.room.compiler)
    ksp(libs.dagger.hilt.androidx)
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.jetbrains.kotlin.android) apply false
    alias(libs.plugins.ksp.processor) apply false
    alias(libs.plugins.dagger.hilt.android) apply false
}

Well, these are my codes, but, apart from the problem related to the dagger warnings, I also have some small problems, for example when inspecting the application, smany "Accessin hidden method of..." appear in the logcat referencing "greylist" that it is not supposed to access, so I may have libraries that are not compatible with each other or maybe deprecated, if you could help me analyze the dependencies I have, I would be very grateful.

MusaibShabir commented 1 month ago

i am facing the same issue with: kotlin = "2.0.20" agp = "8.6.0" featureDelivery = "2.1.0" ksp = "2.0.20-1.0.25"

petukhoudzmitry commented 1 month ago

Ok, here are the libs and gradle codes:

[versions]
agp = "8.4.1"
kotlin = "2.0.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.8.2"
activityCompose = "1.9.0"
composeBom = "2024.06.00"
navComposeVersion = "2.7.7"
room = "2.6.1"
ksp = "2.0.0-1.0.21"
hilt = "2.48.1"
hiltNav = "1.2.0"
dataStore = "1.1.1"
workVersion = "2.9.1"
hiltAndroidx = "1.2.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
androidx-material-icons-extended = { group = 'androidx.compose.material', name = 'material-icons-extended', version = '1.7.0-beta03' }
# Navegación
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navComposeVersion" }
hilt-navigation = { group = "androidx.hilt", name = "hilt-navigation", version.ref = "hiltNav" }
hilt-navigation-compose = { group = "androidx.hilt", name = "hilt-navigation-compose", version.ref = "hiltNav" }
# Room - Base de datos
androidx-room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" }
androidx-room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" }
androidx-room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" }
androidx-room-testing = { group = "androidx.room", name = "room-testing", version.ref = "room" }
# Dagger Hilt - DI
android-dagger-hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
dagger-compiler = { group = "com.google.dagger", name = "dagger-compiler", version.ref = "hilt" }
dagger-hilt-android-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }
# DataStore
androidx-datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "dataStore" }
# WorkManager
androidx-work-runtime = { group = "androidx.work", name = "work-runtime-ktx", version.ref = "workVersion" }
dagger-hilt-androidx = { group = "androidx.hilt", name = "hilt-compiler", version.ref = "hiltAndroidx" }
androidx-hilt-work = { group = "androidx.hilt", name = "hilt-work", version.ref = "hiltAndroidx" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
ksp-processor = { id = "com.google.devtools.ksp", version.ref = "ksp" }
dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }

Also

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
    alias(libs.plugins.compose.compiler)
    alias(libs.plugins.dagger.hilt.android)
    alias(libs.plugins.ksp.processor)
}

android {
    namespace = "com.--------------"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.-----------"
        minSdk = 30
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
    }

    configurations {
        create("cleanedAnnotations")
        implementation {
            exclude(group = "org.jetbrains", module = "annotations")
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    testImplementation(libs.junit)
    testImplementation(libs.androidx.room.testing)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    androidTestImplementation(platform(libs.androidx.compose.bom))
    androidTestImplementation(libs.androidx.ui.test.junit4)
    debugImplementation(libs.androidx.ui.tooling)
    debugImplementation(libs.androidx.ui.test.manifest)
    implementation(libs.androidx.material.icons.extended)
    // Navegación
    implementation(libs.androidx.navigation.compose)
    implementation(libs.hilt.navigation)
    implementation(libs.hilt.navigation.compose)
    // Room
    implementation(libs.androidx.room.runtime)
    annotationProcessor(libs.androidx.room.compiler)
    implementation(libs.androidx.room.ktx)
    // Dagger Hilt
    implementation(libs.android.dagger.hilt)
    // DataStore
    implementation(libs.androidx.datastore.preferences)
    // Work Manager
    implementation(libs.androidx.work.runtime)
    implementation(libs.androidx.hilt.work)

    ksp(libs.dagger.compiler)
    ksp(libs.dagger.hilt.android.compiler)
    ksp(libs.androidx.room.compiler)
    ksp(libs.dagger.hilt.androidx)
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.jetbrains.kotlin.android) apply false
    alias(libs.plugins.ksp.processor) apply false
    alias(libs.plugins.dagger.hilt.android) apply false
}

Well, these are my codes, but, apart from the problem related to the dagger warnings, I also have some small problems, for example when inspecting the application, smany "Accessin hidden method of..." appear in the logcat referencing "greylist" that it is not supposed to access, so I may have libraries that are not compatible with each other or maybe deprecated, if you could help me analyze the dependencies I have, I would be very grateful.

I couldn't reproduce any of the mentioned issues. Please provide more information about your gradle configurations and make sure you applied all my advices.

petukhoudzmitry commented 1 month ago

i am facing the same issue with: kotlin = "2.0.20" agp = "8.6.0" featureDelivery = "2.1.0" ksp = "2.0.20-1.0.25"

I also couldn't reproduce any issue for your data.