代码之家  ›  专栏  ›  技术社区  ›  oolyvi Devrath

类型不匹配:推断的类型为String,但应为KaptOptions

  •  0
  • oolyvi Devrath  · 技术社区  · 2 年前

    当我使用最新版本的安卓工作室时,我面临着这个问题。在我的另一个项目中,实现了完全相同的依赖关系,但并没有问题。在这里,我面临着这些错误

    Type mismatch: inferred type is String but KaptOptions was expected Type mismatch: inferred type is () -> Unit but KaptOptions was expected Unresolved reference: correctErrorTypes

    这是我的build.gradle(模块)文件:

    import org.jetbrains.kotlin.kapt3.base.Kapt.kapt
    
    plugins {
        id("com.android.application")
        id("org.jetbrains.kotlin.android")
        id ("kotlin-kapt")
        id ("com.google.dagger.hilt.android")
    }
    
    android {
        namespace = "com.urahimli.booklistbeta"
        compileSdk = 34
    
        defaultConfig {
            applicationId = "com.urahimli.booklistbeta"
            minSdk = 26
            targetSdk = 34
            versionCode = 1
            versionName = "1.0"
    
            testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
            vectorDrawables {
                useSupportLibrary = true
            }
        }
    
        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
        }
        composeOptions {
            kotlinCompilerExtensionVersion = "1.3.2"
        }
        packaging {
            resources {
                excludes += "/META-INF/{AL2.0,LGPL2.1}"
            }
        }
    }
    
    dependencies {
    
        implementation("androidx.core:core-ktx:1.10.1")
        implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
        implementation("androidx.activity:activity-compose:1.7.2")
        implementation(platform("androidx.compose:compose-bom:2023.03.00"))
        implementation("androidx.compose.ui:ui")
        implementation("androidx.compose.ui:ui-graphics")
        implementation("androidx.compose.ui:ui-tooling-preview")
        implementation("androidx.compose.material3:material3")
        testImplementation("junit:junit:4.13.2")
        androidTestImplementation("androidx.test.ext:junit:1.1.5")
        androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
        androidTestImplementation(platform("androidx.compose:compose-bom:2023.03.00"))
        androidTestImplementation("androidx.compose.ui:ui-test-junit4")
        debugImplementation("androidx.compose.ui:ui-tooling")
        debugImplementation("androidx.compose.ui:ui-test-manifest")
    
    
        // Compose dependencies
        implementation ("androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1")
        implementation ("androidx.navigation:navigation-compose:2.7.0")
        implementation ("androidx.hilt:hilt-navigation-compose:1.1.0-alpha01")
    
        // Coroutines
        implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2")
        implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.2")
    
        //Dagger - Hilt
        implementation ("com.google.dagger:hilt-android:2.46.1")
        kapt ("com.google.dagger:hilt-android-compiler:2.46.1")
        kapt ("androidx.hilt:hilt-compiler:1.0.0")
    
        // Room
        implementation ("androidx.room:room-runtime:2.5.2")
        kapt ("androidx.room:room-compiler:2.5.2")
    
        // Kotlin Extensions and Coroutines support for Room
        implementation ("androidx.room:room-ktx:2.5.2")
    
        //material 3
        implementation("androidx.compose.material3:material3:1.1.1")
        implementation("androidx.compose.material:material-icons-extended:1.5.0")
    }
    
    kapt {
        correctErrorTypes = true
    }
    

    这是我的build.gradle(Project)文件:

    plugins {
        id("com.android.application") version "8.1.0" apply false
        id("org.jetbrains.kotlin.android") version "1.8.10" apply false
    
        id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false
    }
    

    正如我所说,我认为所有这些事情都发生在创建一个新项目之后。关于我的旧项目,没有问题。我需要你的解决方案

    1 回复  |  直到 2 年前
        1
  •  1
  •   Scott Stanchfield    2 年前

    你失踪了

    id("com.google.dagger.hilt.android") version "2.47" apply false
    

    在您的项目级别 build.gradle.kts 文件

    我测试了添加它,这似乎可以修复它。