【发布时间】:2022-11-09 19:39:19
【问题描述】:
我做了一个实验,将 iOS UI 测试添加到使用 Kotlin Multiplatform Mobile(KMM) 创建的项目中。通过开始遵循官方指南,我能够在 Xcode 中连接共享库并启动 iOS 应用程序或从 Android Studio 执行单元测试。但是当我尝试让 XCTest 添加一些 UI 测试时,Xcode 抱怨如下截图。
我已经在互联网上搜索了很多,仍然没有运气。伙计们,如果你以前也遇到过同样的问题,请给我一些关于如何追踪这个拱门问题的提示。
从构建日志错误来看,我认为首先 Gradle Task :shared:linkDebugFrameworkIosSimulatorArm64 FAILED 和下面说 XCTest 是为 iOS arm64 arch 构建的,它与 iOS Simulator 不一致。
我正在使用 Mac M1 机器,这可能是原因。所以我将 Xcode 切换到 Rosetta 模式,这次来自 Run Script 的命令 embedAndSignAppleFrameworkForXcode 有 NO-SOURCE 并遵循一个 iOS 模拟器版本对齐抱怨。
XCTest.def
language = Objective-C
package = platform.XCTest
depends = UIKit
modules = XCTest
linkerOpts= -weak_framework XCTest -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/UIKit.framework -F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks/
compilerOpts= -weak_framework XCTest -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/
build.gradle 文件
import com.android.build.gradle.internal.scope.ProjectInfo.Companion.getBaseName
plugins {
kotlin("multiplatform")
id("com.android.library")
}
kotlin {
android {
}
listOf(
iosArm64(),
iosSimulatorArm64()
).forEach {
it.binaries.framework {
baseName = "shared"
embedBitcode = org.jetbrains.kotlin.gradle.plugin.mpp.Framework.BitcodeEmbeddingMode.DISABLE
}
it.compilations.getByName("main") {
val xctest by cinterops.creating {
// Def-file describing the native API.
defFile(project.file("src/iosMain/xctest.def"))
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
// implementation(
// "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5-native-mt"
// )
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.5-native-mt")
implementation("androidx.test.espresso:espresso-core:3.2.0")
implementation("androidx.test.espresso:espresso-contrib:3.2.0")
implementation("androidx.test:core:1.4.0")
implementation("androidx.test.ext:junit:1.1.3")
implementation("androidx.test.uiautomator:uiautomator:2.2.0")
}
}
val androidTest by getting {
dependencies {
}
}
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosArm64Test by getting
val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosArm64Test.dependsOn(this)
iosSimulatorArm64Test.dependsOn(this)
}
}
}
android {
namespace = "com.bsc.radiant_hope_test"
compileSdk = 32
defaultConfig {
minSdk = 21
targetSdk = 32
}
}
共享库已连接。
【问题讨论】:
标签: swift xcode xctest kotlin-multiplatform kotlin-multiplatform-mobile