KMM project build error - 'testClasses' not found in project ':shared'
Asked Answered
D

2

9

I'm trying out KMM for the first time and when I try to rebuild the project, I get this error. Not sure what this task does. Am I the only one getting this error?

I'm using a Macbook Pro M1 that runs

Android Studio Iguana | 2023.2.1 Runtime version: 17.0.9+0-17.0.9b1087.7-11185874 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.

Executing tasks: [:androidApp:clean, :shared:clean, 
:androidApp:assembleDebug, :androidApp:assembleDebugUnitTest, 
:androidApp:assembleDebugAndroidTest, :shared:assembleDebug, 
:shared:assembleDebugUnitTest, :shared:assembleDebugAndroidTest, 
:shared:assemble, :shared:testClasses] in project 
/Users/betteropinions/Development/KMM/TranslateKMMApp

Calculating task graph as no configuration cache is available for 
tasks: :androidApp:clean :shared:clean :androidApp:assembleDebug 
:androidApp:assembleDebugUnitTest 
:androidApp:assembleDebugAndroidTest :shared:assembleDebug 
:shared:assembleDebugUnitTest :shared:assembleDebugAndroidTest 
:shared:assemble :shared:testClasses
Type-safe project accessors is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Cannot locate tasks that match ':shared:testClasses' as task 
'testClasses' not found in project ':shared'.

* Try: 
> Run gradle tasks to get a list of available tasks.
> For more on name expansion, please refer to 
https://docs.gradle.org/8.4/userguide/
command_line_interface.html#sec: 
name_abbreviation in the Gradle documentation.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1s
Configuration cache entry stored.

Below is the build.gradle.kts for shared module


plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.kotlinCocoapods)
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.kotlinSerialization)
    id("com.squareup.sqldelight")
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }

    iosX64()
    iosArm64()
    iosSimulatorArm64()

    cocoapods {
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        version = "1.0"
        ios.deploymentTarget = "16.0"
        podfile = project.file("../iosApp/Podfile")
        framework {
            baseName = "shared"
            isStatic = true
        }
    }
    
    sourceSets {

        commonMain.dependencies {
            //put your multiplatform dependencies here
            implementation(libs.ktor.client.core)
            implementation(libs.ktor.client.content.negotiation)
            implementation(libs.ktor.serialization.kotlinx.json)
            implementation(libs.sqldelight.coroutines.extensions)
            implementation(libs.sqldelight.runtime)
            implementation(libs.kotlinx.datetime)
        }

        commonTest.dependencies {
            implementation(kotlin("test"))
            implementation(libs.turbine)
            implementation(libs.assertk)
        }

        androidMain.dependencies {
            implementation(libs.ktor.client.android)
            implementation(libs.sqldelight.android.driver)
        }

        iosMain.dependencies {
            implementation(libs.ktor.client.darwin)
            implementation(libs.sqldelight.native.driver)
        }
    }
}

android {
    namespace = "com.example.mytranslate"
    compileSdk = 34
    defaultConfig {
        minSdk = 24
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

sqldelight {
    database("TranslateDatabase") {
        packageName = "com.example.mytranslate.database"
        sourceFolders = listOf("sqldelight")
    }
}
Dampproof answered 9/3 at 19:11 Comment(5)
please provide the build.gradle file belonging to the shared module. thank youFajardo
@Lino, I have modified the question by adding the build.gradle of the shared module. This issue comes only when I click on the rebuild option.Dampproof
I am experimenting the same issue, looks like a bug when adding CMP to an already existing project, however, on a CMP imported via Jetbrains wizard, works fineMarienthal
@Marienthal I am still getting this error when using the jetbrains wizard (kmp.jetbrains.com) without altering any of the code provided by it or adding anything to it. Does this still work for you?Outfall
@C.Toni After adding the below-given task in the build.gradle.kts file, my KMP project builds successfully.Dampproof
S
27

This solution https://mcmap.net/q/648130/-android-studio-task-39-testclasses-39-not-found-in-project works for me.

I've added task("testClasses") within.in kotlin { } block in build.gradle.kts (:shared) file.

plugins {
    ...
}

kotlin {
    androidTarget {
        ...
    }

    sourceSets {
        ...
    }

    task("testClasses")
}

android {
    ...
}
Silly answered 14/3 at 8:24 Comment(3)
Ok, this is working. Accepting your answer. Thank you :)Dampproof
Would you share why it's fixing this issueManzanilla
@SamRamezanli The error was specifically looking for a task named 'testClasses'. Since task("testClasses") explicitly defines such a task, Gradle no longer throws an error. Please note that this task, as defined, doesn't do anything; it's merely a placeholder.Silly
S
1

Also got this problem since I installed last version of android studio and kotlin multiplatform plugin 0.8.2. Same project with android studio Giraffe and kotlin multiplatform plugin 0.8.1 is running fine (it also fixed intrumental tests for android, and allow running JS units tests from android studio, while no more available with latest version)

Stroke answered 17/4 at 12:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.