Android [ksp] java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap$Builder.buildOrThrow()'

问题描述 投票:0回答:1

我将库更新到最新版本,并将 jvm 包含到 17,但到目前为止我遇到的问题是

[ksp] java.lang.NoSuchMethodError: 'com.google.common.collect.ImmutableMap com.google.common.collect.ImmutableMap$Builder.buildOrThrow()' 

我已经查看了该网站并说它可能使用旧版本

guava
,所以我尝试在我的gradle中
implementation("com.google.guava:guava:33.3.1-android")
但仍然无法工作

我找不到哪些库使用番石榴,尝试将库更新到最新版本和番石榴,但仍然是同样的问题,我给你gradle.kts

app Gradle kts

import org.jetbrains.kotlin.konan.properties.Properties

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
    id("io.realm.kotlin")
    id("com.google.devtools.ksp")
    id("com.google.dagger.hilt.android")
    id("kotlin-parcelize")
    id("com.google.gms.google-services")
    id("com.google.firebase.crashlytics")
}

val props = Properties()
file("../local.properties").inputStream().use { props.load(it) }

android {
    namespace = "com.honcho.quickfire"
    compileSdk = 34

    signingConfigs {
        getByName("debug") {
            keyAlias = props.getProperty("debug.key.alias")
            keyPassword = props.getProperty("debug.key.password")
            storeFile = file(props.getProperty("debug.key.path"))
            storePassword = props.getProperty("debug.key.password.store")
        }
        create("release") {
            keyAlias = props.getProperty("release.key.alias")
            keyPassword = props.getProperty("release.key.password")
            storeFile = file(props.getProperty("release.key.path"))
            storePassword = props.getProperty("release.key.password.store")
        }
        create("beta") {
            keyAlias = props.getProperty("release.key.alias")
            keyPassword = props.getProperty("release.key.password")
            storeFile = file(props.getProperty("release.key.path"))
            storePassword = props.getProperty("release.key.password.store")
        }
    }

    defaultConfig {
        applicationId = "com.honcho.quickfire"
        minSdk = 23
        targetSdk = 34
        versionCode = 81
        versionName = "2.0.24"

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

    buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
            buildConfigField("String", "HOST", props.getProperty("RELEASE_HOST_API"))
            buildConfigField("String", "GALLERY_HOST", props.getProperty("RELEASE_GALLERY_HOST"))
            buildConfigField("String", "WEB_HOST", props.getProperty("RELEASE_WEB_HOST"))
            buildConfigField("String", "SOCKET_HOST", props.getProperty("RELEASE_SOCKET_HOST"))
            buildConfigField("String", "MIXPANEL_TOKEN", props.getProperty("MIXPANEL_TOKEN"))
            buildConfigField("String", "DATADOG_TOKEN", props.getProperty("DATADOG_TOKEN"))
            signingConfig = signingConfigs.getByName("release")
        }

        debug {
            applicationIdSuffix = ".debug"
            isDebuggable = true
            buildConfigField("String", "HOST", props.getProperty("DEBUG_HOST_API"))
            buildConfigField("String", "GALLERY_HOST", props.getProperty("DEBUG_GALLERY_HOST"))
            buildConfigField("String", "WEB_HOST", props.getProperty("DEBUG_WEB_HOST"))
            buildConfigField("String", "SOCKET_HOST", props.getProperty("DEBUG_SOCKET_HOST"))
            buildConfigField("String", "MIXPANEL_TOKEN", props.getProperty("MIXPANEL_TOKEN"))
            buildConfigField("String", "DATADOG_TOKEN", props.getProperty("DATADOG_TOKEN"))
        }

        create("beta") {
            applicationIdSuffix = ".beta"
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
            buildConfigField("String", "HOST", props.getProperty("RELEASE_HOST_API"))
            buildConfigField("String", "GALLERY_HOST", props.getProperty("RELEASE_GALLERY_HOST"))
            buildConfigField("String", "WEB_HOST", props.getProperty("RELEASE_WEB_HOST"))
            buildConfigField("String", "SOCKET_HOST", props.getProperty("RELEASE_SOCKET_HOST"))
            buildConfigField("String", "MIXPANEL_TOKEN", props.getProperty("MIXPANEL_TOKEN"))
            buildConfigField("String", "DATADOG_TOKEN", props.getProperty("DATADOG_TOKEN"))
        }
    }
    compileOptions {
        isCoreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
    buildFeatures {
        compose = true
        buildConfig = true
    }
    composeOptions {
        // kotlinCompilerExtensionVersion = "1.4.3"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }

    allprojects {
        tasks.withType<JavaCompile> {
            options.compilerArgs.addAll(arrayOf("-parameters", "-Xlint:deprecation"))
        }
    }
}

kotlin {
    jvmToolchain(17)
}

ksp {
    arg("jvmTarget", "17")
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
    implementation("androidx.core:core-ktx:1.13.1")
    implementation("androidx.activity:activity-compose:1.9.2")

    implementation(project(mapOf("path" to ":service")))
    implementation(files("libs/pronto-release.aar"))

    // Kotlin
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0")

    // Compose
    implementation(platform("androidx.compose:compose-bom:2024.09.03"))
    implementation("androidx.compose.ui:ui")
    implementation("androidx.compose.ui:ui-graphics")
    implementation("androidx.compose.ui:ui-tooling-preview")
    implementation("androidx.compose.material3:material3")

    // Lifecycle
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6")
    implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.6")
    implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.6")
    implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.8.6")
    implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.6")

    // Navigation 6.0
    implementation ("androidx.navigation:navigation-compose:2.8.2")

    // Work manager
    implementation("androidx.work:work-runtime-ktx:2.9.1")
    implementation("androidx.work:work-multiprocess:2.9.1")

    // CameraX
    implementation("androidx.camera:camera-core:1.3.4")
    implementation("androidx.camera:camera-camera2:1.3.4")
    implementation("androidx.camera:camera-lifecycle:1.3.4")
    implementation("androidx.camera:camera-video:1.3.4")
    implementation("androidx.camera:camera-view:1.3.4")
    implementation("androidx.camera:camera-extensions:1.3.4")

    // Test
    androidTestImplementation(platform("androidx.compose:compose-bom:2024.09.03"))
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.2.1")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
    androidTestImplementation("androidx.compose.ui:ui-test-junit4")
    debugImplementation("androidx.compose.ui:ui-tooling")
    debugImplementation("androidx.compose.ui:ui-test-manifest")

    // Hilt
    implementation ("com.google.dagger:hilt-android:2.52")
    ksp("com.google.dagger:hilt-android-compiler:2.52")

    implementation ("androidx.hilt:hilt-navigation-compose:1.2.0")
    implementation("androidx.hilt:hilt-work:1.2.0")
    ksp("androidx.hilt:hilt-compiler:1.2.0")

    // Firebase
    implementation(platform("com.google.firebase:firebase-bom:28.0.0"))
    implementation("com.google.firebase:firebase-analytics")
    implementation("com.google.firebase:firebase-crashlytics")
    implementation("com.google.firebase:firebase-auth")

    // FirebaseUI for Firebase Auth
    implementation("com.firebaseui:firebase-ui-auth:8.0.2")
    implementation("com.google.android.gms:play-services-auth:20.6.0")

    // Ktor
    implementation("io.ktor:ktor-client-core:2.3.4")
    implementation("io.ktor:ktor-client-cio:2.3.4")
    implementation("io.ktor:ktor-client-json:2.3.4")
    implementation("io.ktor:ktor-client-content-negotiation:2.3.4")
    implementation("io.ktor:ktor-client-serialization:2.3.4")
    implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.4")

    // Coil
    implementation("io.coil-kt:coil-compose:2.6.0")
    implementation("io.coil-kt:coil:2.6.0")

    // Guava
    implementation("com.google.guava:guava:33.3.1-android")

    // Splash Screen
    implementation ("androidx.core:core-splashscreen:1.0.1")
    implementation("androidx.compose.animation:animation-graphics:1.7.3")

    // Realm MongoDB
    implementation ("io.realm.kotlin:library-base:1.10.0")
    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

    // Event Bus
    implementation("org.greenrobot:eventbus:3.3.1")
    // ExifInterface
    implementation("androidx.exifinterface:exifinterface:1.3.7")
    // Datastore
    implementation("androidx.datastore:datastore-preferences:1.1.1")
    // QrCode
    implementation("com.github.androidmads:QRGenerator:1.0.1")
    // GSON
    implementation("com.google.code.gson:gson:2.11.0")
    // ZoomImage
    implementation ("net.engawapg.lib:zoomable:1.5.2")
    // MixPanel
    implementation("com.mixpanel.android:mixpanel-android:7.4.0")
    //Tooltip Balloon
    implementation("com.github.skydoves:balloon-compose:1.6.4")
    // Datadog
    implementation("com.datadoghq:dd-sdk-android-logs:2.6.2")
}

service Gradle kts
我使用这个项目来处理后端服务

plugins {
    id("com.android.library")
    id("com.google.devtools.ksp")
    id("org.jetbrains.kotlin.android")
    id("io.realm.kotlin")
    id("kotlinx-serialization")
    id("com.google.gms.google-services")
    id("com.google.dagger.hilt.android")
}

android {
    namespace = "com.honcho.service"
    compileSdk = 34

    defaultConfig {
        minSdk = 23
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles("consumer-rules.pro")
    }

    buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }

        create("beta") {}
    }
    compileOptions {
        isCoreLibraryDesugaringEnabled = true
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = 17.toString()
        tasks.withType<org.jetbrains.kotlin.gradle.internal.KaptGenerateStubsTask>().configureEach {
            kotlinOptions {
                jvmTarget = 17.toString()
            }
        }
    }
}

kotlin {
    jvmToolchain(17)
}

ksp {
    arg("jvmTarget", "17")
}

dependencies {

    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2")
    implementation("androidx.core:core-ktx:1.13.1")
    implementation("androidx.appcompat:appcompat:1.7.0")

    // Kotlin
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.9.0")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")

    // SDK Camera
    compileOnly(files("libs/pronto-release.aar"))

    // implementation("com.google.android.material:material:1.12.0")

    // Guava
    implementation("com.google.guava:guava:33.3.1-android")

    // Hilt
    implementation ("com.google.dagger:hilt-android:2.52")
    ksp("com.google.dagger:hilt-android-compiler:2.52")

    // Realm
    implementation("io.realm.kotlin:library-base:3.0.0")

    // Ktor
    implementation("io.ktor:ktor-client-core:3.0.0")
    implementation("io.ktor:ktor-client-okhttp:3.0.0")
    implementation("io.ktor:ktor-client-auth:3.0.0")
    implementation("io.ktor:ktor-client-logging:3.0.0")
    implementation("io.ktor:ktor-client-content-negotiation:3.0.0")
    implementation("io.ktor:ktor-client-serialization:3.0.0")
    implementation("io.ktor:ktor-serialization-gson:3.0.0")

    // Firebase
    implementation(platform("com.google.firebase:firebase-bom:28.0.0"))
    implementation("com.google.firebase:firebase-auth-ktx")

    // FirebaseUI for Firebase Auth
    implementation("com.firebaseui:firebase-ui-auth:8.0.2")
    implementation("com.google.android.gms:play-services-auth:20.6.0")

    // Test
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.2.1")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")

    // Serialization
    implementation("com.google.code.gson:gson:2.11.0")
    // Centrifuge
    implementation("io.github.centrifugal:centrifuge-java:0.4.2")
}

这个

root Gradle

import org.jetbrains.kotlin.gradle.dsl.kotlinExtension

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id("com.android.application") version "8.7.0" apply false
    id("org.jetbrains.kotlin.android") version "1.9.25" apply false
    id("com.google.devtools.ksp") version "1.9.25-1.0.20" apply false
    id("org.gradle.toolchains.foojay-resolver-convention") version("0.5.0") apply false
    id("io.realm.kotlin") version "1.10.0" apply false
    id("com.android.library") version "8.7.0" apply false
    id("com.google.dagger.hilt.android") version "2.52" apply false
    id("com.google.gms.google-services") version "4.4.1" apply false
    id("org.jetbrains.kotlin.plugin.serialization") version "1.8.10" apply false
    id("com.google.firebase.crashlytics") version "2.9.9" apply false
}

subprojects {
    afterEvaluate {
        kotlinExtension.jvmToolchain(17)
    }
}

configurations.all {
    resolutionStrategy {
        force("com.google.guava:guava:33.3.1-android")
    }
}
java android kotlin gradle gradle-kotlin-dsl
1个回答
0
投票

我们面临同样的问题。可以用以下版本的kotlin、ksp和realm解决这个问题:

[versions]
kotlin = "2.0.21"
ksp = "2.0.21-1.0.28"
realm = "3.0.0"
© www.soinside.com 2019 - 2024. All rights reserved.