Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am using the latest kts build tool to learn Android hilt, but kapt seems to have some issues

I am using the latest kts build tool to learn Android hilt, and I have introduced dependencies according to the official tutorial, but kapt seems to have some issues:

This is the root level build.gradle.kts of the project

plugins {
    id("com.android.application") version "8.2.0-alpha04" apply false
    id("com.android.library") version "8.0.0" apply false
    id("org.jetbrains.kotlin.android") version "1.8.20" apply false
    id("com.google.dagger.hilt.android") version "2.44" apply false
}

This is the app build.gradle.kts of the project

import org.jetbrains.kotlin.kapt3.base.Kapt.kapt

plugins {
    id("com.android.application")
    kotlin("kapt")
    id("com.google.dagger.hilt.android")
}

android {
    namespace = "com.example.myapplication"
    compileSdk = 33

    defaultConfig {
        applicationId = "com.example.myapplication"
        minSdk = 29
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    viewBinding {
        enable = true
    }
}

dependencies {

    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    compileOnly("org.projectlombok:lombok:1.18.26")
    annotationProcessor("org.projectlombok:lombok:1.18.26")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.8.0")
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
    implementation("com.google.dagger:hilt-android:2.44")
    kapt("com.google.dagger:hilt-android-compiler:2.44")
}
// Allow references to generated code
kapt {
    correctErrorTypes = true
}

This is an error while building the project

> Configure project :app
e: C:\Users\123\AndroidStudioProjects\MyApplication\app\build.gradle.kts:52:10: Type mismatch: inferred type is String but Action<KaptExtension> was expected

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\123\AndroidStudioProjects\MyApplication\app\build.gradle.kts' line: 52

* What went wrong:
Script compilation error:

  Line 52:     kapt("com.google.dagger:hilt-android-compiler:2.44")
                    ^ Type mismatch: inferred type is String but Action<KaptExtension> was expected

1 error

* Try:

> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> ```

like image 798
1872386506 Avatar asked Sep 02 '25 10:09

1872386506


1 Answers

I have resolved this issue because my project is Java code, so there is no need to introduce kapt.

Write this:

annotationProcessor("com.google.dagger:hilt-android-compiler:2.44")

instead of

kapt("com.google.dagger:hilt-android-compiler:2.44")

You can use dependency injection now.

like image 120
1872386506 Avatar answered Sep 04 '25 02:09

1872386506