Hey, guys. I need to parse URL in K/M (for Native)...
# ktor
u
Hey, guys. I need to parse URL in K/M (for Native). I’ve added
implementation "io.ktor:ktor-client-core:1.2.3"
in common sourseSet and
implementation("io.ktor:ktor-client-curl:1.2.3")
in native sourcesSet (
macosX64
actually). I can’t access
io.ktor.http.Url
in native code:
NativeURL.kt: (3, 8): Unresolved reference: io
Is it multiplatform? Wrong imports? I can see “io.ktor-ktor-http:1.2.3” actually shown in External deps in IDEA. Any suggestions on how to proceed?
e
Hi @4ntoine, yep it’s mpp and native locates here:
io.ktor-ktor-http-native:1.2.3
u
i will try, thanks
@e5l what should be according common dep? currently trying
io.ktor:ktor-client-core:1.2.3
BTW i guess it was meant to be
io.ktor:ktor-http-native:1.2.3
Still having package not found in native. Any example?
d
Have you enabled metadata?
u
@Dominaezzz i assume using
-common
dependency in common sourceset does it.
d
It has to be explicitly enabled in library consumers.
enableFeaturePreview('GRADLE_METADATA')
in your
settings.gradle.kts
.
u
why is it required (briefly)?
d
It has to be explicitly enabled because it is somewhat experimental (was recently released). Metadata is required for native, if you want to infer the package from the target. Otherwise you have to explicity use
-macosX64
instead of just
-native
.
u
thanks for the explanation, i will try
Task libcompileKotlinNative
w: skipping /Users/asmirnov/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu-macos64/0.12.9/fcdf1e13e61d2f712f42ccf3e9dc8f5b808a46a7/atomicfu-macos64-0.12.9.klib. The abi versions don’t match. Expected ‘[8]’, found ‘9’ w: The compiler versions don’t match either. Expected ‘[1.2.1]’, found ‘1.3-eap-10779’ e: Compilation failed: Could not find “/Users/asmirnov/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/atomicfu-macos64/0.12.9/fcdf1e13e61d2f712f42ccf3e9dc8f5b808a46a7/atomicfu-macos64-0.12.9.klib” in [/Users/asmirnov/Documents/dev/src/kotlin-research/project-kotlin, /Users/asmirnov/.konan/klib, /Users/asmirnov/.konan/kotlin-native-macos-1.2.1/klib/common, /Users/asmirnov/.konan/kotlin-native-macos-1.2.1/klib/platform/macos_x64]. PS. I had to use
-macosx64
dep (small x)
d
Are you using kotlin
1.3.41
?
u
1.3.31
d
ktor 1.2.3 requires kotlin 1.3.41
u
what version should be used for 1.3.31?
just tried ktor 1.2.2 and 1.2.1 - same error
d
Hmm, any reason you can't upgrade?
u
it can probably require some other changes
d
Although, you'll be missing memory leak fixes in the client.
u
@Dominaezzz thank you so much! For testing purposes it’s ok, but i will keep that in mind
unfortunately i was able to do it for jvm and run the tests, but not for native. Still getting the same error -
io
package just not found:
Copy code
jvm()
android()

macosX64("native")

...        

commonJvmMain {
    dependsOn commonMain
    dependencies {
        implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
        implementation 'commons-io:commons-io:2.6'
        implementation 'io.ktor:ktor-client-okhttp:1.2.0'
    }
}

jvmMain {
    dependsOn commonJvmMain
    dependencies {
        implementation 'com.google.code.gson:gson:2.8.5'
    }
}

jvmTest {
    dependencies {
        implementation 'org.jetbrains.kotlin:kotlin-test'
        implementation 'org.jetbrains.kotlin:kotlin-test-junit'
    }
}

nativeMain {
    dependencies {
        implementation 'io.ktor:ktor-http-macosx64:1.2.0'
    }
}

nativeTest {
	// any test deps similar to jvmTest required here?
}

...
d
Which
io
package?
u
import io.ktor.http.Url as KtorUrl
d
implementation 'io.ktorktor client okhttp1.2.0' -> implementation 'io.ktorktor client core1.2.0'.
Nvm
u
it works for jvm i guess common part is ok
d
Add
implementation 'io.ktor:ktor-client-core:1.2.0'
to nativeMain
This is my currently working setup, if it helps.
Copy code
sourceSets {
        commonMain {
            dependencies {
                implementation(kotlin("stdlib-common"))
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialVersion")

                implementation("io.ktor:ktor-client-core:$ktorVersion")
                implementation("io.ktor:ktor-client-json:$ktorVersion")
                implementation("io.ktor:ktor-client-serialization:$ktorVersion")
            }
        }
        commonTest {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        named("jvmMain") {
            dependencies {
                implementation(kotlin("stdlib-jdk8"))

                implementation("io.ktor:ktor-client-serialization-jvm:$ktorVersion")
                implementation("io.ktor:ktor-client-apache:$ktorVersion")
            }
        }
        named("jvmTest") {
            dependencies {
                implementation(kotlin("test"))
                implementation(kotlin("test-junit"))
            }
        }
        named("jsMain") {
            dependencies {
                implementation(kotlin("stdlib-js"))

                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialVersion")
                implementation("io.ktor:ktor-client-serialization-js:$ktorVersion")
                implementation("io.ktor:ktor-client-js:$ktorVersion")
            }
        }
        named("jsTest") {
            dependencies {
                implementation(kotlin("test-js"))
            }
        }
        named("linuxMain") {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialVersion")
                implementation("io.ktor:ktor-client-serialization-native:$ktorVersion")
                implementation("io.ktor:ktor-client-curl:$ktorVersion")
            }
        }
        named("linuxTest") {
        }
    }
u
shank for sharing, will check it
i can see you also have implementation(“io.ktorktor client curl$ktorVersion”) in native deps
it did not help
what’s your version?
ktor
d
1.2.3
😁
The only thing I can think of is
enableFeaturePreview("GRADLE_METADATA")
but I'm not sure what's wrong at this point.
u
1.2.0 did not work with kotlin 1.3.31. I’ve just tried to update to kotlin 1.3.41 and use 1.2.3. Got the following error:
Copy code
* What went wrong:
Could not resolve all files for configuration ':lib:nativeCompileKlibraries'.
> Could not resolve io.ktor:ktor-http-macosx64:1.2.3.
  Required by:
      project :lib > io.ktor:ktor-http-native:1.2.3
   > Could not resolve io.ktor:ktor-http-macosx64:1.2.3.
      > Could not parse module metadata <https://repo.maven.apache.org/maven2/io/ktor/ktor-http-macosx64/1.2.3/ktor-http-macosx64-1.2.3.module>
         > Expected a name but was STRING at line 31 column 26 path $.variants[0].dependencies[0].version.requires
   > Could not resolve io.ktor:ktor-http-macosx64:1.2.3.
      > Could not parse module metadata <https://jcenter.bintray.com/io/ktor/ktor-http-macosx64/1.2.3/ktor-http-macosx64-1.2.3.module>
         > Expected a name but was STRING at line 31 column 26 path $.variants[0].dependencies[0].version.requires
   > Could not resolve io.ktor:ktor-http-macosx64:1.2.3.
      > Could not parse module metadata <https://dl.bintray.com/kotlin/ktor/io/ktor/ktor-http-macosx64/1.2.3/ktor-http-macosx64-1.2.3.module>
         > Expected a name but was STRING at line 31 column 26 path $.variants[0].dependencies[0].version.requires
the line is:
"requires": "1.3.41"
and the error is
Expected a name but was STRING
looks like a bug or compatibility issue again
(trying with
enableFeaturePreview("GRADLE_METADATA")
)
1.2.3 with kotlin 1.3.41 without enableFeaturePreview(“GRADLE_METADATA”): getting the same “package not found” error
i think i have to try some existing (working) ktor sample first
Ok, i did it. For curious: here is the combination of everything that works: ktor 1.2.3, kotlin 1.3.41, gradle 5.1.1, enableFeaturePreview(“GRADLE_METADATA”) enabled. If any of this is changed, it does not work due to different errors