Andreas Jost
02/06/2020, 9:22 AMQuotes\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:
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.Andreas Jost
02/06/2020, 11:47 AMbuildscript {
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:Andreas Jost
02/06/2020, 11:47 AMapply 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'
}
}
}Kris Wong
02/06/2020, 1:08 PMandroidTest needs
implementation(kotlin("test"))
implementation(kotlin("test-junit"))Andreas Jost
02/06/2020, 1:29 PM'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:
Hello from JVM from Ktor. Check me value: 42
Loading...
But instead of "Loading..." there should be the JS response StringKris Wong
02/06/2020, 1:41 PMAndreas Jost
02/06/2020, 2:00 PMIvan Kubyshkin [JetBrains]
02/11/2020, 12:16 PMAndreas Jost
02/11/2020, 12:51 PMIvan Kubyshkin [JetBrains]
02/12/2020, 12:59 PMAndreas Jost
02/12/2020, 4:59 PM