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
multiplatform
  • l

    Lukasz Ciastko

    04/15/2022, 1:53 PM
    Hi. Can someone instruct me how to create a Kotlin Multiplatform Mobile project with App Code? The new plugin doesn’t seem to work. I select a new project and Application -> Kotlin Multiplatform Mobile. Then I enter the name and click Finish. I select a folder and click Open. The IDE goes back to the Welcome to AppCode window.
    d
    t
    • 3
    • 4
  • v

    Vivek Modi

    04/15/2022, 1:59 PM
    Hey guys i am trying to communicate between kmm module and application. I tried to implement interface. In androidMain
    actual class Platform actual constructor() {
         actual val versionCode = AppConfig.versionCode
    }
    
    interface AppConfig {
        val versionCode: String
    }
    But I am getting error
    g
    j
    • 3
    • 6
  • j

    julioromano

    04/15/2022, 4:01 PM
    I’m trying to compile multiple KMM modules into a single iOS framework using the so called “shared umbrella module”. I’ve noticed that when compiling such module Gradle says it has no source:
    > Task :shared:compileKotlinIosSimulatorArm64 NO-SOURCE
    > Task :shared:linkDebugFrameworkIosSimulatorArm64 NO-SOURCE
    > Task :shared:assembleDebugAppleFrameworkForXcodeIosSimulatorArm64 NO-SOURCE
    Which is true because technically there is no source file in that module, it only includes other modules as dependencies. Nevertheless no actual framework is generated and the next Gradle task fails with:
    > Task :shared:embedAndSignAppleFrameworkForXcode FAILED
    cp: /.../project/shared/build/xcode-frameworks/Debug/iphonesimulator15.4/shared.framework: No such file or directory
    The same umbrella module works fine if imported from the android app (I can use and see all its transitive dependencies). How to debug this?
    ✅ 1
    r
    • 2
    • 1
  • j

    julioromano

    04/15/2022, 7:36 PM
    Getting an
    Undefined symbols for architecture arm64
    during a KMM build (using sqldelight). See 🧵 for full error log. It seems similar to https://github.com/cashapp/sqldelight/issues/1442 but it’s not the same exact missing symbols. What could this be? (perhaps related to: https://kotlinlang.slack.com/archives/C3PQML5NU/p1650038479860419)
    ✅ 1
    k
    • 2
    • 12
  • j

    James Black

    04/17/2022, 2:10 AM
    In my shared code I have this and would a contract make sense here to so I don't have to force unwrap or use the null checks where I call the add function? I am trying to understand where the contract keyword makes sense.
    fun addClothingToClothingWeather(clothing:ClothingTypes) {
            if(clothingWeatherData == null) clothingWeatherData = ClothingWeatherModel()
            clothingWeatherData!!.clothing?.toMutableList()?.add(clothing)
        }
    
    @Serializable
    data class ClothingWeatherModel(val clothing:List<ClothingTypes>? = emptyList(), val temperature:MainTemperature? = null, val situation:Situations? = null)
    r
    • 2
    • 2
  • m

    martmists

    04/17/2022, 1:37 PM
    How do I enable context receivers in common code? Using the following in gradle:
    tasks.withType<KotlinCompile> {
        kotlinOptions.jvmTarget = "1.8"
        kotlinOptions.freeCompilerArgs = listOf("-Xcontext-receivers")
    }
    
    tasks.withType<Kotlin2JsCompile> {
        kotlinOptions.freeCompilerArgs = listOf("-Xcontext-receivers")
    }
    
    tasks.withType<KotlinCompileCommon> {
        kotlinOptions.freeCompilerArgs = listOf("-Xcontext-receivers")
    }
    
    tasks.withType<KotlinNativeCompile> {
        kotlinOptions.freeCompilerArgs = listOf("-Xcontext-receivers")
    }
    And then inspecting it in File -> Project Settings -> Modules shows it being added to every target except commonMain/commonTest
    e
    t
    • 3
    • 5
  • a

    Arjan van Wieringen

    04/17/2022, 5:52 PM
    Hi all, I am getting compilations errors with the new context receivers. I have configured it as follows:
    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class).all {
        kotlinOptions.freeCompilerArgs = listOf("-Xcontext-receivers")
    }
    And my context receiver is simple:
    context(Node.BuilderScope)
    fun foo() {
    // nothing here yet
    }
    The error I am getting:
    java.lang.IllegalStateException: FULL: FUN name:foo visibility:public modality:FINAL <> (<this>:nl.avwie.vdom.Node.BuilderScope) returnType:kotlin.Unit
     Ir: nl.avwie.vdom#foo(nl.avwie.vdom.Node.BuilderScope){}
     Descriptor: nl.avwie.vdom#foo!nl.avwie.vdom.Node.BuilderScope(){}
    
    	at org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker$visitDeclaration$2.invoke(ManglerChecker.kt:96)
    	at org.jetbrains.kotlin.backend.common.serialization.mangle.ManglerChecker$visitDeclaration$2.invoke(ManglerChecker.kt:95)
    • 1
    • 2
  • p

    phuc.tran

    04/18/2022, 6:08 AM
    Hello everyone. I’m new to compose 🙂 I am trying to create a multiplatform project (android, iOS, web, desktop). I found this repository with multi platform set up: https://github.com/joreilly/PeopleInSpace Is there any reference that I can follow to setup similar project with those modules?
    j
    • 2
    • 9
  • h

    Hasan Nagizade

    04/18/2022, 6:32 AM
    Hi everyone 🙂 I am new to Kotlin Multiplatform. Here’s my typical package structure for an Android app that I follow in every project I work. I usually use MVVM+Clean Architecture+Koin for DI in my Android apps. I have read a lot of articles regarding KMM. Most examples have one module for ios one for android one shared and so on. But if you follow MVVM+CLEAN you must have at least 4 modules. I just don’t know what should I do. Should I create all of that modules as packages inside shared module or should I create other modules myself? in app module I initialise dependency injection in presentation module I create UI and everything related to UI. data and domain modules are used for business logic, repositories,use cases,models and so on. Now with KMM I feel confused. Should I treat androidApp module as my presentation module and put the rest of the code in shared module? Thank you very much in advance.
    j
    x
    • 3
    • 4
  • h

    handstandsam

    04/18/2022, 1:26 PM
    Is there any sort of tool or plugin to go from a
    java-library
    to a
    kotlin("multiplatform")
    project configuration? I'm looking to slowly introduce Kotlin Multiplatform on a few modules that currently only target the JVM. I'd like a way to swap between the two so there is less hesitation from other developers to give it a try. Basically it would make the KMP module "backwards compatible" to just a java-library, and completely avoid any references to multiplatform plugins when it was switched off. Goals: • Just change "myplugin.jvm.lib" to "myplugin.kmp.lib". • This would take all
    dependencies
    from the java-library and make them dependencies on
    commonMain
    . • It would be nice to just change one line and see if it compiles to Kotlin Multiplatform as
    commonMain
    . I've given this a try, but when trying to map dependencies I get:
    Unresolved reference: implementation
    because it should be a
    commonMain
    dependency instead. I've thought about two ways of approaching this: • See if I can just iterate through declared dependencies, move them to commonMain, and remove them from the default dependencies block. • Create a custom "commonDependencies {}" extension that can then map to either. I'm looking at how I can do this, but wanted to see if any tools or processes currently exist to make a one-line backwards compatible (java-library instead of kotlin("multiplatform")) module?
    j
    e
    • 3
    • 22
  • d

    Dan Katz

    04/18/2022, 5:22 PM
    Are there any good resources to help getting an existing kotlin multi platform project setup with AppCode? Any tricks to getting breakpoints in Kotlin code when building to an iOS device?
    t
    • 2
    • 1
  • d

    David Gonzalez

    04/19/2022, 2:39 PM
    Hey, is there a Gradle plugin/task to publish an iOS framework to a private repo? If not, which other way to handle framework distribution?
    d
    h
    • 3
    • 3
  • l

    Lucas Schiavini

    04/19/2022, 2:39 PM
    Hmmmm my ios app can't see default implementations on interface methods on kotlin. Anyone seen that as well?
    g
    • 2
    • 1
  • m

    Mendess

    04/19/2022, 4:22 PM
    Which kotlin/js compiler should I choose? LEGACY or IR
    d
    g
    r
    • 4
    • 5
  • s

    Sunny

    04/19/2022, 6:02 PM
    Hi Need inputs on the folllowing 1. Can we disable tests for a particular platform from commonTest, like disable for js platform 2. Any way to get it running for JS platform for the given error
    Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':database:jsBrowserTest'.
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:145)
    	at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:143)
    	at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:131)
    	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:77)
    	at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    	at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
    	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
    	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
    	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
    	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    	at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:74)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:402)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:389)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:382)
    	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:368)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
    	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
    	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
    Caused by: java.util.NoSuchElementException: No value present
    d
    • 2
    • 1
  • k

    kierans777

    04/20/2022, 1:06 AM
    I'm trying to port a Kotlin lib (the module is called
    sdk
    in the project) to iOS. When I run
    ./gradlew build
    the
    compileKotlinMetadata
    step fails. How can I fix this please? (I've moved the CLI output into the thread)
    e
    • 2
    • 5
  • b

    brabo-hi

    04/20/2022, 2:48 AM
    Hi all, what do you recommend as a good testing framework for a kmm mobile app
    j
    • 2
    • 2
  • m

    Mendess

    04/20/2022, 9:51 AM
    I'm trying to export a class with an array, something like this
    class Foo<T>(val array: Array<T>)
    but when I annotate with
    @JsExport
    I get the warning saying Array is not exportable, but the docs seem to suggest otherwise. error:
    Exported declaration uses non-exportable property type: Array<T>
    docs: https://kotlinlang.org/docs/js-to-kotlin-interop.html#kotlin-types-in-javascript
    g
    • 2
    • 10
  • e

    eygraber

    04/20/2022, 2:28 PM
    I'm looking to make a multiplatform Uri parsing library. I see 3 options for doing so. I have a feeling any one of them are ok, but is one "better" than the rest? 1. Write an RFC compliant implementation from scratch (I started doing this but I realized I'd run out of time that I allocated for this project) 2. Use expect/actual and delegate to platform functionality; Android
    Uri
    , JS
    URL
    , iOS
    swift-URI
    , Native haven't found anything yet (all the implementations have slightly different behavior + I haven't found a simple solution for native) 3. Port an existing implementation to KMP I've started all 3 approaches, and I'm leaning towards #3, and porting Android
    Uri
    j
    • 2
    • 1
  • s

    Slackbot

    04/20/2022, 3:57 PM
    This message was deleted.
    r
    j
    • 3
    • 2
  • k

    kierans777

    04/21/2022, 2:06 AM
    In my MPP app I'm trying to create an
    NSDecimal
    from a
    String
    . However I'm not sure how to as the
    NSDecimal
    constructor only takes a
    NativePtr
    argument. Can someone tell me how to do this please? 😄
    r
    e
    k
    • 4
    • 8
  • b

    benkuly

    04/21/2022, 5:50 AM
    Are there plans from JetBrains for a multiplatform crypto library? Iirc it was one of the most upvoted features here in slack, when someone from JetBrains asked for missing features.
    👍 1
    ➕ 1
    o
    z
    • 3
    • 11
  • e

    eygraber

    04/21/2022, 6:40 AM
    Using Kotlin 1.6.21 I'm adding dependencies to my
    commonMain
    source set, but Intellij 2022.1 can't resolve them (building via command line works fine). Android Studio Bumblebee works fine. Is that expected?
    a
    • 2
    • 16
  • m

    martmists

    04/21/2022, 12:59 PM
    How should I go about publishing a multiplatform native library? Github actions is building them, but since they all have the name "native" it seems to cause some conflicts when publishing to maven, any ideas? I tried changing it to build all 3 but then it refuses to commonize properly and I'm afraid of that causing issues when publishing
    a
    • 2
    • 11
  • a

    ansman

    04/21/2022, 2:16 PM
    So I’m trying to export
    Map
    types to JS so I added a
    MapWrapper<K, V> : Map<K, V
    that is `@JsExport`ed. But even if I manually override the method they still don’t end up in the typescript definitions. It seems that all functions that are declared in a non exported interface are not included in the export. Does anyone know of a workaround?
    a
    m
    • 3
    • 2
  • j

    Jose Garcia

    04/21/2022, 3:27 PM
    One of my tests is failing on
    myproject:iosX64Test
    iosX64 target but is passing on
    myproject:iosSimulatorArm64Test
    . How could I find the reason for this happening? Does anything to do with the fact I am using an Arm64 chip (Apple M1)?
    r
    d
    k
    • 4
    • 29
  • m

    martmists

    04/21/2022, 5:14 PM
    How do I build a project with cinterops for multiple platforms? adding cinterops to all targets results in it failing to build cinterops for windows on linux (build.gradle.kts and error log in thread)
    a
    • 2
    • 9
  • j

    julioromano

    04/21/2022, 9:54 PM
    I’m having a hard time transitioning a working KMP project from
    embedAndSignAppleFrameworkForXcode
    to cocoapods ( following docs at: https://kotlinlang.org/docs/native-cocoapods-xcode.html ). Whenever I try to launch the iosApp (both from within Android Studio and Xcode) it fails with:
    ld: framework not found Pods_iosApp
    . It seems the linker cannot find the framework generated by cocoapods? Any idea how to debug this?
    ✅ 1
    • 1
    • 1
  • k

    kpgalligan

    04/21/2022, 10:37 PM
    Hard to say without looking at it. It’s an xcode/build thing rather than a Kotlin-specific thing, though. First to try is check which file you have opened in Xcode. I’d close Xcode, and make sure you open the
    *.xcworkspace
    rather than
    *.xcodeproj
    . When you use cocoapods, you need to open a different project file. I don’t know that AS would still be failing, though (not sure how the plugin picks project configs, and I use Xcode most of the time)
    ✅ 1
    :thank-you: 1
    j
    • 2
    • 4
  • e

    eygraber

    04/21/2022, 10:55 PM
    I'm trying to port some JVM code to native code, and I need to replicate some
    ByteBuffer
    code. I'm using ktor-io but there's something that I'm not doing correctly. Code in 🧵
    e
    • 2
    • 8
Powered by Linen
Title
e

eygraber

04/21/2022, 10:55 PM
I'm trying to port some JVM code to native code, and I need to replicate some
ByteBuffer
code. I'm using ktor-io but there's something that I'm not doing correctly. Code in 🧵
Here's what I'm porting:
if (byteBuffer.position() == 0) {
  return;
}
byteBuffer.flip();
try {
  builder.append(decoder.decode(byteBuffer));
} catch (CharacterCodingException e) {
  if (throwOnFailure) {
    throw new IllegalArgumentException(e);
  } else {
    builder.append(INVALID_INPUT_CHARACTER);
  }
} finally {
  // Use the byte buffer to write again.
  byteBuffer.flip();
  byteBuffer.limit(byteBuffer.capacity());
}
Here's my code (an extension function on
Buffer
):
if(writePosition == 0) return

resetForRead()

try {
  builder.append(readBytes().decodeToString())
}
catch(e: Exception) {
  if(throwOnFailure) {
    throw IllegalArgumentException(e)
  }
  else {
    builder.append(INVALID_INPUT_CHARACTER)
  }
}
finally {
  reset()
}
The problem is that a bunch of 0s are showing up when I call
readBytes
(this is after writing 1 byte to the buffer then calling my function, then writing 3 bytes to the buffer then calling my function, then writing 3 bytes to the buffer then calling my function):
47, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-60, -126, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-32, -95, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
e

ephemient

04/21/2022, 11:21 PM
you should probably indicate which
Buffer
you're using. doesn't seem to be okio.Buffer
if it's io.ktor.utils.io.core.Buffer, I've no experience with it but
resetForRead()
doesn't seem to be equivalent to `flip()`: it marks the whole buffer as readable, not just the part up to the write position
e

eygraber

04/21/2022, 11:25 PM
It's ktor's
Buffer
but my IDE is having issues resolving dependencies, so it's hard to step through it to see how it works. I'm assuming there's a way to do it with
okio.Buffer
as well?
e

ephemient

04/21/2022, 11:28 PM
with okio there's usually enough helpers build on (Buffered)Source, (Buffered)Sink, Pipe, etc. that there's no need to work on Buffer directly
e

eygraber

04/21/2022, 11:37 PM
Although looking at the problem again after some sleep I can probably make a simple wrapper around a byte array for this use case.
View count: 16