https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

ribesg

01/29/2019, 2:38 PM
When I run
compileKotlinIosArm64
, it doesn’t even find the dependencies of `commonMain`:
Copy code
// Somewhere in a commonMain file
import io.ktor.client.HttpClient
       ^
My `build.gradle.kts`: https://gist.github.com/Ribesg/d76208f8d921cb22b50347e87014c144
@yshrsmz what I have looks incredibly close to what I can see in your example here https://github.com/yshrsmz/GitHubKotlinMPPSample but it still doesn’t work
Nevermind your code does not compile either
y

yshrsmz

01/29/2019, 3:34 PM
yeah i pushed everything before leaving office 😁
r

ribesg

01/29/2019, 3:34 PM
I don’t understand I have all dependencies set correctly but it doesn’t find ktor at all... Do you have any idea?
y

yshrsmz

01/29/2019, 3:54 PM
I tried to create both arm64 source set and x64 source set before, but I couldn’t make it. This is why I change preset depending on the provided property in this repo
https://github.com/yshrsmz/HNKotlinNative this repo should work on ios simulator
r

ribesg

01/29/2019, 4:01 PM
True, I don’t think I saw any working example where both targets are set, so maybe it’s the problem. I’ll try that tomorrow, thanks
n

nestserau

01/29/2019, 4:24 PM
It won’t work with 1.1.2. Have the same issue. Seems I read there is a bug in metadata. I will try 1.3.20.
It works with 1.0.0, but it’s not binary compatible with Kotlin gradle plug-in 1.3.20 which I need for Android AAR publication.
So 1.3.20 and Gradle 4.10.3 is the way, just need to find a way to link with Ktor.
👍 1
y

yshrsmz

01/30/2019, 3:47 AM
@ribesg let me know if you make it!
r

ribesg

01/30/2019, 9:43 AM
@yshrsmz I switched from 2 targets to a single one but as expected it doesn’t change anything
n

nestserau

01/30/2019, 10:04 AM
Guys, I’ve made it work. Here is my
build.gradle
script in case anyone is interested:
Copy code
plugins {
    id 'com.android.library'
    id 'kotlin-multiplatform'
}

repositories {
    google()
    jcenter()
    mavenCentral()
}

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

ext.ktor_version = '1.1.2'

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 kotlin('stdlib-common')
                implementation "io.ktor:ktor-client-core:$ktor_version"
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        iosMain {
            dependencies {
                implementation "io.ktor:ktor-client-ios:$ktor_version"
            }
        }
        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"
}

configurations {
    compileClasspath
}
r

ribesg

01/30/2019, 11:19 AM
You have a weird mix of
kotlin.sourceSets.<target>
dependencies and global project dependencies
I’m starting to think that I can’t getting to work because I’m using Kotlin DSL, and maybe it compiles/translates to something different in Groovy than what I expect
n

nestserau

01/30/2019, 12:09 PM
Yes, it’s weird, but that’s the only way it works for me. If I try to make it “normal”, it stops compiling.
r

ribesg

01/30/2019, 12:59 PM
Which target stops compiling?
Because with what I have in my gist the Android part works, I can run it
It’s just the iOS target that can’t find dependencies for some reason
@nestserau did you ever get in a situation where the android app worked but the dependencies didn’t work when compiling iOS?
n

nestserau

01/30/2019, 2:08 PM
I think so. And vice versa too. The file I posted above is a result of days of trial and error.
r

ribesg

01/30/2019, 2:12 PM
I tried removing the entire android part of my project (gradle plugin, android block, android target, everything) and it didn’t change the fact that the ios part does not compile
n

nestserau

01/30/2019, 2:15 PM
I cannot help you with the Kotlin part, because I don’t use it. Maybe try switching back to Groovy. You have a working example then at least…
r

ribesg

01/30/2019, 3:04 PM
I rewrote the entire build file in Groovy, no difference
n

nestserau

01/30/2019, 3:07 PM
In your settings.gradle, do you have enableFeaturePreview(‘GRADLE_METADATA’)?
r

ribesg

01/30/2019, 3:09 PM
No, trying that
😄 1
Ok it looks like it built
n

nestserau

01/30/2019, 3:12 PM
Yes, that line is essential.
r

ribesg

01/30/2019, 3:12 PM
Where is that documented? I’m now trying to go back to 1) Gradle 5 instead of 4 and 2) Kotlin DSL
n

nestserau

01/30/2019, 3:13 PM
Somewhere on the Kotlin website.
r

ribesg

01/30/2019, 3:13 PM
Looks like it works with Gradle 5.1.1 and my build.gradle.kts
🎉 1
n

nestserau

01/30/2019, 3:14 PM
An experimental publishing and dependency consumption mode can be enabled by adding enableFeaturePreview(“GRADLE_METADATA”) to the root project’s settings.gradle file.
r

ribesg

01/30/2019, 3:14 PM
Well, by “it works” I mean that the compileKotlinIos task succeeds, I didn’t have a look at what it produced and if I can use it, but it’s a step in the right direction at least
Thanks for that @nestserau, been stuck for days
n

nestserau

01/30/2019, 3:15 PM
Me too man, getting through the same shit for a couple of weeks already.
3 Views