【发布时间】:2021-07-07 12:36:11
【问题描述】:
所以我尝试使用 kotlin 多平台构建项目,我设法与数据库/ktor 等集成,但问题是当我需要一些来自 cocoapods 的依赖时。我已经看到从 kotlin 1.4 xcode 开始不需要构建这样的依赖项(但是即使它失败了,除非我在我的机器上安装了 xcode)。但重点是,每次我在build.gradle.kts 中的cocoapods 中添加pod 部分时,我的同步都会失败:
Exception in thread "main" java.lang.Error: /var/folders/6p/0kpnx2mj22589gthf1dddjwhtr2_tq/T/15810392041507337443.m:1:9: fatal error: module 'AFNetworking' not found
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:68)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:14)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:506)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:264)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:74)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:41)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':example:cinteropAFNetworkingIos'.
> Process 'command '/Applications/Android Studio 4.2 Preview.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
当我启动 podspec 时,它会正确生成,我的构建 gradle 文件: 第一:
buildscript {
ext.kotlin_version = "1.4.31"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0-beta06"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:1.4.31"
classpath "com.squareup.sqldelight:gradle-plugin:1.4.4"
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url "https://kotlin.bintray.com/kotlinx" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
还有那个有cocoapods的:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
kotlin("native.cocoapods")
id("com.android.library")
id("kotlin-android-extensions")
id("com.squareup.sqldelight")
}
kotlin {
android()
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {}
version = "1.0.0"
cocoapods {
summary = "This is sample Summary"
homepage = "Home URL"
pod("AFNetworking")
pod("FirebaseAnalytics")
}
val coroutinesVersion = "1.3.9-native-mt"
val serializationVersion = "1.0.0-RC"
val ktorVersion = "1.5.3"
val sqlDelightVersion = "1.4.4"
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("com.squareup.sqldelight:runtime:$sqlDelightVersion")
}
}
val androidMain by getting {
dependencies {
implementation("androidx.core:core-ktx:1.3.2")
implementation("io.ktor:ktor-client-android:$ktorVersion")
implementation("com.squareup.sqldelight:android-driver:$sqlDelightVersion")
implementation("com.jakewharton.timber:timber:4.7.1")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
implementation("com.squareup.sqldelight:native-driver:$sqlDelightVersion")
}
}
}
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
}
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
}
也许有人已经找到了解决方案?
【问题讨论】: