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

    Christian Sousa

    05/28/2020, 11:36 AM
    Anyone knows what should I do to achieve the following in kotlin?
    class LeftAlignedCollectionViewFlowLayout: UICollectionViewFlowLayout {
    
        override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
            let attributes = super.layoutAttributesForElements(in: rect)
    
            var leftMargin = sectionInset.left
            var maxY: CGFloat = -1.0
            attributes?.forEach { layoutAttribute in
                if layoutAttribute.frame.origin.y >= maxY {
                    leftMargin = sectionInset.left
                }
    
                layoutAttribute.frame.origin.x = leftMargin
    
                leftMargin += layoutAttribute.frame.width + minimumInteritemSpacing
                maxY = max(layoutAttribute.frame.maxY , maxY)
            }
    
            return attributes
        }
    }
    Asking this because if I try to do:
    class LeftLayout: UICollectionViewFlowLayout {
        constructor(): super()
    
        override fun layoutAttributesForElementsInRect(rect: CGSize){
            
        }
    }
    It simply tells me that theres nothing to override..
    r
    a
    • 3
    • 11
  • l

    Luigi Scarminio

    05/28/2020, 1:13 PM
    Hi everyone! I'm using cinterops to link a dynamic library in a mingw binary executable. Everything is working fine, except that the .dll name that the executable asks is different from the one declared at the .def file. I don't know where this different name is coming from! This is from my gradle.build.kts:
    mingwX86("mingw"){
        compilations["main"].cinterops{
            val scape2 by creating {
                val cafmSrc = "C:/Software/SCAP E2/CAFM_src"
                val scapSrc = "C:/Software/SCAP E2/TO/ETME2"
                val modifiedSrc = "C:/Software/SCAP E2/Modified CAFM files"
                includeDirs.headerFilterOnly(cafmSrc, scapSrc, modifiedSrc)
                extraOpts.add("-verbose")
    
            }
        }
        binaries {
            executable()
        }
    }
    This is my scape2.def file:
    headers = scape2.h
    headerFilter = scape2.h \ GEO_API_SCAPTO.h
    linkerOpts.mingw = -LC:/Users/lscarmin/git/calculation-module4 -lscape2
    I was expecting that the dll name to be scape2.dll. But when I run the executable, it asks for ETME2.dll! If I rename scape2.dll to ETME2.dll, the code works.
    • 1
    • 1
  • k

    Kweku

    05/29/2020, 2:30 AM
    So I've been working on importing an obj-c framework using c-interop and currently in linkeropts to link to a framework I have an absolute path. It all works fine but is there any way to use relativele paths in the Def fil just for ease of use with Vcs? Is it possible to set the path in gradle?
    a
    • 2
    • 4
  • a

    aleksey.tomin

    05/29/2020, 3:45 AM
    Hello I use ktor-client/curl in KN/macos
    return runBlocking {
                <http://client.post|client.post><String>(url) {
                    contentType(ContentType.Application.Json)
                    body = json
                }
            }
    When server response 200 it’s OK But when I make wrong request and server response
    400 Bad Request
    I have got error on
    <http://client.post|client.post><String>(url)
    line
    kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@d7847578
            at 0   xpoint-sdk.kexe                     0x0000000103325b07 kfun:kotlin.Throwable.<init>(kotlin.String?)kotlin.Throwable + 87 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Throwable.kt:22:37)
            at 1   xpoint-sdk.kexe                     0x000000010331efb5 kfun:kotlin.Exception.<init>(kotlin.String?)kotlin.Exception + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:44)
            at 2   xpoint-sdk.kexe                     0x000000010331f155 kfun:kotlin.RuntimeException.<init>(kotlin.String?)kotlin.RuntimeException + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:44)
            at 3   xpoint-sdk.kexe                     0x0000000103353d75 kfun:kotlin.native.concurrent.InvalidMutabilityException.<init>(kotlin.String)kotlin.native.concurrent.InvalidMutabilityException + 85 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:22:60)
            at 4   xpoint-sdk.kexe                     0x00000001033555f8 ThrowInvalidMutabilityException + 680 (/Users/teamcity3/buildAgent/work/4d622a065c544371/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:90:11)
    ...
    What have I done wrong?
    p
    n
    • 3
    • 4
  • s

    saket

    05/29/2020, 4:24 AM
    Think that's a known issue with ktor on native platforms
    a
    p
    • 3
    • 2
  • p

    Patrick

    05/29/2020, 12:19 PM
    Can someone help me with the task of compiling a dynamic lib using mingwx64. What I tried so far is this:
    dlltool.exe -d test.def -l test.lib.a
    This gives me a static lib loader (as far as I can understand) Now I need to compile it using gcc:
    gcc main.c -o main -L. -ltest
    This works and returns main.exe. However when I execute it I get this error:
    ---------------------------
    main.exe - System Error
    ---------------------------
    The code execution cannot proceed because (null).DLL was not found. Reinstalling the program may fix this problem. 
    ---------------------------
    OK   
    ---------------------------
    a
    s
    • 3
    • 29
  • k

    Ken Gilmer

    05/29/2020, 5:47 PM
    Hello 🙂 I'd like to try the Quick sample of Serialization with Kotlin native. I have latest 1.3.73 / 0.20.0 of libraries, but cannot figure out how to express gradle dependencies such that I can see the serialization library in my project. Can anyone point me to a working example of Kotlin Native + Serialization?
    b
    p
    l
    • 4
    • 6
  • h

    hannesstruss

    06/01/2020, 11:35 AM
    How can I make kotlin-native include classes and functions declared in module dependencies? I have a Gradle module A which which is my iOS framework. Module A has an
    api
    dependency on module B. Module B contains some utilities. Only classes/functions from module B that are used in module A end up in my iOS framework, the rest seem to be excluded. How can I make sure they're included in the framework? Should I declare module B to be a framework on its own?
    a
    • 2
    • 2
  • s

    serebit

    06/02/2020, 5:32 PM
    Hmm... My local K/N build fails consistently when using Gradle 6.4.1, but not when using the Gradle wrapper. Should I file an issue? (I'm building K/N itself)
    g
    • 2
    • 31
  • a

    aleksey.tomin

    06/03/2020, 7:40 PM
    My macos KN applications write in console:
    Discarding message for event 0 because of too many unprocessed messages
    How can I process messages from OS?
    l
    a
    s
    • 4
    • 8
  • o

    Omar Mainegra

    06/04/2020, 2:42 PM
    Hi there, I'm working on a macOS app with MapKit, I was able to move the camera and add pins, but I'm struggling with
    MKPolyline
    • 1
    • 3
  • a

    aleksey.tomin

    06/04/2020, 4:03 PM
    Have anyone sign OSX/IOS application by appleID? I want to sign my application by gradle MP project
    s
    • 2
    • 1
  • o

    Omar Mainegra

    06/04/2020, 5:39 PM
    Hi, I want to convert a base64 string using
    NSData().initWithBase64EncodedString(str, 0)
    , but the function is deprecated and doesn't compile, the error says:
    Use factory method instead
    , but I can't find the equivalent
    s
    • 2
    • 2
  • s

    serebit

    06/04/2020, 6:32 PM
    Was this not supported previously? I'm only just now seeing this error on 1.4-M2, it didn't show up on 1.4-M1.
    l
    d
    • 3
    • 3
  • y

    yigit

    06/05/2020, 2:22 AM
    after updating to 1.4-M2, my project started failing where it cannot find symbols from linked so. https://youtrack.jetbrains.com/issue/KT-39396 I'm wondering if anybody else is having similar problems w/ cinterop
    • 1
    • 1
  • a

    aleksey.tomin

    06/05/2020, 9:55 AM
    I’m confused about KN -> C interropt. How can I do it?
    memScoped {
                val locator = alloc<IWbemLocator>()
                val pointer: CValuesRef<LPVOIDVar> = locator.???
    I try
    val pointer: CValuesRef<LPVOIDVar> = CPointerVarOf<LPVOID>(locator.ptr.rawValue).ptr
    but it leads compile-time internal error. If I create pointer by
    val ptr = alloc<COpaquePointerVar>()
    How I can get
    IWbemLocator
    ?
    a
    • 2
    • 3
  • m

    Mananpoddarm

    06/05/2020, 7:43 PM
    Hi, I have generated a .so shared library using kotlin/native. I am using this .so shared library in my different android project. I am able to load the library but I am not able to call the functions, I think the methods name have to be with JNI underscore or something, is there a way to get details like method names of the .so shared library inside android project? (after we do System.loadLibrary(".so library name"))
    n
    • 2
    • 5
  • n

    napperley

    06/08/2020, 2:02 AM
    Is it possible to use the Kotlin Native Worker API to run tasks in parallel? Have a situation where the linuxX64 code base is running tasks in parallel via the KotlinX Coroutines library, however the linuxArm32Hfp code base is running tasks in a basic event loop. The KotlinX Coroutines library isn't available for the Linux ARM targets, and it doesn't look like that will change anytime soon 😦.
    a
    • 2
    • 3
  • g

    gildor

    06/08/2020, 3:05 AM
    Workers is essentially the only way to run some operation on another thread which is available on K/N (without usage of pthread and other platform specific features, so it’s the only common way to do that), kotlinx.coroutines not even released with support of concurrency, it’s under active development I don’t see how it can be compareed, and it’s a separate library, after all
    n
    t
    • 3
    • 7
  • m

    Mananpoddarm

    06/08/2020, 10:01 AM
    Hi, I have built a .so shared library in kotlin/native and I am able to use it's methods in my android app(thanks to @natario1) But now, I am using cinterop in my kotlin/native project to access tensorflow C API and i am able to access the tensorflow methods inside my kotlin/native project. But these functions are not accessibly by my android app. why?
    g
    m
    • 3
    • 11
  • a

    aleksey.tomin

    06/09/2020, 4:48 AM
    How can I create daemon-thread in KN? I’ve read about
    Worker
    and
    executeAfter
    but have not understood how I have to do this.
    g
    • 2
    • 2
  • a

    aleksey.tomin

    06/09/2020, 9:11 AM
    How can I write the same code in KN? I want to get file name for function
    func
    inline fun javaClassName(noinline func: () -> Unit) = func.javaClass.name
    g
    h
    • 3
    • 9
  • a

    aleksey.tomin

    06/09/2020, 10:31 AM
    Can I know debug/release app launched? I want do to something like
    if (isDebug) println("we a here")
    Maybe write something in
    build.gradle.kts
    ?
    a
    • 2
    • 4
  • s

    sena

    06/09/2020, 2:13 PM
    Hi, am I right in thinking that it is impossible to generate android native libraries and executables which utilise the kotlinx serialization library?
    > Could not resolve all files for configuration ':self-common:androidNativeArm32CompileKlibraries'.
       > Could not resolve org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0-1.4-M2.
         Required by:
             project :self-common
          > Unable to find a matching variant of org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0-1.4-M2:
              - Variant 'iosArm32-api' capability org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0-1.4-M2:
                  - Incompatible attribute:
                      - Required org.jetbrains.kotlin.native.target 'android_arm32' and found incompatible value 'ios_arm32'.
                  - Other attributes:
                      - Found org.gradle.status 'release' but wasn't required.
                      - Required org.gradle.usage 'kotlin-api' and found compatible value 'kotlin-api'.
                      - Required org.jetbrains.kotlin.platform.type 'native' and found compatible value 'native'.
              - Variant 'iosArm32-iosArm32MetadataElements' capability org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0-1.4-M2:
    If this is is stated somewhere obvious apologies as I haven’t seen it.
    s
    r
    • 3
    • 6
  • n

    Nico Buescher

    06/09/2020, 8:22 PM
    Is it currently possible to use the kotlin native runtime to evaluate kotlin script code at runtime? I’ve found only references to the javax.script support on the JVM while searching.
    d
    • 2
    • 3
  • b

    basher

    06/10/2020, 2:18 AM
    is there a way to pass a reference to a local UInt as a UIntVar, or do you have to use alloc to be able to pass such a pointer to a c function?
    d
    • 2
    • 2
  • h

    hmole

    06/10/2020, 9:58 PM
    Anyone knows why k/n compile and link tasks are running sequentually with gradle parallelism enabled? #gradle
    d
    s
    • 3
    • 6
  • h

    hmole

    06/10/2020, 10:40 PM
    Trying to use cinterop and most of the generated bindings come out with
    @Deprecated("Unable to import this declaration"
    . Is there any way to generate "unsafe" bindings or something like that? The header in question is
    sqlite3ext.h
    and targets are Android NDK
    y
    • 2
    • 4
  • s

    Samyak Jain

    06/12/2020, 8:41 AM
    Hi, is anyone aware from kts to groovy translation? I tried converting kotlin DSL files to Groovy, but it is showing errors? The kts function is as follows:
    tasks {
        withType<KotlinCompile> {
            kotlinOptions.jdkHome = rootProject.extra["JDK_18"] as String
            kotlinOptions.languageVersion = "1.2"
            kotlinOptions.apiVersion = "1.2"
            kotlinOptions.freeCompilerArgs += listOf("-Xskip-metadata-version-check")
        }
    
        named<ProcessResources>("processResources") {
            val propertiesToExpand = mapOf("projectVersion" to project.version)
            for ((name, value) in propertiesToExpand) {
                inputs.property(name, value)
            }
            filesMatching("project.properties") {
                expand("projectVersion" to project.version)
            }
        }
    
        named<Jar>("jar") {
            callGroovy("manifestAttributes", manifest, project)
        }
    
        named<ValidateTaskProperties>("validateTaskProperties") {
            failOnWarning = true
        }
    
        named<DokkaTask>("dokka") {
            outputFormat = "markdown"
            includes = listOf("$projectDir/Module.md")
        }
    }
    I wanted it to convert it Groovy: tasks {
    withType(KotlinCompile) {
            kotlinOptions.jdkHome = rootProject.ext["JDK_18"] as String
            kotlinOptions.languageVersion = "1.2"
            kotlinOptions.apiVersion = "1.2"
            kotlinOptions.freeCompilerArgs += ["-Xskip-metadata-version-check"]
        }
    
        processResources {
            val propertiesToExpand = {"projectVersion" = project.version}
            for ((name, value) in propertiesToExpand) {
                inputs.property(name, value)
            }
            filesMatching("project.properties") {
                expand("projectVersion" to project.version)
            }
        }
    
        jar {
            callGroovy("manifestAttributes", manifest, project)
        }
    
        validateTaskProperties {
            failOnWarning = true
        }
    
        dokka {
            outputFormat = "markdown"
            includes = ["$projectDir/Module.md"]
        }
    }
    n
    • 2
    • 2
  • k

    katokay

    06/12/2020, 5:56 PM
    As kotlin-native evolves especially with 1.4 it would be really great if Jetbrains can help clarify package publishing that include native dependencies. For reference, this discussion shows it's not real clear at the moment or what the vision is. https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/36#issuecomment-643244227
    n
    • 2
    • 2
Powered by Linen
Title
k

katokay

06/12/2020, 5:56 PM
As kotlin-native evolves especially with 1.4 it would be really great if Jetbrains can help clarify package publishing that include native dependencies. For reference, this discussion shows it's not real clear at the moment or what the vision is. https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/36#issuecomment-643244227
n

napperley

06/13/2020, 1:27 AM
I'm assuming you are only talking about the mobile platforms. Package publishing will be different for the other platforms like Linux (targets like linuxX64, linuxArm32Hfp, linuxArm64 etc) for example.
k

katokay

06/13/2020, 1:23 PM
That's my specific pain point yes, but the problem will exist there as well. Yes, of course it will be different for other platforms and likely for each library. My point is that it's not very clear at the moment and that there's been a lot of change. There are docs that describe specific settings, specific targets. I think what's needed is something that is more narrative. Here we have a library that needs to do this with JS, this with iOS, this with JVM, this for linuxX64. Here's how to publish a package that takes all of this into consideration. Now that we've published our package, users will do this to add a dependency (given their specific use case). Here's how these choices we made earlier affect the end-user adding your package as a dependency.
View count: 3