https://kotlinlang.org logo
Docs
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
  • c

    Chilli

    04/30/2020, 4:07 PM
    Is it possible to read files from the
    resource
    folder from Kotlin/Native? Everything in the internet I found uses
    javaClass.getResource
    which is obviously not available in Native...
    m
    k
    • 3
    • 4
  • c

    Chilli

    04/30/2020, 9:40 PM
    How can I unfreeze a companion object? I tried usin g
    @konan.ThreadLocal
    but I have no idea what's its package — it gives me
    Unresolved reference
    I managed to find a way, but another question persists — where to store global data so the singletons may stay immutable?
    k
    • 2
    • 5
  • c

    Chilli

    04/30/2020, 11:54 PM
    Any idea of how to get rid of that
    @ExperimentalUnsignedTypes
    requirement?
    k
    • 2
    • 1
  • n

    natario1

    05/01/2020, 1:32 PM
    When we build binaries with Kotlin Native there seems to be a small overhead in size due to the K/N "runtime". If the binary is a shared library and you have many of these, this overhead is multiplied. Is there a way to build shared libs linked against a shared libkotlinnative, for example? This way we could add a single libkotlinnative to the project. Kind of like in Android NDK you can choose to build with libc++_shared.so or libc++_static.so, each one being better than the other for some use cases. https://developer.android.com/ndk/guides/cpp-support
    k
    • 2
    • 2
  • k

    Kavan

    05/01/2020, 4:03 PM
    I was just looking at my code after long time lots of reinterpret() Can we make it go away ?
    createThread {
                val woeid = WeatherAPI.queryLocation("Toronto")
                val weekForcast = WeatherAPI.getWeatherInfo(woeid.get(0).woeid)
    
                val todayInfo = weekForcast.get(0)
    
                gtk_ideal {
                    gtk_label_set_text(gtk_builder_get_object(builder, "the_temp")?.reinterpret(), "${todayInfo.currentTemp.toInt()}°")
                    gtk_label_set_text(gtk_builder_get_object(builder, "day_place")?.reinterpret(), "${todayInfo.dayOfWeek} - ${woeid.get(0).name}")
                    gtk_label_set_text(gtk_builder_get_object(builder, "weather_state_name")?.reinterpret(), "${todayInfo.weatherState}")
                    gtk_label_set_text(gtk_builder_get_object(builder, "more_detailed")?.reinterpret(), "High: ${todayInfo.maxTemp.toInt()}° Low: ${todayInfo.minTemp.toInt()}°  Precip: 0%")
    
    
                    val weekGridView = gtk_builder_get_object(builder, "week_detail_grid")
                    weekForcast.drop(1).forEachIndexed { index, dayInfo ->
                        gtk_grid_attach(weekGridView?.reinterpret(), createElement(dayInfo.dayOfWeek.substring(0,3), dayInfo.weatherStateAbbr, dayInfo.maxTemp.toInt().toString(), dayInfo.minTemp.toInt().toString())?.reinterpret(), index, 0, 1, 1)
                    }
                    gtk_widget_show_all(weekGridView?.reinterpret())
    
                }
    
            }
    j
    • 2
    • 1
  • r

    Rahul Singhal

    05/01/2020, 4:10 PM
    <attr name="onClick" format="string" />
    
    android:onClick="@{() -> onClickEvent.invoke()}"
    Please help me to understand how onClick accept the lamda function . how this () -> onClickEvent.invoke() convert to string
    r
    • 2
    • 1
  • c

    Chilli

    05/01/2020, 4:43 PM
    When I'm trying to use a function from cinterop, clang++ throws a weird error:
    e: C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/clang++ invocation reported errors
    
    The C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/clang++ command returned non-zero exit code: 1.
    output:
    C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: DWARF error: mangled line number section (bad file number)
    C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: DWARF error: mangled line number section (bad file number)
    ...
    C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: DWARF error: mangled line number section (bad file number)
    C:\Users\Chilli\AppData\Local\Temp\konan_temp2904216670241181048\result.o:out:(.text+0x7e4d1): undefined reference to `GetUserNameExA'
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    
    > Task :linkDebugSharedWindows FAILED
    
    Execution failed for task ':linkDebugSharedWindows'.
    > Compilation finished with errors
    Just if the reference weren't there, but IntelliJ does see this function. It's a function from secext.h that I'm importing using secext.def:
    headers = secext_wrapper.h
    headerFilter = secext.h
    package = me.[...].cinterop.secext
    
    linkerOpts.mingw = -lpsapi
    and secext_wrapper.h:
    #pragma once
    #include <windows.h>
    #define SECURITY_WIN32
    #include <security.h>
    Any idea why doesn't it work?
    k
    a
    • 3
    • 13
  • s

    Sean Keane

    05/01/2020, 5:24 PM
    Is it possible to write UI Components with UI Kit and export them as a framework? Currently getting the following error.
    Kotlin subclass of Objective C class can't be imported
    For this class
    @ExportObjCClass
    public class MyView: UIView {
        private val helloWorldLabel = UILabel()
        @OverrideInit
        constructor(coder: NSCoder) : super(coder)
        @OverrideInit
        public constructor(frame: CValue<CGRect>) : super(frame) {
        
            helloWorldLabel.apply {
                text = "Hello World"
                translatesAutoresizingMaskIntoConstraints = false
            }
            NSLayoutConstraint.activateConstraints(
                listOf(
                    helloWorldLabel.centerXAnchor.constraintEqualToAnchor(this.centerXAnchor),
                    helloWorldLabel.centerYAnchor.constraintEqualToAnchor(this.centerYAnchor)
                )
            )
            this.addSubview(this.helloWorldLabel)
        }
        @ObjCAction
        fun layoutSubviews() {
        }
    }
    k
    • 2
    • 5
  • n

    natario1

    05/01/2020, 8:38 PM
    Can Kotlin Native cinterop work with a C++ library whose only public functions are marked as
    extern "C"
    ?
    d
    • 2
    • 4
  • l

    louiscad

    05/01/2020, 10:07 PM
    Hello, I'm having trouble upgrading my project #splitties from Kotlin 1.3.61 to 1.3.72 as I get this error at gradle sync:
    Could not GET '<https://download-cf.jetbrains.com/kotlin/native/builds/releases/1.3.72/macos/kotlin-native-macos-6.1.tar.gz>'. Received status code 403 from server: Forbidden
    Am I the only one to experience it? EDIT: Same issue with Kotlin 1.4-M1:
    Could not GET '<https://download-cf.jetbrains.com/kotlin/native/builds/releases/1.4-M1/macos/kotlin-native-macos-6.1.tar.gz>'. Received status code 403 from server: Forbidden
    I'm completely blocked, so I'll be very grateful for help.
    e
    • 2
    • 1
  • j

    jdiaz

    05/02/2020, 7:09 PM
    I'm right now linking libgit2, the problem is that in WSL, the version is pretty old so I built it myself. The problem is that now I don't know how to link the newly built library in the linker ops as it seems to ignore my -L
    Before:
    linkerOpts.linux = -L/usr/lib64 -L/usr/lib/x86_64-linux-gnu -lgit2
    After:
    linkerOpts.linux = -L/usr/lib64 -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lgit2
    And I can see it in
    ldconfig -v | grep -C3 libgit
    (libgit2.so.1.0 -> libgit2.so.1.0.0). What am I missing?
    d
    • 2
    • 6
  • n

    Nick Williams

    05/03/2020, 6:37 PM
    How do I add a dependency on a .framework to the
    iosTest
    target? Im getting an error
    ld: framework not found FirebaseCore
    in the task
    linkDebugTestIos
    d
    b
    y
    • 4
    • 23
  • h

    Hauke Radtki

    05/04/2020, 6:30 PM
    Mutex is failing me on multithreaded coroutines with
    InvalidMutabilityException: mutation attempt of frozen kotlinx.coroutines.sync.MutexImpl.LockedQueue
    when accessed from two different threads, even though the documentation states:
    All core communication and synchronization objects in
    kotlin.coroutines
    such as Job, Deferred, Channel, BroadcastChannel, Mutex, and Semaphore are shareable. It means that they can be frozen for sharing with another thread and still continue to operate normally.
    Anyone experienced this?
    k
    • 2
    • 6
  • y

    yk_nb

    05/05/2020, 7:07 AM
    Can anybody give me some insight on the following https://stackoverflow.com/questions/61581030/cyrillic-input-not-recognized-in-kotlin-native ? Thank you.
    c
    • 2
    • 19
  • p

    Patrick

    05/05/2020, 8:55 AM
    I have a Java (JVM) library that I would like to use in my native code. What is the best way to call JVM functions from native? Do I have to use JNI to make it work. Or is there a better solution?
    c
    h
    • 3
    • 5
  • p

    Prateek Grover

    05/05/2020, 2:53 PM
    Can someone from the JB team, please have a look at this issue? https://youtrack.jetbrains.com/issue/KT-38668?project=kt
    a
    • 2
    • 4
  • k

    Kris Wong

    05/05/2020, 3:19 PM
    does anyone know if/how cinterop handles
    @import Module
    ?
    a
    • 2
    • 2
  • a

    Andrey Gromov

    05/05/2020, 8:35 PM
    Hello. I want to make simple annotation processing plugin for K/N.
    @PrintName("name")
    class SomeClass{...}
    It must print "name" on build phase. I reviewed tons of articles and examples, spent three days with
    <https://github.com/Foso/MpApt>
    and achieve nothing. Maybe you can point me to simple working example? I need only K/N, not mpp.
    a
    f
    • 3
    • 4
  • j

    jdiaz

    05/05/2020, 10:28 PM
    How can one troubleshoot a message like:
    .konan/dependencies/clang-llvm-8.0.0-linux-x86-64/bin/ld.lld invocation reported errors
    ? it happens in linux and not in macOs
    s
    n
    • 3
    • 7
  • m

    mbonnin

    05/05/2020, 10:35 PM
    Can I get a macOS .framework that is optimized and contains debug information ? Looks like I only have the choice between (
    DEBUG=non-optimized with debug info
    or
    RELEASE=optimized without debug info
    ). I feel like having dSYM could still help symbolicate stacktraces but maybe I'm wrong ?
    • 1
    • 1
  • z

    ZabGo

    05/06/2020, 9:09 AM
    Hello, I am trying to add a framework to my KMP library in order to use it in an iOS app. I get the error message:
    Undefined symbols for architecture x86_64
    I am not really sure about the right way to link this framework. I tried to add the headers of this framework to
    compilerOpts
    as well but it did not change anything. Is there anything I need to change or add in the def file or build.gradle? For now the linkerOpts looks like that in my def file:
    linkerOpts= \
     -F/absolute/path/to/MyFramework.framework \
     -framework AVFoundation \
     -framework Foundation \
     -framework CoreGraphics \
     -framework CoreVideo \
     -framework QuartzCore \
     -framework UIKit \
     -framework CoreLocation \
     -framework Security \
     -framework CFNetwork \
     -framework CoreMedia \
     -framework SystemConfiguration \
     -framework AudioToolbox
    in my build.gradle
    iosX64("ios") {
        binaries {
            framework('Shared'){
                linkerOpts "-F/absolute/path/to/MyFramework.framework"
            }
        }
    
        compilations.main {
            cinterops {
                myCinterop {
                    linkerOpts "-F/absolute/path/to/MyFramework.framework"
                }
            }
        }
    k
    • 2
    • 16
  • n

    Nuno Vieira

    05/06/2020, 12:40 PM
    Hi guys. Currently Apple is not approving the submission of an app I’m working on because of the usage of deprecated
    UIWebView
    and we found that the generated KMP Binary was the cause. We did include third party binaries that was using this inside the KMP Binary. We removed them, but still when using
    nm
    on the Generated KMP Binary, it still finds references to
    UIWebViewDelegate
    .
    000000000065d1d8 s __OBJC_LABEL_PROTOCOL_$_UIWebViewDelegate
    00000000006c6010 d __OBJC_PROTOCOL_$_UIWebViewDelegate
    Does anyone know why this happens? We are using version Kotlin/Native 1.3.61, and by looking at the Changelog, it doesn’t mention anything about this. But could it be fixed in recent versions? UPDATE: SOLVED
    🙏 1
    a
    • 2
    • 7
  • r

    rattenkonig

    05/06/2020, 1:34 PM
    Hi! Is there a way to specify target platform for static libraries linkage in cinterop file? Tried to write
    staticLibraries.targetName = path/to/static/lib
    (i.e. mac_x64) but that didn’t work out, ld reported that
    Undefined symbols for architecture x86_64
    . Without specification of target everything compiles, but I need to link that library on several platform and kinda don’t want to create cinterop file for each target
    n
    m
    • 3
    • 3
  • a

    aleksey.tomin

    05/07/2020, 3:23 AM
    Hello for all I’ve create gradle project in CLion.
    kotlin-gradle-plugin
    has got
    macosX64
    and
    linuxX64
    function (kotlin-gradle-plugin-1.3.70-sources.jar!/org/jetbrains/kotlin/gradle/dsl/KotlinTargetContainerWithPresetFunctions.kt:353) but I haven’t found
    windows
    . Can I make windows application?
    r
    • 2
    • 1
  • a

    Andrey Gromov

    05/07/2020, 2:41 PM
    I try to compile
    .def
    file to
    klib
    with header file included. This header contains other includes.
    # cat myext.def
    headers = somepath\somelib.h
    
    # cinterop -def myext.def -o myext
    error: 'someOther.h' file not found with <angled> include; use "quotes" instead
    It's third party headers and I can't change them. How to resolve this without adding those headers into
    def
    in right order?
    k
    • 2
    • 1
  • a

    aleksey.tomin

    05/13/2020, 6:47 AM
    Hey guys. I’ve made
    app.kexe
    for macos. And I try to run it on another computer. Result -
    dyld: Library not loaded: /usr/local/opt/libmicrohttpd/lib/libmicrohttpd.12.dylib
    1. May be put library into kexe? How I can do it? 2. May be create macos installer? How I can do it?
    a
    • 2
    • 4
  • m

    magnumrocha

    05/13/2020, 4:50 PM
    hey guys, is it possible to get the relative
    NSError
    for a kotlin native
    Throwable
    ?
    k
    • 2
    • 3
  • a

    adk

    05/13/2020, 8:51 PM
    Hey, can anyone point me to some info on how to pass variadic args to a c function?
    k
    n
    • 3
    • 25
  • k

    Kavan

    05/14/2020, 5:00 AM
    Can I detach konan from auto download and install dependencies ? I wanna use system installed dependencies
    s
    • 2
    • 1
  • c

    Christian Sousa

    05/14/2020, 11:53 AM
    I’m trying to change the text color of a SegmentedControl with the following:
    setTitleTextAttributes(attributes = mapOf(UIColor.whiteColor to "foregroundColor"), forState = UIControlStateSelected)
    But it is crashing when running the app. Already tried
    foregroundColor
    ,
    backgroundColor
    and
    textColor
    but none worked.
    What am I doing wrong? Solved it by changing the mapOf, the key was out of place
    a
    • 2
    • 2
Powered by Linen
Title
c

Christian Sousa

05/14/2020, 11:53 AM
I’m trying to change the text color of a SegmentedControl with the following:
setTitleTextAttributes(attributes = mapOf(UIColor.whiteColor to "foregroundColor"), forState = UIControlStateSelected)
But it is crashing when running the app. Already tried
foregroundColor
,
backgroundColor
and
textColor
but none worked.
What am I doing wrong? Solved it by changing the mapOf, the key was out of place
a

Artyom Degtyarev [JB]

05/14/2020, 1:28 PM
Hello, can you tell a bit more on the error contents?
c

Christian Sousa

05/14/2020, 1:42 PM
Nevermind, was doing the
mapOf
the other way around. It should be:
setTitleTextAttributes(attributes = mapOf("foregroundColor" to UIColor.whiteColor), forState = UIControlStateSelected)
👍 2
View count: 5