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

    timm

    12/11/2018, 11:35 AM
    How do I add (generated) Java Sources to the jvmMain source set?
    • 1
    • 1
  • n

    Nikolai

    12/11/2018, 1:35 PM
    Hello, everyone I am continuing my work using .ktor, but I faced problem again. Maybe it is wrong thread, but because I am developing multiplatform, I posting here. Correct me if I wrong. So, I am creating request to server, with GET methods, here is the code (I know it's not optimal but it's because I changed it trying to find an error). I setting HttpRequestBuilder
    method
    property and using client.get method and when I trace those properties - all good. But in the Charles proxy tool is displayed like POST request and on server side I got wrong request exception because of that. Did I missed something? I need to set/change something else to make request GET? P.S Screenshot inside conversation.
    g
    d
    • 3
    • 6
  • c

    coletz

    12/11/2018, 3:17 PM
    Hi guys, I tried to create a new mpp and everything seems ok, but there's no
    gradlew
    . Is it normal? How should I generate it? I used Intellij Idea and created the project, nothing else
    n
    r
    • 3
    • 3
  • u

    untwisted

    12/11/2018, 6:42 PM
    Hello, all. I’m using multiplatform and trying to figure out how to specify the multiplatform equivalent of
    compileKotlin2Js.kotlinOptions.moduleKind = "commonjs"
    in the project’s
    build.gradle
    , but Gradle is saying that it can’t find
    compileKotlin2Js
    which I suspect is because this is multiplatform. Is there a way to specify this option in a multiplatform build?
    g
    • 2
    • 4
  • r

    Robert

    12/11/2018, 8:17 PM
    Hi, I'm new. I am trying to build a multiplatform project, but I can't see to use native Java classes in the common code. Is this on purpose or is this an error in my project setup?
    r
    s
    +2
    • 5
    • 17
  • j

    Jacob Applin

    12/11/2018, 11:46 PM
    Is there any work happening on making a DI library, like dagger 2, but for kotlin multiplatform?
    p
    j
    j
    • 4
    • 4
  • j

    josephivie

    12/12/2018, 3:26 AM
    When I add
    api "org.jetbrains.kotlinx:kotlinx-io-native:0.1.1"
    to my native dependencies in
    build.gradle
    , it doesn’t seem to actually add the library. IntelliJ nor Gradle recognizes it. Any ideas?
    g
    d
    • 3
    • 3
  • e

    Efe

    12/12/2018, 10:02 AM
    hi guys, I have created a sample mpp project for Mobile Shared Library. I was able to add the jar file, that I build with ‘jarJvm’ gradle task, into the android project. (a separate project) I am able to build a ‘.klib’ file when I run the ‘iosKlibrary’ task. the problem is, how am I supposed to add that lib to the ios project.
    h
    z
    • 3
    • 9
  • t

    timm

    12/12/2018, 3:54 PM
    Hey, i am trying to use a kotlin multiplatform lib in a java app. Neither
    implementation project(':lib_project_multiplatform')
    nor
    compile project(':lib_project_multiplatform')
    seem to work. Gradle does list me a bunch of variants it cannot choose between. What do i have to do to make this work?
    h
    • 2
    • 3
  • t

    timm

    12/12/2018, 4:02 PM
    yes i did. or better intellij did..
    e
    • 2
    • 4
  • r

    Robert

    12/12/2018, 9:32 PM
    @bissell I get an error when I try to download your kmulti-bignumber package. Does this has to do with the jitpack subscription? Also it seems like the build failed there? https://github.com/kmulti/kmulti-bignumber https://jitpack.io/#kmulti/kmulti-bignumber
    b
    • 2
    • 1
  • c

    coletz

    12/12/2018, 9:52 PM
    Hi guys. I'm going crazy with some code. I have 2 mpp, one I manually created like 2 months ago and one created with "new>project>kotlin mpp (ios/android)". The first one is working fine, while the second one is throwing an error on ios (
    kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen <object>@839b6268
    ). The whole code is the same. Anyone ever had similar issue?
    👍 1
    t
    p
    +3
    • 6
    • 22
  • t

    timm

    12/13/2018, 11:43 AM
    In the pre 1.3 mpp layout i was able to have tests written in java in the JVM Project. is there a way to do this in the new layout? i tried
    jvmTest/java
    and
    test/java
    with the java plugin applied but neither seem to work
    r
    • 2
    • 12
  • t

    timm

    12/13/2018, 11:58 AM
    Anyone familiar with this compiler exception:
    e: org.jetbrains.kotlin.util.KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration JavaCode
    Cause: fromIndex: 1, toIndex: 0
    File being compiled at position: (5,1) in /Users/i13/Projekte/git/project-poc/src/commonMain/kotlin/path/JavaCode.kt
    The root cause was thrown at: Collections.kt:49
    	at org.jetbrains.kotlin.resolve.ExceptionWrappingKtVisitorVoid.visitDeclaration(ExceptionWrappingKtVisitorVoid.kt:43)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:453)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:21)
    • 1
    • 1
  • h

    h0tk3y

    12/13/2018, 12:50 PM
    Hi everyone, In our latest 1.3.20 EAP, we have added Gradle Kotlin DSL support to the
    kotlin-multiplatform
    plugin, along with some DSL improvements, such as simpler targets declaration. You're welcome to try it and share your feedback! See the details in the thread.
    ❤️ 10
    👍 3
    a
    t
    +4
    • 7
    • 40
  • h

    Hauke Radtki

    12/13/2018, 1:01 PM
    Can someone head me in the right direction using the expect/actual mechanism to have a CoroutineDispatcher (MainThread/singleThread/UI) that works on Andorid, iOS and in tests on a plain JVM? If I integrate the solution presented here: https://github.com/Kotlin/kotlinx.coroutines/issues/470#issuecomment-440080970 I'm unable to provide an actual implementation for the jvm target
    e
    • 2
    • 2
  • t

    timm

    12/13/2018, 1:15 PM
    Any Ideas why this does not compile: https://github.com/fr1zle/mpp-with-java-test/blob/master/src/test/java/TestKlass.java#L4
    h
    • 2
    • 8
  • t

    timm

    12/13/2018, 1:55 PM
    Intellij seems to be confused about calling Kotlin Methods from Java with type-aliased parameter types. is this a known issue?
    h
    • 2
    • 3
  • c

    coletz

    12/13/2018, 3:18 PM
    I have a common function written in kotlin which returns a ByteArray, and I'd like to use this on iOS. I though that ByteArray should be a Data on iOS, but it seems like it's a KotlinByteArray. Any way to convert it to a Data? Or something else that is "recognized" by swift?
    n
    • 2
    • 3
  • g

    geatmo

    12/13/2018, 3:21 PM
    Okay.. I'm stupid, and apparently don't know how to google for this, so I'll just ask you guys, if you don't mind. I'm trying to follow this tutorial for Kotlin/MPP: https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html I am on a Windows machine, and I know that I won't be able to compile the iOS portion of this on this machine, but I also cannot resolve the
    platform.UIKit.UIDevice
    package that's used in the iosMain actual.kt file. So are those packages also not accessible for me from a Windows machine?
    h
    j
    +2
    • 5
    • 10
  • m

    manijshrestha

    12/13/2018, 5:03 PM
    Hey Guys, can someone help me to know if it is possible to build a iOS framework that targets multiple architecture at once? e.g.
    targets {
            fromPreset(presets.jvm, 'jvm')
            // This preset is for iPhone emulator
            // Switch here to presets.iosArm64 to build library for iPhone device
            fromPreset(presets.iosX64, 'ios') {
                compilations.main.outputKinds('FRAMEWORK')
            }
        }
    This would only build x64 and have to switch to Arm 64. It would be ideal if I could have a framework with both so that I can use it for both simulator and real device.
    d
    r
    +2
    • 5
    • 10
  • p

    pajatopmr

    12/13/2018, 7:41 PM
    When adding dependency information for using a multiplatform library, the platform targets are pretty obvious, e.g.
    implementation "<http://com.pajato.io:KFile-jvm:0.0.1|com.pajato.io:KFile-jvm:0.0.1>"
    or
    implementation "<http://com.pajato.io:KFile-native:0.0.1|com.pajato.io:KFile-native:0.0.1>"
    but how should
    common
    dependencies be written:
    implementation "<http://com.pajato.io:KFile:0.0.1|com.pajato.io:KFile:0.0.1>"
    or
    implementation "<http://com.pajato.io:KFile-metadata:0.0.1|com.pajato.io:KFile-metadata:0.0.1>"
    ?
    c
    s
    • 3
    • 5
  • k

    kpgalligan

    12/14/2018, 2:15 AM
    I'm integrating ktor in our droidcon app and ran into a frustrating wrinkle. I'm getting a mutability exception inside the native client call, but have been looking at the source from ktor and kotlinconf app and still have no idea what's happening. Post of calling code to follow...
    -.rb
    c
    • 2
    • 9
  • b

    bdeg

    12/14/2018, 1:15 PM
    Is it possible to use ios library from ios target sourcesets? Example I want to implement common class using firebase library.
    r
    • 2
    • 2
  • r

    Robert

    12/14/2018, 8:37 PM
    Is there a way to know if a library is compatibile with multiplatforms? For example, this repo (though it is about the output in this case): https://github.com/rouzwawi/grpc-kotlin if not, would it be possible to do?
    k
    r
    p
    • 4
    • 9
  • j

    josephivie

    12/14/2018, 9:48 PM
    Is the unspecific
    atomicfu
    dependency here a bug? Shouldn’t it refer to
    debug_ios_x64
    ? http://central.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-coroutines-core-native_debug_ios_x64/1.0.1/kotlinx-coroutines-core-native_debug_ios_x64-1.0.1.pom
    d
    • 2
    • 3
  • a

    addamsson

    12/15/2018, 5:43 PM
    do any of you know about a multiplatform OpenCL wrapper for Kotlin?
    d
    • 2
    • 4
  • c

    christophsturm

    12/16/2018, 11:24 PM
    what is the easiest way to publish a multiplatform version of a kotlin library? are there any libraries that have a nice multiplatform build (preferable with gradle kotlin dsl) that works on java, javascript and native that i can look at as an example?
    👍 1
    r
    m
    g
    • 4
    • 8
  • r

    russhwolf

    12/16/2018, 11:35 PM
    @h0tk3y You’ve mentioned in a couple spots (eg https://youtrack.jetbrains.com/issue/KT-27535#focus=streamItem-27-3199028-0-0) that it’s possible to use
    digital.wup.android-maven-publish
    to publish the android part of a
    kotlin-multiplatform
    project. It’s not clear to me how that can be consumed by another
    kotlin-multiplatform
    project. Is there a sample of that anywhere?
    d
    j
    • 3
    • 14
  • n

    nestserau

    12/17/2018, 8:59 AM
    I’ve started working with ktor HttpClient and ran into a couple of issues. First, is that my IDE doesn’t recognize
    HttpClient
    and
    runBlocking
    , while the code itself compiles perfectly fine. What could be a reason for that?
    g
    m
    • 3
    • 20
Powered by Linen
Title
n

nestserau

12/17/2018, 8:59 AM
I’ve started working with ktor HttpClient and ran into a couple of issues. First, is that my IDE doesn’t recognize
HttpClient
and
runBlocking
, while the code itself compiles perfectly fine. What could be a reason for that?
g

gildor

12/17/2018, 9:02 AM
Looks as IDE issue, try restart + invalidate caches
m

msink

12/17/2018, 9:18 AM
Please post your
build.gradle
n

nestserau

12/17/2018, 9:27 AM
plugins {
    id 'com.android.library'
    id 'kotlin-multiplatform'
    id 'maven-publish'
}

repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url '<http://archiva.example.com:9080/repository/internal>' }
}

group 'com.example.multiplatform'
version '0.4.1'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 21
    }
    buildTypes {
        release {
            minifyEnabled true
        }
    }
}

ext.ktor_version = '1.0.+'

kotlin {
    targets {
        final def iosTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64
        fromPreset(iosTarget, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
        fromPreset(presets.android, 'android')
    }
    sourceSets {
        all {
            languageSettings {
                languageVersion = '1.3'
                useExperimentalAnnotation 'kotlin.ExperimentalUnsignedTypes'
            }
        }
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
                implementation "io.ktor:ktor-client:$ktor_version"
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        iosMain
        iosTest
    }
}

dependencies {
    androidMainImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    androidMainImplementation "io.ktor:ktor-client-android:$ktor_version"

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'org.jetbrains.kotlin:kotlin-test'
    androidTestImplementation 'org.jetbrains.kotlin:kotlin-test-junit'
    androidTestImplementation "io.ktor:ktor-client-android:$ktor_version"

    iosMainImplementation "io.ktor:ktor-client-ios:$ktor_version"
}


configurations {
    compileClasspath
}

task packForXCode(type: Sync) {
    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'

    inputs.property "mode", mode
    dependsOn kotlin.targets.ios.compilations.main.linkTaskName("FRAMEWORK", mode)

    from { kotlin.targets.ios.compilations.main.getBinary("FRAMEWORK", mode).parentFile }
    into frameworkDir

    doLast {
        new File(frameworkDir, 'gradlew').with {
            text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
            setExecutable(true)
        }
    }
}

tasks.build.dependsOn packForXCode

task iosTest {
    def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
    dependsOn 'linkTestDebugExecutableIos'
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        def binary = kotlin.targets.ios.compilations.test.getBinary('EXECUTABLE', 'DEBUG')
        exec {
            commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
        }
    }
}

tasks.check.dependsOn iosTest
If anyone can spot an error that would be awesome.
m

msink

12/17/2018, 9:33 AM
Well, I don't know, looks sane. Maybe
ext.ktor_version = '1.0.+'
- better use exact version.
n

nestserau

12/17/2018, 9:36 AM
I tried that and then invalidated cache and restarted. Same thing 😞
g

gildor

12/17/2018, 9:36 AM
I don’t think that it somehow related to build.gradle
Some IDE problem
and most probably related to Gradle Metadata
n

nestserau

12/17/2018, 9:37 AM
Yes, actually when I restart it it throws an exception.
g

gildor

12/17/2018, 9:37 AM
try
io.ktor:ktor-client-jvm
n

nestserau

12/17/2018, 9:42 AM
Maybe that’s the reason, ktor-client-jvm hasn’t been updated for a long time. The latest version is 0.9.0-alpha.
m

msink

12/17/2018, 9:46 AM
And maybe it depend on your Gradle version... But if gradle build passed it should be fine. Strange.
g

gildor

12/17/2018, 9:49 AM
It may be just a problem of Idea with gradle metadata dependencies
runBlocking is actually strange
m

msink

12/17/2018, 9:52 AM
As experiment - if leave only one target - ios or android - it works?
n

nestserau

12/17/2018, 10:05 AM
So I’ve thrown out the
android
target, invalidated cache and restarted. No change.
It looks like IntelliJ doesn’t understand the structure of the project completely. Although Gradle itself can build the project just fine. That’s a minor problem to me for now.
You won’t believe, but I started working on the project further, and somehow it now recognizes HttpClient, just out of the blue, I didn’t change anything, just was typing in more code.
Aha, now I get it. If I use HttpClient version 1.0.0, then it’s fine. With 1.0.1 it’s red. Problem solved, sort of.
View count: 4