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

    nevardreik

    01/25/2022, 4:43 AM
    Hello, i’m wondering if someone might be able to assist with a KMM issue im experiencing since upgrading Kotlin from
    1.5.21
    ->
    1.5.30
    … The issue im experiencing is specifically with
    packForXcode
    where Gradle is returning an error messae all of a sudden
    * What went wrong:
    Could not create task ':mobile-shared:packForXcode'.
    > Key releaseFramework is missing in the map.
    I have had a look around online first for solutions, but really can’t see any resolutions or hints to point me in the right direction. Anyone have any ideas? I’ll post my
    packForXcode
    task as a thread comment.
    a
    n
    3 replies · 3 participants
  • t

    Travis Reitter

    01/25/2022, 7:48 AM
    I can currently build the iOS app that relies upon my KMM module but the Kotlin files in
    iosMain
    , when viewed in Android Studio, have broken syntax highlighting and I get a warning that Kotlin is not configured. If I configure it for the module, I get some extra blocks added to my KMM module's Gradle file (as well as my Android app's Gradle file) which doesn't fix the syntax highlighting in the
    iosMain
    Kotlin files. It also breaks my Android app config and seems to make some other broken configuration (like adding
    classpath(kotlinModule("gradle-plugin", kotlin_version))
    where
    kotlinModule
    can't be resolved) and adding
    androidx-core:core-ktx:+
    and
    stdlib-jdk7
    to my KMM module's dependencies (not just for
    androidMain
    ) What's the proper way to configure Kotlin for
    iosMain
    and fix the syntax highlighting?
    l
    5 replies · 2 participants
  • n

    Nilay Dağdemir

    01/25/2022, 12:21 PM
    Hi all, I’m experiencing framework creation problem on KMM when try to run it on Mac Mini with M1 silicon chip. I’m receiving this error when try to build Xcode project with an embedAndSignFramework task execution as a build phase:
    * What went wrong: Task 'embedAndSignAppleFrameworkForXcode' not found in project ':shared'.
    This error occures only on Mac Mini with M1 silicon chip. It works well on Macbook with an intel chip. I tried every solution online, nothing worked. Do you have any idea how to fix this?
    a
    2 replies · 2 participants
  • i

    Imran/Malic

    01/25/2022, 2:51 PM
    Hi all, I am in kotlin
    1.6.10
    and using the Regex:
    Regex("^?(//(?<authority>((?<userinfo>[^/?#]*)@)?(?<host>(\\[[^\\]]*\\]|[^/?#:]*))(:(?<port>[^/?#]*))?))?(?<path>[^?#]*)(\\?(?<query>[^#]*))?(#(?<fragment>.*))?")
    I am running into an issue running tests against js and nativ platforms: <stacktrace is below> The error points to the second
    /
    at the beginning
    ^?(//
    of the expression. But I am not getting smarter from the error message
    e
    2 replies · 2 participants
  • m

    Michael Paus

    01/25/2022, 3:29 PM
    This is probably a stupid question but why does IntelliJ generate Java-dependent code in the commonMain part of a multi-platform project? You can find an example in the thread.
    e
    4 replies · 2 participants
  • j

    Johannes Fahrenkrug

    01/25/2022, 6:51 PM
    When using
    1.6.20-dev-7317
    (both for
    kotlin("multiplatform")
    and for
    kotlin("native.cocoapods")
    , I get
    Unresolved reference: cocoapods
    when trying to import
    cocoapods
    in a .kt file. For example
    import cocoapods.libsodium.crypto_sign_state
    . This worked fine with
    1.6.10
    . Do I need to do this kind of import differently when using
    1.6.20
    ?
    v
    1 reply · 2 participants
  • t

    tylerwilson

    01/25/2022, 10:22 PM
    Building my shared code as an XCFramework, which include targets iosArm32, iosArm64, iosX64, watchos, macos, takes 28 minutes! Any tips on ways to speed this up, if any? Do we expect the new front-end compiler might help here?
    e
    t
    10 replies · 3 participants
  • p

    Peter Hsu

    01/25/2022, 11:50 PM
    Does anyone have any advice around modularization or know of any documentation or project samples for multi-module KMM compiling to XCFramework? I have a highly modularized project and would prefer to have a single framework generated for use by my iOS App. I included dependencies to my KMM app in iosMain via
    api(project(":some:domain"))
    , but when I look at the generated header files in the framework, I don't see any reference to the classes in some:domain
    j
    r
    +2
    10 replies · 5 participants
  • v

    Vivek Modi

    01/26/2022, 12:11 AM
    Hey I want to learn mutliplatform to create module for my android and ios project. For same business logic to share. Any guide how can I start or any tutorial for that ?
    d
    a
    3 replies · 3 participants
  • d

    Dave Trollope

    01/26/2022, 3:51 AM
    I'm trying to get started again with iOS development on KMM and upgraded gradle, the plugs, AndroidStudio etc. And when I run or debug the getting started example https://kotlinlang.org/docs/kmm-create-first-app.html for iOS, the build succeeds but the run/debug fails with: Error returned in reply: Connection invalid
    /Users/davetrollope/AndroidStudioProjects/KMMEG2022B/build/ios/Debug-iphonesimulator/iosApp.app
    Error returned in reply: Connection invalid
    com.intellij.execution.ExecutionException: Error returned in reply: Connection invalid
    
    Process finished with exit code 0
    Android project runs fine. Ideas? (edited)
    a
    3 replies · 2 participants
  • p

    Paul Weber

    01/27/2022, 5:59 PM
    Could someone point me to a working Github Action for building (or testing) a KMM iOS app with cocoapods integration? Somehow the shared pod doesn’t get linked properly and I’m all out of ideas.
    e
    k
    +1
    12 replies · 4 participants
  • j

    John Aoussou

    01/28/2022, 2:30 AM
    Is there a way to record audio with an external microphone in KMM (desktop) ?
    d
    2 replies · 2 participants
  • c

    chansek

    01/28/2022, 6:16 AM
    In my common module of KMM, I have this data class:
    data class UserRole(
        val entity: Entity,                            
        val role: Role,
        val entityId: String
    ) {
    
        fun isAdmin() = role == Role.ADMIN
    }
    When I do serialize it, I get
    admin
    as a property. How can I avoid that?
    g
    3 replies · 2 participants
  • t

    Travis Reitter

    01/28/2022, 6:35 PM
    what's the recommended acronym? I've seen both "KMP" and "KMM"
    i
    c
    +3
    9 replies · 6 participants
  • j

    Jeff Lockhart

    01/28/2022, 8:54 PM
    After upgrading to Android Studio Bumblebee, I'm now getting an error during the gradle sync:
    Execution failed for task ':shared:podGenIOS'.
    > 'pod gen' command failed with an exception:
       Cannot run program "pod" (in directory "/.../shared/build/cocoapods/synthetic/IOS"): error=2, No such file or directory
              
              Possible reason: CocoaPods is not installed
              Please check that CocoaPods v1.10 or above and cocoapods-generate plugin are installed.
              
              To check CocoaPods version type 'pod --version' in the terminal
              
              To install CocoaPods execute 'sudo gem install cocoapods'
              To install cocoapod-generate execute 'sudo gem install cocoapods-generate'
    cocoapods
    and
    cocoapods-generate
    are both installed and work when executed from the terminal. The build worked before the Android Studio upgrade as well.
    ./gradlew :shared:podGenIOS
    also works on the command line and after completion, the AS gradle sync completes successfully, until it fails again later. Has anyone else experienced anything like this or have any idea what the issue might be?
    l
    b
    6 replies · 3 participants
  • r

    Rohan Maity

    01/29/2022, 9:08 AM
    Hello, is there any Dependency Injection library which could be used for Multi-platform project target android, Web (JS), iOS and desktop ?
    m
    a
    +4
    22 replies · 7 participants
  • j

    jean

    01/29/2022, 9:19 PM
    I’m trying to create a new kmm project using cocoapods in android studio but I keep getting this warning
    Dependency on pods requires cocoapods-generate plugin to be installed.
    If you plan to add dependencies on third party pods, don’t forget to install it by executing ‘gem install cocoapods-generate’ in terminal.
    and this error
    Execution failed for task ':shared:podInstall'.
    > 'pod install' command failed with code 1.
      Error message:
      
             Please, check that podfile contains following lines in header:
             source '<https://cdn.cocoapods.org>'
      
              Please, check that each target depended on shared contains following dependencies:
    I did follow this 7-steps https://youtrack.jetbrains.com/issue/KT-49418#focus=Comments-27-5429773.0-0 but it still doesn’t work. I had to adjust it a bit since I have a Mac/Intel computer. I added this to my
    ~/.zshrc
    export LANG=en_US.UTF-8
    export PATH="/usr/local/opt/ruby@2.7/bin:/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"
    I did try both
    sudo gem install -n /usr/local/bin cocoapods
    sudo gem install -n /usr/local/bin cocoapods-generate
    and
    sudo gem install cocoapods
    sudo gem install cocoapods-generate
    Anything else I should try?
    v
    1 reply · 2 participants
  • y

    Yevhen Railian

    01/30/2022, 2:03 PM
    Hello everyone. All examples that i saw with shared module with KMM were as a single project for both platforms. We have two different repositories on github for iOS and for Android. Is it possible to move shared module to the separate github repository and configure it with KMM plugin somehow to start using it with existing repositories without merging theme to one? I did not find it in the documentation. Thanks.
    :yes: 2
    s
    g
    +1
    6 replies · 4 participants
  • n

    Nilay Dağdemir

    01/31/2022, 12:08 PM
    Hello all, By default do kotlin 1.6.0 creates the shared framework for iOS with bitcode enabled or should I write the code below on the build gradle file?
    kotlin {
    iosArm64(*"myapp"*) {
    binaries {
    framework {
    embedBitcode(*"bitcode"*) // for release binaries.
    }
    }
    }
    }
    I searched but couldn’t find a clear answer about this subject. *I’m not using cocoapods
    v
    u
    8 replies · 3 participants
  • l

    Lukasz Kalnik

    01/31/2022, 11:02 PM
    I use a shared ViewModel in an Android/iOS app. I inject some dependencies there with Koin. However when trying to write data to the
    apiConfigRepository
    dependency I get the exception `mutation attempt of frozen ApiConfigurationRepositoryImpl@1edb608`:
    class TVShowsSharedViewModelImpl(
        dispatcher: CoroutineDispatcher = Dispatchers.Main
    ) : TVShowsSharedViewModel,
        KoinComponent {
    
        val coroutineScope = CoroutineScope(dispatcher)
    
        val tmdbApi: TmdbApi by inject()
        val apiConfigRepository: ApiConfigurationRepository by inject()
    
        init {
            coroutineScope.launch {
                val apiConfig = tmdbApi.getConfiguration()
                with(apiConfigRepository) {
                    imageBaseUrl = apiConfig.images.baseUrl
                    updateBackdropSizes(apiConfig.images.backdropSizes)
                }
            }
        }
    }
    l
    2 replies · 2 participants
  • y

    ynsok

    02/01/2022, 12:15 PM
    Hi 😄 I have a multiplatform project targeting Desktop and Android. I would like to use the library for navigation voyager, but unfortunately, I’m getting this error.
    Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option
    Any suggestion how to solve it ?
    b
    d
    6 replies · 3 participants
  • m

    martmists

    02/01/2022, 2:23 PM
    I'm trying to test my multiplatform project but I'm getting
    e: /home/mart/git/command_parser/src/commonTest/kotlin/CommandTests.kt: (7, 15): Unresolved reference: test
    e: /home/mart/git/command_parser/src/commonTest/kotlin/CommandTests.kt: (8, 15): Unresolved reference: test
    e: /home/mart/git/command_parser/src/commonTest/kotlin/CommandTests.kt: (11, 6): Unresolved reference: Test
    e: /home/mart/git/command_parser/src/commonTest/kotlin/CommandTests.kt: (23, 13): Unresolved reference: assertTrue
    despite having this in my build.gradle.kts:
    val commonTest by getting {
                dependencies {
                    implementation("org.jetbrains.kotlin:kotlin-test-common:1.6.10")
                    implementation("org.jetbrains.kotlin:kotlin-test-annotations-common:1.6.10")
    
                    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
                    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0")
                }
            }
    and the code for testing is
    import com.martmists.commandparser.dispatch.Context
    import com.martmists.commandparser.dispatch.Dispatcher
    import com.martmists.commandparser.dsl.build
    import kotlinx.coroutines.Dispatchers
    import kotlinx.coroutines.*
    import kotlinx.coroutines.test.runTest
    import kotlin.test.Test
    import kotlin.test.assertTrue
    
    class CommandTests {
        @Test
        fun testNoArgs() = runTest {
            launch(Dispatchers.Main) {
                val dispatcher = Dispatcher<Context>()
                build(dispatcher) {
                    command("test") {
                        action {
                            println("test success")
                        }
                    }
                }
                val ctx = Context("test")
                assertTrue(dispatcher.dispatch(ctx))
            }
        }
    }
    j
    1 reply · 2 participants
  • p

    Paul Woitaschek

    02/01/2022, 3:41 PM
    This the following statement correct? HMPP does not have any affect on the created frameworks and can be turned off when testing on the CI server and when publishing only jvm + android libraries to maven
    j
    1 reply · 2 participants
  • a

    Alen Kirm

    02/01/2022, 4:28 PM
    Hey KMM Community! Not sure if this is a bug, but looks like
    baseName
    property is ignored, when running
    module:assembleXCFramework
    Gradle task. Output XCFramework is named by the module itself (shared.XCFramework) and the same applies to fat-frameworks. Is this known issue, or am I missing the purpose of
    baseName
    property ? Thanks.
    👍 1
    p
    3 replies · 2 participants
  • g

    gbaldeck

    02/01/2022, 7:04 PM
    Im looking at the documentation for setting up multiple targets in Gradle. For example JS browser and JS node. How do I go about applying those to specific source sets? I dont see anything in the documentation on that.
    m
    a
    2 replies · 3 participants
  • i

    Igor Milakovic

    02/02/2022, 7:05 PM
    Anyone else getting thousands of warnings (on iOS) after integrating Ktor 1.6.7?
    warning: (x86_64)  could not find object file symbol for symbol _kfun:io.ktor.utils.io.ByteChannelSequentialBase#<get-readByteOrder>(){}io.ktor.utils.io.core.ByteOrder
    warning: (x86_64)  could not find object file symbol for symbol _kfun:io.ktor.utils.io.ByteChannelSequentialBase#<set-readByteOrder>(io.ktor.utils.io.core.ByteOrder){}
    warning: (x86_64)  could not find object file symbol for symbol _kfun:io.ktor.utils.io.ByteChannelSequentialBase#<get-writeByteOrder>(){}io.ktor.utils.io.core.ByteOrder
    warning: (x86_64)  could not find object file symbol for symbol _kfun:io.ktor.utils.io.ByteChannelSequentialBase#<set-writeByteOrder>(io.ktor.utils.io.core.ByteOrder){}
    Literally, 5100+ warnings similar to the above ^ Thanks!
    l
    7 replies · 2 participants
  • b

    Bohdan

    02/03/2022, 12:01 AM
    Hi all. I have a question about sqldelight on iOS side. I can add, store and display data on UI on both(Android and iOS) platforms. But it is more convenient (especially if you have more than 20 tables) to open a database file on any sqlite tool - to test queries, compare some data, visually see data etc. It’s quite easy to get and open db file from Android. I aslo would like to do same with file from ios. As i understood on ios it is generated 3 files : appDb-wal appDb-shm appDb I am able to find and get these files on emulator. While adding new rows only “appDb-wal” size changed - so my guess that data are stored in this file )) My issue that i couldn’t open this file - its requires password as db encrypted . How can i open it? or where i could find this password ? What I am doing wrong ? I am mostly working with android and don’t have much experience with iOS. Thanks in advance.
    k
    24 replies · 2 participants
  • d

    darkmoon_uk

    02/03/2022, 5:05 AM
    Just want to validate a general finding here; but is Kotlin Multiplatform (not just KMM) being intentionally better supported in Android Studio than it is IntelliJ, right now? Asking because I do switch between AS and IntelliJ a bit on this project (using some logic in Gradle script that picks the correct plugin) and IntelliJ - ironically - has problems resolving Java classes from JVM targets, while Android Studio works fine! Seem unable to get the best of both worlds - IntelliJ has the strength that I can run multiple debug sessions (client+server) while AS will only run one at a time...
    e
    2 replies · 2 participants
  • j

    Jonas Frid

    02/03/2022, 8:19 AM
    json dates with the offset format (2022-02-02T08:00:00+00:00) can’t be deserialized to kotlinx.datetime.LocalDateTime. Any suggestions how I can manage this? KMM does not include OffsetDateTime.
    j
    n
    3 replies · 3 participants
  • g

    Gillian Buijs

    02/03/2022, 12:52 PM
    I have a simple class Service in commonMain which I can instantiate and use in an Android/Kotlin submodule. When I try to do the same in Swift I get this error: "ios/Runner/AppDelegate.swift:28:21: error: 'init()' is unavailable" and also: "common.Serivce:13:24: note: 'init()' has been explicitly marked unavailable here public convenience init()". I'm a total Swift noob and pretty clueless what's happening. Help? 😅
    g
    r
    +2
    15 replies · 5 participants
Powered by Linen
Title
g

Gillian Buijs

02/03/2022, 12:52 PM
I have a simple class Service in commonMain which I can instantiate and use in an Android/Kotlin submodule. When I try to do the same in Swift I get this error: "ios/Runner/AppDelegate.swift:28:21: error: 'init()' is unavailable" and also: "common.Serivce:13:24: note: 'init()' has been explicitly marked unavailable here public convenience init()". I'm a total Swift noob and pretty clueless what's happening. Help? 😅
g

Grégory Lureau

02/03/2022, 1:18 PM
Maybe a mistake between an exported method named "init()" and the Swift init method? (init/deinit are keywords in Swift AFAIK) https://docs.swift.org/swift-book/LanguageGuide/Initialization.html
g

Gillian Buijs

02/03/2022, 1:21 PM
I found the issue and it really was a dumb mistake showing how little I know of Swift. This does not work for Swift:
class Service(
    client: CloudClient? = null
){
but changing it to this and no problemo:
class Service {
    private val mdexClient = CloudClient()
}
so I think the former results in code for swift where there is no init() method to create a new instance where the latter does
r

russhwolf

02/03/2022, 2:10 PM
Swift doesn't see Kotlin's default parameters. So the first one probably works if you pass in a client (or nil) manually, but it won't work if you call it with no arguments.
g

Gillian Buijs

02/03/2022, 2:14 PM
I tried with passing in nil manually but it didn't work. But it could be I made a mistake because I'm a Swift noob 🙂
s

Scott Kruse

02/03/2022, 4:16 PM
@russhwolf is that documented anywhere? Curious about other interop gotchas
r

russhwolf

02/03/2022, 5:21 PM
General interop stuff is documented at https://kotlinlang.org/docs/native-objc-interop.html
👍 1
🔥 1
s

Scott Kruse

02/03/2022, 5:24 PM
Ty sir
b

Bob

03/31/2022, 5:01 AM
👋 I’m actually having the same issue with a ffmpeg command string builder. Swift
*let* command = shared.FFmpegCommand.Builder()
<- ‘init()’ is unavailable Kotlin
class FFmpegCommand private constructor(
    private val inputs: String?,
    private val concat: String?,
    val command: StringBuilder = StringBuilder("-y")
        .append(inputs)
        .append(concat)
) {

    data class Builder(
        var inputs: List<String> = emptyList(),
        var concat: String? = "",
    ) {

        fun inputs(inputs: List<String>) = apply { this.inputs = inputs }
        fun concat(output: String) = apply { this.concat = buildConcatFilter(this.inputs.size, output)}
        fun build() = FFmpegCommand(
            inputs.joinToString("") { " -i $it" },
            concat,
        ).command.toString()

        private fun buildConcatFilter(size: Int, output: String): String {
            val filterBuilder = StringBuilder(" -filter_complex \"")
            for (i in 0..size) filterBuilder.append("[$i]")
            filterBuilder.append("concat=n=$size:v=1:a=1[v1][a1]\"")
            filterBuilder.append(" -map '[v0]'")
            filterBuilder.append(" $output")

            return filterBuilder.toString()
        }
    }
}
I need to the defaulting for the builder. I’m not sure how to get around this one
@russhwolf seems like you have worked our this 🙂
r

russhwolf

03/31/2022, 4:44 PM
If you want to call from swift without passing args, you need to define a no-arg version in Kotlin instead of relying on default parameters. You can do it as a secondary constructor if you want to leave the existing default parameters behavior for Kotlin consumers. Something like
data class Builder(
        var inputs: List<String> = emptyList(),
        var concat: String? = "",
    ) {
        constructor() : this(emptyList(), "")
        ...
    }
b

Bob

03/31/2022, 4:52 PM
Ok! I will give that a shot !
Saved me loads of time. TYTYTTYTYT
👍 1
View count: 9