google / ksp

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

Overload resolution ambiguity. All these functions match. #1117

Closed pablobaldez closed 2 years ago

pablobaldez commented 2 years ago

I'm using ksp in my android project and I'm facing an issue that impossibilitates the build All generated code is duplicated after running the command gradlew check in the terminal

I'm using arrow and koin libraries and both generates code by ksp, but somehow the code is duplicated. Here is my app/build.gradle

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    id 'com.google.devtools.ksp'
    id 'kotlin-parcelize'
    id 'kotlinx-serialization'
}

android {
    compileSdk 33

    defaultConfig {
        applicationId "br.com.mob1st.bet"
        minSdk 21
        targetSdk 33
        versionCode 1
        versionName "1.0"

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

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled true
            firebaseCrashlytics {
                mappingFileUploadEnabled false
            }
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs = ["-Xcontext-receivers"]
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_compiler_version
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
    lint {
        checkDependencies true
        textOutput file('stdout')
        textReport true
        ignoreWarnings false
    }
    namespace 'br.com.mob1st.bet'

    applicationVariants.all { variant ->
        variant.sourceSets.kotlin.each {
            it.srcDirs += "build/generated/ksp/${variant.name}/kotlin"
        }
    }
}

dependencies {

    // android core
    implementation 'androidx.core:core-ktx:1.9.0'

    // lifecycle
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"

    // compose
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
    implementation 'androidx.compose.material3:material3:1.0.0-beta03'
    implementation 'androidx.activity:activity-compose:1.6.0'
    implementation "androidx.navigation:navigation-compose:2.5.2"

    // coil
    implementation "io.coil-kt:coil-compose:2.2.1"

    // accompanist
    implementation "com.google.accompanist:accompanist-systemuicontroller:$accompaninst_version"

    // koin
    implementation "io.insert-koin:koin-android:$koin_version"
    implementation "io.insert-koin:koin-androidx-compose:$koin_version"
    implementation "io.insert-koin:koin-annotations:$koin_ksp_version"
    ksp "io.insert-koin:koin-ksp-compiler:$koin_ksp_version"

    // app startup
    implementation "androidx.startup:startup-runtime:1.1.1"

    // firebase & play services
    implementation platform('com.google.firebase:firebase-bom:30.3.1')
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-firestore-ktx'
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'com.google.firebase:firebase-config-ktx'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4'

    // timber
    implementation 'com.jakewharton.timber:timber:5.0.1'

    // arrow
    implementation(platform("io.arrow-kt:arrow-stack:$arrow_version"))
    implementation("io.arrow-kt:arrow-core")
    implementation("io.arrow-kt:arrow-optics")
    ksp("io.arrow-kt:arrow-optics-ksp-plugin:$arrow_version")

    // serialization
    implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0'

    // unit tests
    testImplementation 'junit:junit:4.13.2'
    testImplementation "io.insert-koin:koin-test:$koin_version"
    testImplementation "io.insert-koin:koin-test-junit4:$koin_version"

    // android tests
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}
neetopia commented 2 years ago

if you are seeing duplicated code generated, one possibility is that you are running multiple android build variants tasks, each generates same code into its own generated folder, can you try to run only a certain build variant to see if issue resolves?

pablobaldez commented 2 years ago

I found the problem. I replaced it:

applicationVariants.all { variant ->
        variant.sourceSets.kotlin.each {
            it.srcDirs += "build/generated/ksp/${variant.name}/kotlin"
        }
    }

by it

applicationVariants.configureEach { variant ->
        kotlin.sourceSets {
            getByName(name) {
                kotlin.srcDir("build/generated/ksp/${variant.name}/kotlin")
            }
        }
    }

then it stopped to generate the code for all variants at same time

neetopia commented 2 years ago

It's nice you have a solution! Closing as resolved.