The Task :app:compileDebugUnitTestKotlinAndroid of...
# multiplatform
a
The Task appcompileDebugUnitTestKotlinAndroid of my MPP throws this error:
Quotes\app\src\commonTest\kotlin\de\ajo\quotes\SampleTests.kt: (3, 20): Unresolved reference: Test
It's that line:
import kotlin.test.Test
And then the same error with assertTrue But in app's build.gradle:
Copy code
commonTest {
    dependencies {
        implementation kotlin('test-common')
        implementation kotlin('test-annotations-common')
    }
}
Why is that? Also the following tasks run without errors: appcompileTestKotlinJs, app:jsTest, appjvmTest, appallTests, etc. and IntelliJ doesn't mark these lines as unresolved.
Top-level build.gradle:
Copy code
buildscript {
    ext.kotlin_version = '1.3.61'

    repositories {
        maven { url "<https://dl.bintray.com/jetbrains/kotlin-native-dependencies>" }

        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.0-alpha09'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "<https://kotlin.bintray.com/kotlinx>" }
        maven { url "<https://kotlin.bintray.com/ktor>" }

        google()
        jcenter()
        mavenCentral()
    }
}
build.gradle of app:
Copy code
apply plugin: 'kotlin-multiplatform'
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'

def ktor_version = '1.3.0'
def logback_version = '1.2.3'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "de.ajo.quotes"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), '<http://proguard-rules.pro|proguard-rules.pro>'
        }
    }
    buildFeatures {
        compose true
    }
}

kotlin {
    jvm()
    js {
        browser {
        }
    }
    android()
    iosX64("ios") {
        binaries {
            framework()
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation kotlin('stdlib-common')
            }
        }
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        jvmMain {
            dependsOn commonMain
            dependencies {
                implementation kotlin('stdlib-jdk8')
                implementation "io.ktor:ktor-server-netty:$ktor_version"
                implementation "io.ktor:ktor-html-builder:$ktor_version"
                implementation "ch.qos.logback:logback-classic:$logback_version"
            }
        }
        jvmTest {
            dependsOn commonTest
            dependencies {
                implementation kotlin('test')
                implementation kotlin('test-junit')
            }
        }
        clientCommonMain {
            dependsOn commonMain
        }
        clientCommonTest {
            dependsOn commonTest
        }
        jsMain {
            dependsOn clientCommonMain
            dependencies {
                implementation kotlin('stdlib-js')
            }
        }
        jsTest {
            dependsOn clientCommonTest
            dependencies {
                implementation kotlin('test-js')
            }
        }
        androidMain {
            dependsOn clientCommonMain
            dependencies {
                implementation fileTree(dir: 'libs', include: ['*.jar'])
                implementation kotlin('stdlib-jdk7')
                implementation 'androidx.appcompat:appcompat:1.1.0'
                implementation 'androidx.core:core-ktx:1.1.0'
                implementation 'androidx.ui:ui-layout:0.1.0-dev02'
                implementation 'androidx.ui:ui-material:0.1.0-dev02'
                implementation 'androidx.ui:ui-tooling:0.1.0-dev02'
            }
        }
        androidTest {
            dependsOn clientCommonTest
            dependencies {
                implementation 'junit:junit:4.12'
            }
        }
        iosMain {
            dependsOn clientCommonMain
        }
        iosTest {
            dependsOn clientCommonTest
        }
    }
}

dependencies {
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

jvmJar {
    dependsOn(jsBrowserWebpack)
    from(new File(jsBrowserWebpack.entry.name, jsBrowserWebpack.outputPath))
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    kotlinOptions {
        jvmTarget = '1.8'
    }
}

task run(type: JavaExec, dependsOn: [jvmJar]) {
    group = "application"
    main = "de.ajo.quotes.SampleJvmKt"
    classpath(configurations.jvmRuntimeClasspath, jvmJar)
    args = []
}

// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
    def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
    def target = project.findProperty('kotlin.target') ?: 'ios'
    dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask

    doLast {
        def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
        def targetDir = getProperty('configuration.build.dir')
        copy {
            from srcFile.parent
            into targetDir
            include 'app.framework/**'
            include 'app.framework.dSYM'
        }
    }
}
k
androidTest
needs
Copy code
implementation(kotlin("test"))
                implementation(kotlin("test-junit"))
🎉 1
a
You are correct, I could have seen that. Thanks very much! IntelliJ marks everything red
'implementation' cannot be applied to '(java.lang.String)'
, that's what makes it pretty confusing, because it obviously works. Also
'dependsOn' cannot be applied to '(org.gradle.api.tasks.SourceSet)'
, but it seems to work, too. Now the Android app runs. if I start the "run" task, that is specified in app/build.gradle the JVM server starts, but the JS code isn't executed on the webpage 😕 I'm using the JVM and JS code from the JVM/JS sample project. It prints:
Copy code
Hello from JVM from Ktor. Check me value: 42
Loading...
But instead of "Loading..." there should be the JS response String
k
you will have a much nicer experience if you migrate your build files to Kotlin DSL
a
When I started with MPP a few months ago I had problems with build.gradle.kts, so I went back to Groovy. But I'll try again 🙂 The JS/JVM sample project also uses Groovy, so I started from there, this time. Don't know how the JS part broke now.
i
Can you attach a link to your project on github?
a
I just uploaded it on GitHub: https://github.com/anjo96/Quotes
i
Can you create an issue - http://kotl.in/issue?
a
Is it understandable? It's my first issue 😅 https://youtrack.jetbrains.com/issue/KT-36659?project=kt I hope there is a workaround for that.
🙏 1