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

    alec

    04/05/2022, 12:20 PM
    is
    kotlinx-coroutines-core:x.x.x-native-mt
    still a thing are or does that not need to exist with the new native memory model
    👀 1
    r
    • 2
    • 4
  • g

    Guy Tavor

    04/06/2022, 1:43 PM
    Hi All. I hope I’m not asking that was asked 1000 times before, but I couldn’t find any reliable answer on the web. We are evaluating using K/N for our new and shiny startup’s standalone client app, which should run on MacOS, Linux & Windows. We have no plans to run this client on iOS/Android. Do you know of any real-world standalone desktop app project that’s using K/N? Is K/N suitable for this you think or is it mainly a tool for doing KMM right? We will need things like: • desktop notifications • File-system monitoring and • Displaying a React based UI inside a browser wrapper window. EDIT: building Kotlin/JVM is not an option for us, as we’re building a daemon, and the JVP heap requirements is not acceptable for our use-case.
    e
    l
    t
    • 4
    • 25
  • n

    napperley

    04/08/2022, 2:04 AM
    Today the experimental memory model has been used along with Kotlin 1.6.20 (previously Kotlin 1.4.31 was used) in production with a custom backend service (Linux Daemon). Reserved RAM usage has increased from around 9.8 MB to around 17 MB. Release binary size has slightly decreased from 4.2 MB to 4.1 MB. I'm guessing that the increase in RAM usage comes down to a full GC being used instead of the partial GC used by the old memory model. It should be noted that only changes were made to the build side of the code base (incl build configuration).
    🎉 1
    🔍 3
    • 1
    • 1
  • j

    Joakim Forslund

    04/08/2022, 6:15 AM
    Kotlin: 1.6.10 and 1.6.20 MM enabled I have a callback in c looking this:
    int (*messageClass)(struct UIElement *element, UIMessage message, int di /* data integer */, void *dp /* data pointer */);
    I also have this c function:
    UIElement *UIElementCreate(size_t bytes, UIElement *parent, uint32_t flags,
    int (*messageClass)(UIElement *, UIMessage, int, void *), const char *cClassName);
    That in kotlin interop becomes:
    fun UIElementCreate(
    bytes: size_t,
    parent: CValuesRef<UIElement>?,
    flags: uint32_t,
    messageClass: CPointer<CFunction<(CPointer<UIElement>?, UIMessage, Int, COpaquePointer?) -> Int>>?, cClassName: kotlin.String?): CPointer<UIElement>? { }
    I then try to call above method from kotlin with:
    UIElementCreate(sizeOf<UIWindow>().toULong(),null,UI_ELEMENT_WINDOW,staticCFunction(::messageCallback),"Window")
    fun messageCallback(element: CPointer<UIElement>?, message: UIMessage, di: Int, dp: COpaquePointer?): Int {
    println("Inside weird ass callback")
    return 0
    }
    This results in a crash, What am I doing wrong? As a side-note I also ran the staticCFunction as inline, had the same result (and the function is called just fine from pure c)
    • 1
    • 1
  • j

    jcechace

    04/12/2022, 2:11 PM
    Hi… What is the support for databases in kotlin native? E.g. is it possible to use for example Postgres? So far it looks like either there really isn’t any db support (except for maybe sqlite and some mobile databases such as Ream / Firebase) or my Google-fu is weak today.
    e
    l
    +3
    • 6
    • 32
  • j

    James Ward

    04/15/2022, 10:25 AM
    Is there any way to deal with "classpath" resources in Kotlin/Native? In jvm-land I put a properties file with config into
    META-INF
    and then load it via
    classLoader.getResourceAsStream
    but I'm not sure if there is a way to do something similar in native.
    k
    • 2
    • 5
  • u

    4brunu

    04/19/2022, 9:51 AM
    Hi, I'm trying to integrate kermit in my KMM project, but to do that, first I need to convert the KMM iOS XCFramework from dynamic to static. I have done it by doing so
    listOf(
            iosX64(),
            iosArm64(),
            //iosSimulatorArm64() sure all ios dependencies support this target
        ).forEach {
            it.binaries.framework {
                baseName = "shared"
                isStatic = true
            }
        }
    The problem is that when I make this change, I got 5000 warnings when building the iOS project. Any idea why? By the way, I'm not using cocoapods. ``````
    j
    • 2
    • 3
  • a

    Ayfri

    04/22/2022, 11:10 PM
    Hi, how can I put a string into a
    CPointer<WCHARVar>
    ?
    r
    d
    • 3
    • 5
  • c

    Charles Prado

    04/26/2022, 6:50 PM
    Hi.
    Calling Kotlin suspend functions from Swift/Objective-C is currently supported only on main thread
    I’m using KTOR 2.0.0 with the new memory model. Getting this error when trying to call an async func inside a Task from this iOS side. There’s currently something I can do to be able to call that function in that context?
    r
    j
    h
    • 4
    • 7
  • d

    Dominaezzz

    04/27/2022, 8:29 PM
    Anyone seen something like this before?
    w: skipping D:\a\kgl\kgl\kgl-glfw\build\classes\kotlin\commonizer\cglfw\H3MydyJqF8c0JoJ3z3gndIlI7DE=\(linux_x64, macos_x64, mingw_x64)\com.kgl_kgl-glfw-cinterop-cglfw. The target doesn't match. Expected 'linux_x64', found [mingw_x64]
    https://github.com/JetBrains/kotlin/blob/v1.6.21/kotlin-native/shared/src/library/[…]kotlin/org/jetbrains/kotlin/konan/library/SearchPathResolver.kt
    s
    • 2
    • 13
  • m

    martmists

    04/30/2022, 4:13 PM
    How do I properly commonize libraries? I've got a setup where each linuxX64Main, mingwX64Main, etc all depend on nativeMain in project A Then in project B, the nativeMain depends on project A, and again all <platform>Main sourcesets depend on nativeMain. It compiles just fine, but IntelliJ doesn't recognize the functions from project A's cinterops in the nativeMain module. (build.gradle.kts for A and B in thread)
    r
    n
    • 3
    • 4
  • n

    napperley

    05/02/2022, 9:22 PM
    Does Kotlin Native have a module loading system that is similar to what can be found on some platforms ( https://stackoverflow.com/questions/384121/creating-a-module-system-dynamic-loading-in-c )? I would like to develop a Kotlin Native program that has a basic plugin system built in where certain functionality is loaded on demand, without requiring all C libraries to be available on the target platform. For example, one might develop a Kotlin Native program which generates performance reports that come in various types. One of these types is PDF which requires the Cairo library ( https://www.cairographics.org/ ) to be loaded, whereas the Console report just uses the built in platform libraries and doesn't require the Cairo library.
    e
    s
    s
    • 4
    • 12
  • n

    napperley

    05/03/2022, 1:05 AM
    Was busy looking at a C API ( https://man7.org/linux/man-pages/man7/rtnetlink.7.html ) and wondering if it is a User Space or Kernel Space API. The Man Page description is a bit confusing, "... though this usage is not documented here, and for communication with user-space programs..." ❓ 😕. If it is a User Space API then it should be accessible from the Kotlin side, although it appears this API is macro heavy which complicates matters.
    e
    • 2
    • 2
  • m

    martmists

    05/04/2022, 10:53 PM
    In terms of performance, is it better to work with a FloatArray or an allocated CArrayPointer<FloatVar>, or is it about equal? edit: did some testing in this thread, tl;dr is that in release binaries K/N is slightly slower than c++ with no optimization flags but still fast enough for realtime tasks
    :nice: 1
    • 1
    • 3
  • r

    rrva

    05/05/2022, 3:43 PM
    If i am writing a multiplatform lib targeting android, ios and js, what is a good solution for multiplatform caching for example the LoadingCache pattern Lets say i have a
    suspend fun refreshToken(token: Token)
    if the cache is cold, I want to prevent coroutines concurrently refreshing the value I have tried some solutions Semaphore (the coroutine aware one) Actor-like impl with channels but without actor lib. Are there any other simpler/more obvious solutions?
    • 1
    • 2
  • n

    napperley

    05/06/2022, 3:46 AM
    Which performance metrics should be taken into account with a Kotlin Native program? Below is an example of what my program ( https://gitlab.com/napperley/performance-snapshot ) prints to the console:
    ./perf_snap.kexe sunny --useSsh remote_host
    Creating SSH Console report...
    -- sunny Resource Usage --
    Short Process Name: sunny_island_te
    Binary Path: /home/a_user/sunny_island_telemetry.kexe
    Threads Used: 3
    Total Reserved RAM (in KB): 24840
    Binary Size (in bytes): 4149432
    • 1
    • 1
  • m

    MJegorovas

    05/06/2022, 1:45 PM
    Is it possible to observe kotlin class properties in swift? Like with
    ObservableObject
    and
    Published
    in swiftUI.
    h
    j
    • 3
    • 7
  • v

    Vivek Modi

    05/06/2022, 9:38 PM
    Hey guys, I just join this channel. Can someone tell me what kind of questions we can ask here. Thanks 👍
    m
    • 2
    • 2
  • m

    martmists

    05/06/2022, 10:58 PM
    What does this error mean? I'm just redefining some
    #define
    'd functions into actual functions
    e
    • 2
    • 1
  • n

    Nikolay Kasyanov

    05/12/2022, 12:01 PM
    Hey folks 👋 I just stumbled upon the fact that
    Any?.identityHashCode()
    in Native uses object’s memory address only, unlike JVM, where a piece of random data could be used, making
    identityHashCode
    unique even if two objects happen to be allocated at the same memory address during app’s lifetime. Would it make sense to file this as a bug (it’s a noticeable discrepancy with JVM, after all) or is it a conscious decision to have this implementation in Native?
    e
    • 2
    • 2
  • h

    hfhbd

    05/12/2022, 3:27 PM
    Does anybody know an alternative for https://www.testcontainers.org? Or "only" a Kotlin native docker library?
    👍 1
    c
    • 2
    • 3
  • s

    Simon BRUNOU

    05/13/2022, 2:19 PM
    Hey all, I was wondering how to import some Win32 APIs in Kotlin/Native. Basically, I need to convert this C call to a Kotlin/Native one, but I can’t seem to understand if those headers are included in
    platform.windows.*
    or
    platform.posix.*
    .
    #include <Winsock2.h>
    #include <Ws2bth.h>
    #include <BluetoothAPIs.h>
    Those are standard Win32 headers but I can’t find them anywhere on Kotlin/Native. I am developing on macOS 12.4 with an M1 processor, if it matters. Do I need to use cinterop and bind them manually? Or am I looking in the wrong place? Thanks in advance!
    l
    • 2
    • 10
  • m

    martmists

    05/14/2022, 10:19 AM
    Getting an error compiling my code (file in thread)
    e: org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
          File being compiled: /home/mart/git/kaudio-python/src/nativeMain/kotlin/kaudio/nodes/util/InputNode.kt
          The root cause java.lang.IllegalArgumentException was thrown at: org.jetbrains.kotlin.backend.konan.lower.InteropTransformer.visitCall(InteropLowering.kt:1117)
              at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:238)
              at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException$default(CodegenUtil.kt:234)
              at org.jetbrains.kotlin.backend.common.phaser.PerformByIrFilePhase.invokeSequential(performByIrFile.kt:68)
    a
    • 2
    • 2
  • j

    Ji Sungbin

    05/14/2022, 10:21 AM
    Hi, why Kotlin does not allow the use named arguments for function types?
    m
    h
    • 3
    • 5
  • m

    martmists

    05/14/2022, 10:26 PM
    I can't run a gradle build in intellij, I just get this error:
    'void com.jetbrains.cidr.execution.debugger.CidrDebuggerSettings.setLLDBNatvisRenderersEnabled(boolean)'
    a
    • 2
    • 1
  • s

    Sam Stone

    05/15/2022, 4:00 PM
    Does Kotlin native compile to bytecode or c?
    a
    e
    l
    • 4
    • 4
  • a

    Alexander Black

    05/16/2022, 7:33 PM
    This might not be the right place to ask this, (if so let me know)… I’m wondering if anyone else has experienced an issue with SQLDelight on native incrementing primary keys when doing a
    INSERT OR REPLACE INTO (id, ...) VALUES(?, ...)
    operation? So if I had a null id passed in for the primary key… it makes sense, but I’m not passing in a null. Any advice would be helpful.
    k
    • 2
    • 12
  • k

    Karel Petránek

    05/19/2022, 11:36 PM
    I’m trying to implement
    AVCaptureVideoDataOutputSampleBufferDelegateProtocol
    in Kotlin on iOS and the delegate method never gets called (equivalent code in Swift/ObjC works fine). I suspect it’s because of the protocol definition in Kotlin:
    @kotlinx.cinterop.ExternalObjCClass public interface AVCaptureVideoDataOutputSampleBufferDelegateProtocol : platform.darwin.NSObjectProtocol {
        @kotlinx.cinterop.ObjCMethod public open fun captureOutput(output: platform.AVFoundation.AVCaptureOutput, didOutputSampleBuffer: platform.CoreMedia.CMSampleBufferRef? /* = kotlinx.cinterop.CPointer<cnames.structs.opaqueCMSampleBuffer>? */, fromConnection: platform.AVFoundation.AVCaptureConnection): kotlin.Unit { /* compiled code */ }
    
        @kotlinx.cinterop.ObjCMethod public open fun captureOutput(output: platform.AVFoundation.AVCaptureOutput, didDropSampleBuffer: platform.CoreMedia.CMSampleBufferRef? /* = kotlinx.cinterop.CPointer<cnames.structs.opaqueCMSampleBuffer>? */, fromConnection: platform.AVFoundation.AVCaptureConnection): kotlin.Unit { /* compiled code */ }
    }
    Note that both
    captureOutput
    methods have the exact same signature, they only differ in parameter names. It is impossible to override both methods in Kotlin (it’s also impossible to define such interface in Kotlin code) so I suspect some trickery there. Has anyone met this issue before? Is there a workaround to make Kotlin properly override these ObjC methods?
    r
    t
    • 3
    • 7
  • j

    Julian Hille

    05/20/2022, 8:52 AM
    Hey there, im asking myself if there is a possibility to compile kotlin to objectiv c on linux instead of on macos? So far i did not find any documentation about changing the compiler from c/cpp to objc on the linux target. Is this even possible?
    b
    k
    r
    • 4
    • 55
  • c

    Conrad Kramer

    05/23/2022, 8:45 PM
    When Kotlin throws an exception in my iOS and macOS app and it is unhandled, the crash report is not super helpful at the moment The stack track is in
    Kotlin_ObjCExport_trapOnUndeclaredException
    and the “Application Specific Information” which normally contains the exception message (for Swift traps and Objective-C exceptions) just shows
    abort() called
    Is there a way to put the Kotlin exception message inside of the crash report?
    a
    r
    k
    • 4
    • 37
Powered by Linen
Title
c

Conrad Kramer

05/23/2022, 8:45 PM
When Kotlin throws an exception in my iOS and macOS app and it is unhandled, the crash report is not super helpful at the moment The stack track is in
Kotlin_ObjCExport_trapOnUndeclaredException
and the “Application Specific Information” which normally contains the exception message (for Swift traps and Objective-C exceptions) just shows
abort() called
Is there a way to put the Kotlin exception message inside of the crash report?
a

ankushg

05/23/2022, 8:53 PM
We’ve used CrashKiOS for this: https://github.com/touchlab/CrashKiOS I believe it’s also integrated into Kermit?
r

Rick Clephas

05/23/2022, 8:54 PM
I don't believe there is. If I remember correctly folks at Touchlab actually log the unhandeled exceptions at the Kotlin side in their Kermit library. https://github.com/touchlab/Kermit
c

Conrad Kramer

05/23/2022, 8:55 PM
There is
setUnhandledExceptionHook
(which is what they use), so perhaps I could take the exception and crash myself in a way that reports the exception message correctly I do wonder how “Application Specific Information” is populated, though, and if there is a way to get this functionality into Kotlin itself
Because other information goes in there, like the “dyld4 config” and the current selector being performed by AppKit if present
r

Rick Clephas

05/23/2022, 9:00 PM
Yeah. Maybe if you convert the exception to an
NSError
and then send it to ObjC/Swift. From there you could basically throw it or something to get the "normal behavior". Not sure if that would actually work but might be worth to try.
c

Conrad Kramer

05/23/2022, 9:01 PM
I could generate an NSException and throw it
But thankfully Swift is open source and I am figuring out how they do it: https://github.com/apple/swift/blob/b3b080e12d60a558a2155892e771a98b54a7825a/stdlib/public/runtime/Errors.cpp#L264-L295
:nice: 1
👀 1
Looks like it is private API, but it is a DATA section of the process that Swift fills out before aborting (
__crash_info
)
I’ll write a Kotlin library to populate that in the hook and actually let Kotlin finish the abort
🙌🏻 2
Wireshark, Firefox, etc all have implementations of it: https://github.com/wireshark/wireshark/blob/master/wsutil/crash_info.c
a

ankushg

05/23/2022, 9:21 PM
Nice, maybe worth checking with @kpgalligan to see if they’d considered adding that to crashkios and ruled it out for some reason
r

Rick Clephas

05/23/2022, 9:22 PM
Very interesting! Looks like even more info could be attached (like the app specific backtrace).
k

kpgalligan

05/23/2022, 9:26 PM
Interesting. We haven't done that. Obviously I'd be very interested to see what you come up with. On my phone now but will look at source linked when back on the computer
c

Conrad Kramer

05/25/2022, 7:42 AM
Funnily enough, Kotlin tries to do it itself, but it looks like the private API they were using may have broken: https://github.com/JetBrains/kotlin/blob/4c3fb8697b0a2b4bb504557427ec309aedffeaac/kotlin-native/runtime/src/main/cpp/ObjCExceptions.cpp#L100
Actually, they don’t enable that for macOS
k

kpgalligan

05/25/2022, 12:00 PM
That exception writing from the kotlin runtime has been there for years. I don’t know if the api is currently broken, but it used to write to your local device (or the buffer it wrote to wrote to your local device). It never surfaced to remote exception loggers (Crashlytics, etc), which was (is) our goal, so we didn’t try too much with it.
I’ve been poking around this since you posted, so I have some more thoughts (and old things coming back from long term memory).
Crashlytics is aware of the
__crash_info
structure (https://github.com/firebase/firebase-ios-sdk/blob/35669875acdb8d27503feead0d8a2b3d3a0fe19c/Crashlytics/Crashlytics/Components/FIRCLSProcess.c#L752), but it seems to only care about the
message
field (https://github.com/firebase/firebase-ios-sdk/blob/35669875acdb8d27503feead0d8a2b3d3a0fe19c/Crashlytics/Crashlytics/Components/FIRCLSProcess.c#L804). I was getting excited that maybe the
backtrace
field (https://github.com/firebase/firebase-ios-sdk/blob/35669875acdb8d27503feead0d8a2b3d3a0fe19c/Crashlytics/Crashlytics/Components/FIRCLSProcess.c#L756) would be the magic key, but as far as I can see, at least Crashlytics doesn’t care about it.
Now, is it possible that I’m just looking in the wrong place? Absolutely. I’m not sure when I’ll get time to finish it, but I’ve been setting up a little C code to write to those fields and see what comes out, but C isn’t exactly my strong suit, and obviously there isn’t a lot of documentation out there, so we’ll see.
From what I can tell, Crashlytics grabs the state of all threads stacktraces at abort time and writes them out, so for our purposes (full stack trace), I don’t think it’ll work.
My approach prior to this thread was appending the stack info before sending the crash. Bugsnag at least lets you inspect and modify crash reports before they’re sent to the server, so the Kotlin unhandled exception callback can write the Kotlin stack, and add it after restart, but there’s a lot left to figure out there, and I’m not sure Crashlytics or others allow the same.
It does technically work, though.
However, looking back on the thread, I don’t think you cared so much about remote tools? On the
__crash_info
, I think the piece, or one of the pieces, that I’m missing is what actually gets put in there, and who is intended to read it? I did go through the wireshark and firefox code, but only lightly. I’m definitely not set up for local native dev like that, so I’ve just been reading source. I think writing to it would be easy enough if I understand what’s happening, although I wouldn’t know what to write. Also, I have that background concern of if this is actually a private api, does that mess with app store submissions? That last one is a bit down the road as far as worries go, but still.
Anyway, that’s where I’m at this morning. I rabbit holed a bit on this yesterday, but there’s a whole bunch of things I really should be focused on this week, so I’m probably not going to make much progress for a bit.
r

Rick Clephas

05/25/2022, 2:42 PM
Also, I have that background concern of if this is actually a private api, does that mess with app store submissions?
As long as Swift is using the same that shouldn’t be an issue, right? Also if Crashlytics is aware of it then it’s already part of your app.
k

kpgalligan

05/25/2022, 3:23 PM
It doesn’t seem like
__crash_info
is a problem, but I’m not sure that it’s considered private either. Poorly documented for sure, but not sure it’s something Apple cares about. but, again, I’m also not sure it’ll do much for the crash reports, at least for stack traces.
👍 1
r

Rick Clephas

05/25/2022, 3:52 PM
Bugsnag at least lets you inspect and modify crash reports before they’re sent to the server … and I’m not sure Crashlytics or others allow the same.
Yes if automatic collection is disabled you can update the report before it’s send: https://firebase.google.com/docs/reference/swift/firebasecrashlytics/api/reference/Classes/Crashlytics#checkandupdateunsentreports Though there is no field for a stacktrace, but you could add it as logs or as a custom value or something.
c

Conrad Kramer

05/25/2022, 4:09 PM
Yeah, a few things: • I care primarily about local crash reports. I run UI integration tests on GitHub actions and my app crashes in one, but the report in the xcresult was useless, which is why I am looking into this in the first place • As for reporting, I am always just going to use Apple’s crash reporting functionality. On macOS I might have a custom reporting functionality, but it will still use the Apple crash reports that are written to disk. Out of process crash reporting is just more robust • The backtrace functionality does work – NSException actually uses it. I remember reading a lot of “Application Specific Backtrace” sections when I was reading reports at Apple. I plan on populating it with the Kotlin exception’s backtrace • Kotlin’s built in exception reporting is very much a hack. I'll likely write a diff for the Kotlin runtime to use crash_info (as that is where it belongs, in the runtime), but compiling Kotlin sounds like a PITA • Haven't gotten it working locally quite yet, but working on it
k

kpgalligan

05/25/2022, 5:12 PM
when I was reading reports at Apple
Apologies in advance for the endless list of questions I might throw at you in the future
As for reporting, I am always just going to use Apple’s crash reporting functionality
We’re primarily focused on 3rd party tools, but that’s mostly because that’s what our clients are using. Certainly interested to see what you figure out.
The backtrace functionality does work – NSException actually uses it. I remember reading a lot of “Application Specific Backtrace” sections
I’d definitely love to see how this works. The apple-side internals are a bit out of my wheelhouse, and I’m not sure the 3rd party tools wouldn’t report this, but would need to try it and see how it goes.
I’ll likely write a diff for the Kotlin runtime to use crash_info (as that is where it belongs, in the runtime), but compiling Kotlin sounds like a PITA
I wouldn’t say compiling Kotlin is the easiest, but it’s not too bad once you get it set up. We’re hacking around compiler changes now. If you have thoughts on what that should look like we might be able to try some things our, or just assist getting local dev working for you if needed.
c

Conrad Kramer

05/26/2022, 6:16 PM
I got it working in pure Kotlin. Originally, I had some C code to generate a
__crash___info
section, but the crash info section seemingly only gets checked for system libraries. I updated the code to find an existing section in a system library and write to that
k

kpgalligan

05/26/2022, 6:19 PM
That’s interesting. This is definitely a bit out of my wheelhouse, but I’m surprised you can write that to a system library. I’d definitely like to try this out if you make anything public and/or just post some code. I’d like to see if the crash reporting libraries we’re using pick up that data.
👍 1
c

Conrad Kramer

05/26/2022, 6:22 PM
It is the data section of a system library, which is read write (it writes to it just as the system library itself would) but yes! I am landing it in my codebase first: https://github.com/conradev/Wallet/pull/9/files but I will consider making it into a Kotlin library that people can drop in later – have never made or setup a Kotlin library on Github before
👀 1
Firefox and Chrome both have functionality to read the info out, at least the message part
k

kpgalligan

05/26/2022, 6:29 PM
Yeah, I saw that for both. Crashlytics does that too, but again, just the message. Not sure they don’t also get the rest, but the only code that used the defined structure for that data type (that I could find) was pulling the message string. We also use bugsnag and I haven’t started poking around the client code for that. In any case, I’d love to see if anything interesting makes its way out after stuffing data in.
I was curious about the signature. Wasn’t sure if one needed to worry about that. Guess not 🙂
If you want to do a library, we work on that quite a bit, so can chat/answer questions.
There’s not much different, except sometimes publishing.
View count: 14