jared
11/18/2020, 5:53 PMkotlinx.coroutines
1.3.9-native-mt-2
and Ktor 1.4.2
in a multiplatform library for sharing networking between iOS and Android. I am confused over Ktor and background threads. I am using the Main
dispatcher and I can’t tell if the network request is running on the main thread or a background thread. Does Ktor handle running a single background thread for me?Cicero
11/18/2020, 9:31 PMNikita Khlebushkin
11/18/2020, 10:15 PMmobile-shared [SharedLogic]
|____ ModuleShared
|____ TestAndroidApp
|____ TestIosApp
I can build and compile KMM library, assemble .jar, Cocoapods - no problem here.
Lately I've been trying to add this project as a module dependency to an Android project, which used to have the following structure:
MyApp
|____ app
and now has the following structure:
MyApp
|____ app
|____ mobile-shared [SharedLogic]
|____|____ ModuleShared
|____|____ TestAndroidApp
|____|____ TestIosApp
How I was trying to do it:
Option 1:
MyApp/settings.gradle.kts:
pluginManagement {
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
useModule("com.android.tools.build:gradle:4.0.1")
}
}
}
}
include(":app")
include(":SharedLogic")
project(":SharedLogic").projectDir = File("mobile-shared")
include(":SharedLogic:ModuleShared")
MyApp/app/build.gradle.kts:
...
android {
dependencies {
implementation(project(":SharedLogic:ModuleShared"))
Option 2:
MyApp/settings.gradle.kts:
pluginManagement {
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android" || requested.id.name == "kotlin-android-extensions") {
useModule("com.android.tools.build:gradle:4.0.1")
}
}
}
}
include(":app")
include(":ModuleShared")
project(":ModuleShared").projectDir = File("mobile-shared/ModuleShared")
MyApp/app/build.gradle.kts:
...
android {
dependencies {
implementation(project(":ModuleShared"))
Error I encounter:
A problem occurred configuring project ':SharedLogic:ModuleShared'.
* Where:
Build file '/home/xlebnick/projects/MyApp/mobile-shared/ModuleShared/build.gradle.kts' line: 40
* What went wrong:
This version of the kotlin-serialization Gradle plugin is built for a newer Kotlin version. Please use an older version of kotlin-serialization or upgrade the Kotlin Gradle plugin version to make them match.
In ModuleShared/build.gradle.kts:
plugins {
kotlin("plugin.serialization") version "1.4.10"
}
In mobile-shared/build.gradle.kts:
buildscript {
repositories {
gradlePluginPortal()
jcenter()
google()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10")
classpath("com.android.tools.build:gradle:4.1.0")
}
}
And in MyApp/build.gradle.kts:
uildscript {
apply(from = "versions.gradle.kts")
val kotlinVersion: String by extra // 1.4.10
val rootClasspath: List<String> by extra
repositories {
mavenCentral()
google()
jcenter()
maven("<https://plugins.gradle.org/m2/>")
maven("<https://maven.fabric.io/public>")
}
dependencies {
classpath(kotlin("gradle-plugin", version = kotlinVersion))
for (rc in rootClasspath) {
classpath(rc)
}
}
}
What am I doing wrong?
P.S. Found this issue, but it doesn't help at allPhilip Dukhov
11/18/2020, 10:24 PMError: Could not find or load main class com.well.server.ApplicationKt
I’ve found a solution to run it, using following task:
task<JavaExec>("run") {
main = "com.well.server.ApplicationKt"
val jvm by kotlin.targets.getting
val main: KotlinCompilation<KotlinCommonOptions> by jvm.compilations
val runtimeDependencies = (main as KotlinCompilationToRunnableFiles<KotlinCommonOptions>).runtimeDependencyFiles
classpath = files(main.output.allOutputs, runtimeDependencies)
}
One of the minuses - I can’t debug server and run an other module, because server starts running as part of task, and task progress remains 92 until I abort it.
Is there a better solution?
But the main goal right now is to deploy the server. Following the official guide, I tried this code:
tasks.create("stage") {
dependsOn(tasks.getByName("installDist"))
}
application {
mainClassName = "ApplicationKt"
}
distributions {
main {
contents {
from("$buildDir/libs") {
rename("${rootProject.name}-jvm", rootProject.name)
into("lib")
}
}
}
}
tasks.getByName<JavaExec>("run") {
`classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by jvmJar
can be found and served`
}
But ./gradlew :server:run
returns Could not find or load main class ApplicationKt
error, and :server:jvmJar
finishes without errors but doesn’t seems to produce the outputAmritansh
11/18/2020, 11:13 PMwilliam
11/19/2020, 1:05 AMkotlin.Result
in multiplatform?
i'm not having any luck using it with
kotlin {
targets.all {
compilations.all {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-Xallow-result-return-type"
}
}
}
}
I still get the message saying I can't use result as a return typewilliam
11/19/2020, 1:45 AMRengu N
11/19/2020, 5:26 AMSergio Casero
11/19/2020, 11:05 AMimplementation(project(":accesscontrol"))
This is my 6th kmp project and I never get this issue. I have 3 JVM modules and works on 2 of them perfectly. I've tried cleaning the project, invalidating the cache, restarting the PC... When I execute ./gradlew run
I can see that common related tasks are executed, and I can see the jar inside the build folderJeremias Nunez
11/19/2020, 2:16 PMPrecondition failed: NSArray element failed to match the Swift Array Element type
Expected Movie but found SharedMovie: file Swift/ArrayBuffer.swift, line 354
My Movie class is defined like this:
@Serializable
data class Movie(
val name: String,
val tone: String,
val light: String,
val url: String,
val order: Int,
val version: Int
)
I found this issue but it doesn't provide any possible solution: https://github.com/JetBrains/kotlin-native/issues/2830Cicero
11/20/2020, 8:56 AMmmaillot
11/20/2020, 10:04 AMTristan Hamilton
11/20/2020, 12:37 PMAzur Haljeta
11/20/2020, 5:55 PMOla Adolfsson
11/21/2020, 7:44 PMCicero
11/21/2020, 9:13 PMdata class LoginModel(
@SerialName("username")
val username: String?,
@SerialName("password")
val password: String?,
@SerialName("userType")
val userType: String = "PROFESSIONAL"
)
With the serialisers and all, when I try to access it in swift I find this:
- (instancetype)initWithUsername:(NSString * _Nullable)username password:(NSString * _Nullable)password userType:(NSString *)userType
And when I try to use it on my code it kinda foces me to put something on my variable with a pre defined value, like this:
let login = common.LoginModel(username: emailTextfield.text, password: passwordTextField.text, userType: “PROFESSIONAL”)
I can live with this but I would like to know if there is an immediate solution.
PS: It works fine on android, as intended.
How default values work on swift: https://docs.swift.org/swift-book/LanguageGuide/Functions.htmlSkolson5903
11/22/2020, 1:39 AMbuildscript {
...
classpath("org.jetbrains.kotlinx:atomicfu-gradle-plugin:0.14.4")
}
Module build.gradle.kts:
plugins {
...
id("kotlinx-atomicfu")
}
After the upgrade the IDE (Android Studio 4.1) shows this import in error, but gradle build still works:
import kotlinx.atomicfu.atomic
In the IDE, the ending "atomic" is red as if it isn't in the dependencies, but gradle builds OK and tests run.
Previously I had seen IDE-bad vs Gradle-good build issues in this project on the "java" package, but adding this to gradle.properties fixed that:
kotlin.mpp.enableGranularSourceSetsMetadata=true
That option is still set and doesn't help this new atomic issue. Anyone else seen this with 1.4.20? I'm still researching. Thanks in advance for any info...napperley
11/22/2020, 2:59 AMHai Tran
11/23/2020, 9:02 AMCicero
11/23/2020, 11:51 AMJérôme Gully
11/23/2020, 5:52 PMaw
11/23/2020, 7:09 PMshared.framework
(which is exported from :*packForXcode*) via a cococapods
into an existing App, without linking the App-project with the MPP-project (like in the Android Studio example)? We need to have the MPP-project separate from the iOS App and only use cocoapods
to link the (prebuild) dependency. Every example I find either directly invokes :packForXcode from Xcode build-phases or uses cocoapods
just to reference to the relative-path of the framework.Amritansh
11/23/2020, 9:48 PMrusshwolf
11/23/2020, 10:25 PMkotlin.mpp.enableCompatibilityMetadataVariant
flag for library authors to avoid compatibility issues with projects that don’t enable heirarchical project support? I see it in the JB libs, but can I use it or should I avoid it?Vincent Chen
11/24/2020, 6:11 AMJérôme Gully
11/24/2020, 9:55 AMPaul Woitaschek
11/24/2020, 10:30 AMPhilip Dukhov
11/24/2020, 4:47 PMxcconfig
file in Xcode, and shared it with android using android.buildTypes.resValue
. How can I do the same with a KMP shared module?Frankablu
11/24/2020, 5:15 PMwhy
11/24/2020, 6:37 PMwhy
11/24/2020, 6:37 PMTijl
11/24/2020, 8:59 PM