gpt4 book ai didi

android - 在 Kotlin MultiPlatform 项目中未解决 iOS 依赖项

转载 作者:行者123 更新时间:2023-12-02 13:16:28 25 4
gpt4 key购买 nike

我正在尝试开发一个小型库来将问题发布到我公司的 Jira 服务器,我认为带有 KTOR 的 Kotlin MPP将只是门票。
起初,按照一些教程,我做了一个共享项目,iOS 的导入工作正常,但 Android 的 Ktor 实现无法解决。然后我意识到我需要重新创建项目并创建一个库而不是共享应用程序,因为我已经为每个移动客户端拥有了现有的代码库,并且我需要发布 MPP 库以供他们使用。
将项目重新创建为库并开始添加 KTOR 1.3.2 的依赖项后,iOS 依赖项无法解决。这不仅仅是 KTOR,它是任何 iOS 依赖项,所以我的项目设置中显然有一些不正确的地方,但我无法发现它。
这是gradle文件:

plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}

repositories {
jcenter()
mavenCentral()
maven { url "https://kotlin.bintray.com/kotlinx" }
}

group 'com.example.issuereporter'
version '0.0.1'

apply plugin: 'maven-publish'

kotlin {

targets {
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64

fromPreset(iOSTarget, 'ios') {
binaries {
framework('IssueReporter')
}
}


fromPreset(presets.jvm, 'android')
}

def ktor_version = "1.3.2"

sourceSets["commonMain"].dependencies {
implementation kotlin('stdlib-common')

implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
}

sourceSets["commonTest"].dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}

sourceSets["androidMain"].dependencies {
implementation kotlin('stdlib')

implementation "io.ktor:ktor-client-core-jvm:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "io.ktor:ktor-client-auth-jvm:$ktor_version"

}

sourceSets["androidTest"].dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}

sourceSets["iosMain"].dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-core-native:$ktor_version"
implementation "io.ktor:ktor-client-json-native:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$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'
final def framework = kotlin.targets.ios.binaries.getFramework("IssueReporter", mode)

inputs.property "mode", mode
dependsOn framework.linkTask

from { framework.outputFile.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
控制台输出是
Could not resolve io.ktor:ktor-client-ios:1.3.2.
Could not resolve io.ktor:ktor-client-core-native:1.3.2.
Could not resolve io.ktor:ktor-client-json-native:1.3.2.
Could not resolve io.ktor:ktor-client-serialization-native:1.3.2.
有什么明显我在这里失踪的吗?
更新
我废弃并重新创建了带有 IntelliJ 更新版本(IntelliJ IDEA 2019.3.5(社区版))和安装了 Kotlin 1.4.0 插件的项目。这给了我一个稍微不同的创建向导,以及使用 Kotlin 作为 Gradle 语法的选项。
更新 build.gradle.kts文件:
plugins {
kotlin("multiplatform") version "1.4.0"
kotlin("plugin.serialization") version "1.4.0"
id("com.android.library")
id("kotlin-android-extensions")
}
group = "com.example.issuereporter"
version = "1.0-SNAPSHOT"

repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
maven(url = "https://kotlin.bintray.com/kotlinx")
maven(url = "https://dl.bintray.com/kotlin/ktor")
maven(url = "https://repo1.maven.org/maven2/")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
maven(url = "https://plugins.gradle.org/m2/")
}
kotlin {
android()
iosX64("ios") {
binaries {
framework {
baseName = "library"
}
}
}

val ktor_version = "1.3.2"
val serialization_version = "0.20.0"

sourceSets {
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-json:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("io.ktor:ktor-client-auth:$ktor_version")
implementation("io.ktor:ktor-client-apache:$ktor_version")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("androidx.core:core-ktx:1.2.0")

implementation("io.ktor:ktor-client-android:$ktor_version")
implementation("io.ktor:ktor-client-auth-jvm:$ktor_version")
implementation("io.ktor:ktor-client-json-jvm:$ktor_version")
}
}
val androidTest by getting
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktor_version")
implementation ("io.ktor:ktor-client-core-native:$ktor_version")
implementation("io.ktor:ktor-client-json-native:$ktor_version")
implementation("io.ktor:ktor-client-auth-native:$ktor_version")
}
}
val iosTest by getting
}
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
当我设置 ktor_version 时,iOS 的 gradle 依赖项成功同步至 1.3.2但不适用于 1.4.0 (假设镜像没有更新 native 文件??)...但是当我尝试使用该类时导入不会编译...见附图:
enter image description here

最佳答案

我猜你没有 enableFeaturePreview("GRADLE_METADATA")settings.gradle .
settings.gradle
查看我们的入门项目 KaMPKit对于 1.3.72 上的运行示例。我们可能会在本周将它升级到 1.4.0,但现在它应该是一个很好的引用。

关于android - 在 Kotlin MultiPlatform 项目中未解决 iOS 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63480511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com