https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
kotlin-native
  • j

    Jaroslav

    02/21/2019, 11:19 AM
    is there any way to use delay in an iOS project? https://github.com/Kotlin/kotlinx.coroutines/issues/920
    l
    l
    • 3
    • 6
  • b

    basher

    02/21/2019, 4:30 PM
    Are there any examples of C or Obj-C compiled inside / alongside an mpp project?
    s
    • 2
    • 5
  • b

    bob

    02/22/2019, 12:09 PM
    I’m building a desktop app (windows mainly) that will communicate to hardware via RS-232 and RS-485. Is that possible? Any suggestions on libraries?
    o
    • 2
    • 1
  • j

    Jaroslav

    02/22/2019, 1:06 PM
    Why there is no
    NSDate(timeIntervalSince1970:)
    in kotlin? 😞
    s
    j
    • 3
    • 4
  • d

    Dominaezzz

    02/22/2019, 1:07 PM
    Is there any chance that I could get more information other than
    runtime assert: Memory leaks found
    ? Can't find where the leak is from.
    o
    • 2
    • 1
  • r

    ribesg

    02/22/2019, 2:12 PM
    Is there an issue for generating multiple native functions when a kotlin function has default parameters? I can’t find it if there is one, and there should be one if there is none, because I’ve got a constructor with 5 optional parameters and that’s a lot of
    constructor
    cases to define by hand
    g
    • 2
    • 3
  • b

    basher

    02/23/2019, 4:12 AM
    When you call
    .freeze()
    on an object, somewhere along the line it calls
    FreezeSubgraph
    internally. What is it that determines what is part of an object's subgraph that also gets frozen as a part of that object's freeze operation?
    o
    • 2
    • 1
  • b

    basher

    02/23/2019, 4:13 AM
    Also, is there a debug tool that would let you tell what things you might accidentally be freezing, in a more complex project?
    r
    o
    • 3
    • 3
  • b

    Bernhard

    02/24/2019, 5:38 PM
    hi does kotlin native work compared to normal kotlin, do you still have a GC?
    d
    l
    n
    • 4
    • 3
  • b

    Bernhard

    02/24/2019, 5:39 PM
    or do you need to deal with CPointer types and malloc/free bindings
    d
    • 2
    • 2
  • b

    basher

    02/25/2019, 10:53 PM
    tbh, i've avoided this by just defining file-level functions that call into the companion, which become exposed to Swift/Obj-C as FileKt.someClassMethod
    d
    • 2
    • 3
  • d

    drofwarcs

    02/25/2019, 10:56 PM
    thats my usual goto also, however I need a companion in this case because the function is creating an instance of a class that has a private constructor
    r
    • 2
    • 2
  • i

    ivan.savytskyi

    02/26/2019, 5:17 PM
    is there any good example or documentation for how to use 3rd party library (particularly iOS
    framework
    provided by some vendor) in Kotlin Native?
    o
    s
    • 3
    • 16
  • j

    jacek.karaskiewicz

    02/27/2019, 3:03 PM
    when compiling the following K/N code:
    fun foo(bar: IntArray) {}
    to a macOsX dynamic library, I “get” a compiled library with a generated header where kotlin IntArray type is mapped to
    libtest_kref_kotlin_IntArray
    , where
    test
    is the name of my library. There seems to be no good way of constructing this object though, or at least it’s not defined in this header. Is there a way of consuming this library in a C program and somehow providing an object of that type?
    d
    o
    • 3
    • 8
  • r

    r4zzz4k

    02/27/2019, 8:47 PM
    Hey iOS people! Daniel Eke (didn't find him here unfortunately) posted nice Gradle snippet that allows one to build fat framework using
    lipo
    with single Gradle task (configuring and running two Gradle builds under the hood). https://github.com/JetBrains/kotlin-native/issues/2718#issuecomment-467838456 This looks to me like a good candidate for a bit of generalization, so maybe someone will find it useful :)
    👍 2
    d
    r
    • 3
    • 3
  • s

    spierce7

    02/28/2019, 3:26 AM
    What happened to the Kotlin/native plugin for app code? It doesn't work with the latest version of app code.
    ➕ 2
    a
    b
    l
    • 4
    • 4
  • y

    yusuf3000

    02/28/2019, 12:38 PM
    I’m using the most recent multiplatform plugin and when i run
    ./gradlew build
    it recompiles the project even when it successfully compiled previously and there has been no changes. Is this a bug? Or is there some misconfiguration in my project?
    g
    s
    • 3
    • 4
  • b

    basher

    02/28/2019, 6:27 PM
    I tried making a
    data class
    backed by an iOS foundation object, and kotlin didn't complain. Is this because K/N has built in facilities for generating equals and hashCode that call the NSObject equivalents?
    s
    • 2
    • 5
  • c

    Cyrille QUÉMIN

    02/28/2019, 11:51 PM
    hey guys, I am trying to build a framework from a cinterops that imports another framweork: NearbyMessages from Google So I install the NearbyMessages framework via cocoapods. NO issues. I defined my cinterops bloc and I can use the generated bindings in Kotlin classes. I can also publish locally my multiplatform library. But if I decide to export my ios target as a framework, I receive this error:
    ld: symbol(s) not found for architecture arm64
    this only appears because I added
    staticLibraries
    and a
    libraryPaths
    in my def file since I noticed that the google framework contains a native library
    .a
    and other frameworks as part of the its internal dependency. I have tried multiple combination of using
    linkerOpts
    with
    -L
    or
    -F
    pointing at the folder where the framework has been imported but nothing works. I have not been able to find a clear explanation as to how to create correct cinterops with ios framework that contains a static library and multiple indirect dependencies since I suspect that the impossibility to export this as ios framework is related to my wrong configuration of the cinterops. Thanks in advance Def File:
    depends = Foundation
    language = Objective-C
    headers = GNSMessages.h
    staticLibraries = NearbyMessages/Libraries/libGNSMessages.a
    libraryPaths = /Users/cyrille.quemin/Documents/git/multiplatform-p2p/p2p-common/src/iosMain/dependencies/Pods
    Cinterops:
    binaries {
                    framework("p2p_common") {
                        linkerOpts "-L${podsDir}/NearbyMessages/Libraries"
                    }
                }
                compilations.main.cinterops {
                    NearbyMessage {
                        defFile "src/iOSMain/c_interop/NearbyMessages.def"
                        includeDirs "${podsDir}/Headers/Public/NearbyMessages"
                        linkerOpts "-F${podsDir}/NearbyMessages/Libraries/"
                  }
             }
    s
    • 2
    • 12
  • j

    juancho

    03/01/2019, 2:59 AM
    Hi all! From Kotlin Native I’m trying to access a swift extension:
    SWIFT CODE:
    let originalString = "test/test"
    let escapedString = originalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
    print(escapedString!)
    I found that this function is defined as an extension in a class called
    StringProtocol
    extension StringProtocol where Self.Index == String.Index {
    Any idea how can I get access to this function from Kotlin Native? Thanks!
    s
    • 2
    • 7
  • r

    Roman

    03/01/2019, 8:03 AM
    Why does
    SystemTimeToFileTime
    return 0, I messed up with types? For the structure, should I do
    alloc
    or` allocArray`?
    val systemTime = alloc<_SYSTEMTIME>()
                systemTime.wDay=1u
                systemTime.wHour=11u
                systemTime.wMinute=11u
                systemTime.wSecond=11u
                systemTime.wMonth=11u
                systemTime.wYear=11u
            val fileTime = alloc<_FILETIME>()
    
            println(SystemTimeToFileTime(systemTime.ptr, fileTime.ptr))
    s
    • 2
    • 3
  • o

    olonho

    03/01/2019, 9:31 AM
    Kotlin team is pleased to announce 1.3.30-EAP (see https://discuss.kotlinlang.org/t/kotlin-1-3-30-early-access-preview/11780), and following changes were made in Kotlin/Native:
    * Exception backtraces in debug mode on macOS and iOS targets contains symbolic information
      * Support for 32-bit Windows targets (target mingw_x86)
      * Support for cross-compilation to Linux (x86-64 and arm32) from macOS and Windows hosts
      * Static Apple frameworks can be produced
      * Support Gradle 5.1
      * Fix alignment-related issues on ARM32 and MIPS platforms
      * Write unhandled exceptions stacktrace on device to iOS crash log
      * Fix undefined behavior in some arithmetic operations
      * Interop:
        * Get rid of libffi dependency
        * Support returning struct from C callbacks
        * Support passing Kotlin strings to C interop functions accepting UTF-32 arguments
        * Fix bool conversion
        * Support variable length arrays
        * Provide Kotlin access to C compiler intrinsics via platform.builtins package
        * Support clang modules
      * IDE
        * Kotlin/Native plugin is supported in CLion 2018.3 and AppCode/CLion 2019.1
        * Basic highlighting support for .def files
        * Navigation to source files from exception backtrace
    🍏 1
    🕺 2
    🤘 1
    ❤️ 5
    👏 3
    🎉 19
    💥 3
    a
    b
    l
    • 4
    • 5
  • r

    ribesg

    03/01/2019, 10:43 AM
    Hey, I’m creating a framework from a MPP project with ktor as dependency, but the built
    .h
    doesn’t even seem to compile
    o
    c
    s
    • 4
    • 16
  • c

    Cyrille QUÉMIN

    03/01/2019, 11:02 AM
    How can pass a linker option to points at non Apple framework. I tried in my def file something like
    linkerOpts = -framework AVFoundation -framework full/path/to/my/Framework
    and also
    linkerOpts = -framework AVFoundation -F path/to/my/framework/folder
    -framework MyFramework` but it does not work. I keep on receiving this type of error:
    ld: framework not found MyFramework
    • 1
    • 1
  • r

    ribesg

    03/01/2019, 2:05 PM
    Damn, Kotlin extensions aren’t compiled into Swift extensions?
    s
    • 2
    • 4
  • r

    ribesg

    03/01/2019, 2:36 PM
    How do I define a lambda parameter in Kotlin Native that returns Objc/Swift’s
    Void
    ?
    s
    • 2
    • 5
  • c

    Cyrille QUÉMIN

    03/01/2019, 2:42 PM
    I have now built a framework from a MPP project that in importing 2 framework via cinterops. However when I tried to import it into XCode the header seems to be generated with reserved words:
    @property (readonly) Passport_reader_commonMapper *default;
    or
    @property (readonly) double double;
    which prevent the frameword to be built in my iOS app. Any idea on a workaround?
    r
    s
    o
    • 4
    • 28
  • c

    Cyrille QUÉMIN

    03/02/2019, 1:31 PM
    Hey there I have a kotlin MPP (android and ios) and I have
    ios32
    and
    ios64
    presets. And some methods thatI use have a different signatures in 32 where it uses
    Int
    versus 64 where it uses
    Long
    . Those method are ios specific only. If I declare the same method twice (in 32 and 64 source set) then obviously I get a multiple definition error. Is there a way to deal with this where I dont need to have `expected`/`actual` because android would have no need for it and therefore 'fake' implementation?
    o
    s
    • 3
    • 11
  • c

    Cyrille QUÉMIN

    03/02/2019, 2:29 PM
    Hey there I have a kotlin MPP (android and ios) and I have
    ios32
    and
    ios64
    presets. The 32 preset defines a
    cinterops
    . Is there a way for the 64 to 'inherit` the preset definition or do I have to duplicate the
    cinterops
    bloc and the others into my 64 preset ? Ideally something like ?
    fromPreset(presets.iosArm32, 'myIOS') {
      compilations.main.cinterops {
      [...]
    }
    
    fromPreset(presets.myIOS, 'iOS64'){
    }
    d
    • 2
    • 6
  • g

    GarouDan

    03/02/2019, 3:44 PM
    Guys, if I need these dependencies:
    import kotlinx.interop.wasm.dom.*
    import kotlinx.wasm.jsinterop.*
    which dependencies should I include in my
    build.gradle.kts
    configuration file? I’m trying to follow the steps of this project but I didn’t find the correct dependencies yet: https://github.com/JetBrains/kotlin-native/tree/master/samples/html5Canvas
    d
    • 2
    • 13
Powered by Linen
Title
g

GarouDan

03/02/2019, 3:44 PM
Guys, if I need these dependencies:
import kotlinx.interop.wasm.dom.*
import kotlinx.wasm.jsinterop.*
which dependencies should I include in my
build.gradle.kts
configuration file? I’m trying to follow the steps of this project but I didn’t find the correct dependencies yet: https://github.com/JetBrains/kotlin-native/tree/master/samples/html5Canvas
d

Dominaezzz

03/02/2019, 3:45 PM
You don't need a dependency.
Just make sure you're using the
wasm
target.
Can I see your current
build.gradle
?
g

GarouDan

03/02/2019, 4:29 PM
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile
import java.nio.file.Paths

plugins {
	kotlin("multiplatform")
}

repositories {
	jcenter()
}

val packageName = "kotlinx.interop.wasm.dom"
val jsinteropKlibFileName = Paths.get(buildDir.toString(), "klib", "$packageName-jsinterop.klib").toString()

kotlin {
	wasm32 {
		compilations["main"].outputKinds("EXECUTABLE")
		compilations["main"].entryPoint("com.company.team.project.application.native_.wasm.main")
	}

	sourceSets {
		val wasm32Main by getting {
			kotlin.srcDir("src/main/kotlin")
			resources.srcDir("src/main/resources")

			dependencies {
				implementation(files(jsinteropKlibFileName))
			}
		}
		val wasm32Test by getting {
			kotlin.srcDir("src/test/kotlin")
			resources.srcDir("src/test/resources")

			dependencies {
			}
		}
	}
}

tasks {
	withType<KotlinNativeCompile>().configureEach {
		dependsOn("jsinterop")
	}
}

task("jsinterop") {
	val os = org.gradle.internal.os.OperatingSystem.current()!!
	val workingDir = projectDir
	val ext = if (os.isWindows) ".bat" else ""
	val distributionPath = project.properties["org.jetbrains.kotlin.native.home"] as String
	val jsinteropCommand = Paths.get(file(distributionPath).path, "bin", "jsinterop$ext").toString()

	inputs.property("jsinteropCommand", jsinteropCommand)
	inputs.property("jsinteropPackageName", packageName)
	outputs.file(jsinteropKlibFileName)

	exec {
		commandLine(
			jsinteropCommand,
			"-pkg",
			packageName,
			"-o",
			jsinteropKlibFileName,
			"-target",
			"wasm32"
		)
	}
}
d

Dominaezzz

03/02/2019, 4:31 PM
Sorry, how is this not working? Build error? No auto-complete?
g

GarouDan

03/02/2019, 4:33 PM
Example.kt:7:36: error: unresolved reference: textContent
	document.getElementById("target").textContent = "Test"
There are some red markers in my import:
package com.company.team.project.application.native_.wasm

import kotlinx.interop.wasm.dom.*
import kotlinx.wasm.jsinterop.*

fun main() {
	document.getElementById("target").textContent = "Test"
}
d

Dominaezzz

03/02/2019, 4:35 PM
Hmm, not sure what's wrong. Someone with more knowledge will come by.
g

GarouDan

03/02/2019, 4:36 PM
I was using
document.getElementById("target").textContent
for js, is this exists for wasm? Since my autocompletion is not working I can’t really know
In the example it uses this:
document.getElementById("myCanvas").asCanvas
but I would like to write just a text for now
d

Dominaezzz

03/02/2019, 4:38 PM
Haven't used the wasm target before, so have no idea.
g

GarouDan

03/02/2019, 4:39 PM
Ok. Thanks for helping 😃
Oh, it worked. Despite I don’t have autocompletion, using the main function of the example it worked.
fun main() {

	val canvas = document.getElementById("myCanvas").asCanvas
	val ctx = canvas.getContext("2d")
	val rect = canvas.getBoundingClientRect()
	val rectLeft = rect.left
	val rectTop = <http://rect.top|rect.top>

	var mouseX: Int = 0
	var mouseY: Int = 0
	var draw: Boolean = false

	document.setter("onmousemove") { arguments: ArrayList<JsValue> ->
		val event = MouseEvent(arguments[0])
		mouseX = event.getInt("clientX") - rectLeft
		mouseY = event.getInt("clientY") - rectTop

		if (mouseX < 0) mouseX = 0
		if (mouseX > 639) mouseX = 639
		if (mouseY < 0) mouseY = 0
		if (mouseY > 479) mouseY = 479
	}

	document.setter("onmousedown") {
		draw = true
	}

	document.setter("onmouseup") {
		draw = false
	}

	setInterval(10) {
		if (draw) {
			ctx.strokeStyle = "#222222"
			ctx.lineTo(mouseX, mouseY)
			ctx.stroke()
		} else {
			ctx.moveTo(mouseX, mouseY)
			ctx.stroke()
		}
	}
}
View count: 33