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
  • v

    Vlad Balan

    03/17/2020, 5:28 PM
    Hi guys. Is there a way to provide a
    cinterop
    dependency for the
    commonMain
    ? Thanks in advance!
    r
    • 2
    • 1
  • v

    Vlad Balan

    03/17/2020, 6:37 PM
    Hi guys, I have a problem regarding a
    cinterop
    library and the architectures:
    arm32
    and
    x64
    . I am using the
    Cairo
    library as
    cinterop
    library for both targets. After the
    cinterop
    process the following struct:
    typedef struct {
        unsigned long        index;
        double               x;
        double               y;
    } cairo_glyph_t;
    is mapped for
    arm32
    to:
    @kotlinx.cinterop.internal.CStruct public final class cairo_glyph_t public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
        public companion object : kotlinx.cinterop.CStructVar.Type {
        }
    
        public final var index: kotlin.UInt /* compiled code */
    
        public final var x: kotlin.Double /* compiled code */
    
        public final var y: kotlin.Double /* compiled code */
    }
    and for
    x64
    to:
    @kotlinx.cinterop.internal.CStruct public final class cairo_glyph_t public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
        public companion object : kotlinx.cinterop.CStructVar.Type {
        }
    
        public final var index: kotlin.ULong /* compiled code */
    
        public final var x: kotlin.Double /* compiled code */
    
        public final var y: kotlin.Double /* compiled code */
    }
    As you can see the
    index
    field has different types. I am trying to write the code once and compile it for both platforms, but the following example does not compile:
    val glyph = cValue<cairo_glyph_t> {
      index =  0
      x = 0.0
      y = 0.0
    }
    Does anybody have an idea how I can overcome this issue? Thanks in advance!
    d
    • 2
    • 2
  • v

    Vlad Balan

    03/18/2020, 2:39 PM
    Hi guys, I have a question regarding
    Object pinning
    . According to the documentation this can be done as follows:
    fun readData(fd: Int): String {
      val buffer = ByteArray(1024)
      buffer.usePinned { pinned ->
        while (true) {
          val length = recv(fd, pinned.addressOf(0), buffer.size.convert(), 0).toInt()
          if (length <= 0) {
            break
         }
         // Now `buffer` has raw data obtained from the `recv()` call.
       }
     }
    }
    What about if I want to use it on something else than a buffer. For example on
    cValue<cairo_text_extents_t>
    where
    cairo_text_extents_t
    is:
    @kotlinx.cinterop.internal.CStruct public final class cairo_text_extents_t public constructor(rawPtr: kotlinx.cinterop.NativePtr /* = kotlin.native.internal.NativePtr */) : kotlinx.cinterop.CStructVar {
        public companion object : kotlinx.cinterop.CStructVar.Type {
        }
    
        public final var height: kotlin.Double /* compiled code */
    
        public final var width: kotlin.Double /* compiled code */
    
        public final var x_advance: kotlin.Double /* compiled code */
    
        public final var x_bearing: kotlin.Double /* compiled code */
    
        public final var y_advance: kotlin.Double /* compiled code */
    
        public final var y_bearing: kotlin.Double /* compiled code */
    }
    and the function to which I want to provide it is:
    @kotlinx.cinterop.internal.CCall public external fun cairo_glyph_extents(cr: kotlinx.cinterop.CValuesRef<libcairo.cairo_t /* = cnames.structs._cairo */>?, glyphs: kotlinx.cinterop.CValuesRef<libcairo.cairo_glyph_t>?, num_glyphs: <http://kotlin.Int|kotlin.Int>, extents: kotlinx.cinterop.CValuesRef<libcairo.cairo_text_extents_t>?): kotlin.Unit { /* compiled code */ }
    My problem is that
    cValue<cairo_text_extents_t>
    does not have the function
    addressOf
    . I provide a small code snippet to show what I mean:
    val glyph = cValue<cairo_glyph_t>()
    val extents = cValue<cairo_text_extents_t>()
    extents.usePinned {pinned ->
    	memScoped {
    		cairo_glyph_extents(context.cairo, glyph.ptr, 1, pinned.<what>) // how to get the address 
    	}
    }
    Does anybody know how I can do this? Thanks in advance!
    d
    • 2
    • 3
  • s

    spierce7

    03/18/2020, 8:29 PM
    So I just compiled a small Kotlin/native fat framework for our iOS team. It included 2 small private libs, kotlinx.coroutines, ktor, and kotlinx.serialization. The entire compiled framework when added to the iOS app only increased app size by 1.1 MB. That’s fantastic! Way better than I anticipated. It’s so good I’m actually a bit skeptical that the iOS dev measured things correctly. Does this sound right?
    k
    k
    • 3
    • 25
  • s

    serebit

    03/18/2020, 9:13 PM
    I keep getting an error
    runtime assert: Must be positive
    in my project that uses GTK interop, and I have no idea what's causing it. It's raised by konan, in the
    garbageCollect
    function.
    d
    k
    • 3
    • 17
  • k

    Kavan

    03/19/2020, 3:23 AM
    Gradle is soo slow
    s
    n
    • 3
    • 5
  • r

    ribesg

    03/19/2020, 11:30 AM
    I’ve got a new crash on ios in Kotlin 1.3.70 in coroutines. Here is the top of the stack
    b
    • 2
    • 15
  • d

    Daniel Gruber

    03/19/2020, 12:33 PM
    Hey there 🙂 does someone know how to change the details of the generated exe file? tried with manifest but did not work for me currently
    m
    • 2
    • 2
  • j

    j.l.

    03/19/2020, 4:19 PM
    Hello community, I am playing around with the Kotlin/Native compiler. Trying to compile using the command line (I'm using a MacBook). My terminal does not recognize the
    kotlinc-native
    command. Looking at the bin folder, i see all of the other compilers (
    kotlinc
    ,
    kotlinc-js
    ,
    kotlinc-jvm
    , etc.) but no
    kotlinc-native
    . I believe I am on the latest version (1.3.70-release-328 (JRE 13.0.1+9)). I was wondering if anyone else faced this issue or if it was just me. Couldn't really find anything helpful about it when googling the problem.
    a
    • 2
    • 9
  • s

    spierce7

    03/19/2020, 10:35 PM
    Is there a way to have the Kotlin documentation available and visible from Swift code?
    b
    • 2
    • 3
  • r

    ribesg

    03/20/2020, 9:14 AM
    Wow, ok so here’s a VERY weird one. After updating to 1.3.70, one of my endpoints implementation with ktor sends a completely wrong body. It’s the endpoint for login, and it sends a completely different endpoint body. Like, another serializable request body that isn’t even defined in the same gradle module. Only occurs in simulator and not on device. Wtf?
    e
    s
    • 3
    • 10
  • l

    Luoqiaoyou

    03/20/2020, 12:40 PM
    Could we provide a mechanism for make the object read from other thread possible but modify from other thread impossible?
    k
    k
    • 3
    • 11
  • s

    spierce7

    03/20/2020, 4:24 PM
    After hearing about the performance improvements for 1.3.70 I thought I’d try out my html builder benchmark again. The entire lib basically compiles down to a giant
    StringBuilder
    with inline functions. I’m still seeing that building a website 10k times takes ~400 millis on JVM, and about 10X that for Kotlin/native with target macosx64 at ~4100 millis. https://github.com/ScottPierce/kotlin-html/tree/master/benchmark
    ./gradlew :benchmark:runReleaseExecutableMacosX64
    if anyone else wants to try.
    d
    e
    • 3
    • 3
  • l

    Luoqiaoyou

    03/21/2020, 10:12 AM
    When I was learning the KN concurrency model, I did some concurrency experiments and some strange problems appeared,here is the code:
    // Uncaught Kotlin exception: kotlin.IllegalStateException: Illegal transfer state
    fun test(): Test {
        return Worker.start().execute(TransferMode.SAFE, { atomic(Test()) }) {
            it.value.a += 100
            it
        }.result.value
    }
    // fine
    fun test1(): Test {
        return Worker.start().execute(TransferMode.SAFE, { Test() }) {
            it.a += 100
            it
        }.result
    }
    k
    k
    a
    • 4
    • 14
  • b

    Big Chungus

    03/22/2020, 3:11 PM
    Was freeCompilerArg
    -include binary <PATH>
    removed with 1.3.70?
    d
    • 2
    • 5
  • r

    Richard Myers

    03/23/2020, 10:56 AM
    I’m trying to build a Kotlin/native app for Android that accesses my own C library via cinterop. Any suggestions about a good example/sample to use? I’m currently trying to modify this one: https://github.com/JetBrains/kotlin-native/tree/master/samples/androidNativeActivity
    • 1
    • 1
  • d

    dazza5000

    03/23/2020, 10:10 PM
    has anyone here used/seen kotlin/native used with flutter via dart ffi?
    s
    • 2
    • 2
  • k

    Kavan

    03/24/2020, 4:27 AM
    @olonho Kotlin native right now not good with GUI applications, manual bindings is only option. What's your thoughts about chromium's opensource rendering engine bindings for kotlin-native ?
    o
    • 2
    • 1
  • p

    Patrick

    03/24/2020, 11:13 AM
    How do I change the name of the executable? I understand that by default the name is the same as the project name.
    • 1
    • 1
  • s

    Sylvain Patenaude

    03/24/2020, 1:07 PM
    When creating a .framework library for iOS, is it by default targetting some versions of Swift/Obj-C or is the interface (header, modules, etc.) core enough to support all versions? Thanks in advance!
    l
    • 2
    • 2
  • n

    Nikolay Kasyanov

    03/24/2020, 3:05 PM
    Hey folks, is increased memory usage by K/N compiler expected in 1.3.70 (or 71)? I’m getting
    java.lang.OutOfMemoryError: Java heap space
    while building iOS frameworks from klibs.
    r
    m
    • 3
    • 4
  • s

    Sylvain Patenaude

    03/24/2020, 5:17 PM
    What's the purpose of
    ios_framework_name
    in the build.gradle file? Can we use that variable to change the name of the generated framework for iOS?
    k
    • 2
    • 13
  • r

    redbassett

    03/25/2020, 4:15 AM
    Brand new to KN, coming from Android, so forgive my lack of familiarity with native build processes. I’ve been trying to follow the hello world tutorials for KN, and they all point to a
    kotlinc-native
    compiler tool. I have
    kotlin
    and
    kotlinc
    available at my command line, but not
    kotlinc-native
    . I’m on Mac, and I don’t recall if I ever installed Kotlin or it was already there from using IntelliJ/Android Studio for Kotlin. How do I get this compiler?
    a
    • 2
    • 2
  • n

    Nikolay Kasyanov

    03/25/2020, 8:04 AM
    hey iOS folks, just a heads up, if you are on Kotlin 1.3.61 or below and is about to switch to Xcode 11.4 (Swift 5.2), brace yourselves for impact as this issue’s fix hasn’t made it into the 5.2 release: https://bugs.swift.org/browse/SR-12169.
    💥 1
    👍 2
    b
    r
    • 3
    • 20
  • k

    Kris Wong

    03/25/2020, 2:25 PM
    If I want to update to 1.3.71, is it sufficient for my dependencies to be using 1.3.70, or do they also need to be on 71?
    d
    • 2
    • 2
  • s

    Sam

    03/25/2020, 3:20 PM
    I upgraded to Xcode 11.4 today and running in the iOS simulator works fine. However when trying to switch to a device it tells me that my framework was build for the simulator and gives me an error. Previously Xcode would just re-run the build script and the gradle build file would rebuild for the correct environment. Has anyone else run into this with the new Xcode?
    m
    t
    • 3
    • 8
  • n

    napperley

    03/25/2020, 10:26 PM
    Looked at the resource usage for a program I had developed. After running the program for over 90 min I found that CPU usage is very low, but the memory usage was steadily climbing which indicates that there are some memory leaks. Shared Memory remained steady at 12.4 MB. What is the difference between Shared Memory and Memory?
    • 1
    • 6
  • r

    ribesg

    03/26/2020, 1:02 PM
    I lost auto imports for
    platform.*
    in IntelliJ IDEA a few days ago and I didn’t manage to get them back the usual way, by cleaning everything (
    .gradle
    ,
    .idea
    ,
    build
    ) while IDEA is closed, calling
    gradle --stop
    and then starting IDEA again. Anything else you guys do when IDEA borks?
    k
    l
    • 3
    • 5
  • p

    Peter Samokhin

    03/26/2020, 2:38 PM
    Is there a way to use SQLDelight with 1.3.71? https://github.com/cashapp/sqldelight/issues/1623 - it is not updated yet and the build is crashing
    j
    • 2
    • 1
  • n

    Nico Buescher

    03/26/2020, 6:29 PM
    I'm trying to implement a fraction function in kotlin native (opposite of truncate), and given the following C code:
    #include <stdio.h>
    float fract(float x) {
        return x - (long)x;
    }
    int main() {
        printf("%f", fract(2.3f));
    }
    with output
    0.3
    , I expected the same output from kotlin code:
    fun fract(x: Float): Float {
    	return x - x.toLong()
    }
    
    fun main() {
    	println(fract(2.3f))
    }
    instead I get:
    0.29999995
    What's happening here?
    e
    m
    • 3
    • 4
Powered by Linen
Title
n

Nico Buescher

03/26/2020, 6:29 PM
I'm trying to implement a fraction function in kotlin native (opposite of truncate), and given the following C code:
#include <stdio.h>
float fract(float x) {
    return x - (long)x;
}
int main() {
    printf("%f", fract(2.3f));
}
with output
0.3
, I expected the same output from kotlin code:
fun fract(x: Float): Float {
	return x - x.toLong()
}

fun main() {
	println(fract(2.3f))
}
instead I get:
0.29999995
What's happening here?
e

Erik Christensen

03/26/2020, 6:40 PM
It's likely just the decimal precision setting for the strings generated by the print functions you're using. They may be different by default.
m

Markus Böck

03/26/2020, 6:42 PM
Correct, printf by default has a precision of 6 digits
You can also see in a debugger that in C it too has the same value
💯 2
n

Nico Buescher

03/26/2020, 6:43 PM
Ooooooh. That makes so much sense. Thanks!
View count: 5