我使用Intelli-j IDE (community edition)创建了一个Kotlin多平台项目,按照此网站的教程进行操作:https://medium.com/@cafonsomota/set-up-your-first-kotlin-multiplatform-project-for-android-and-ios-april-2020-258e2b1d9ef4。我没有遵循教程中xCode部分的步骤,因为尽管我希望这个项目是多平台的,但我的主要关注点是Android。
当我运行common示例测试时,出现如下错误: e: org.jetbrains.kotlin.konan.MissingXcodeException: An error occurred during an xcrun execution. Make sure that Xcode and its command line tools are properly installed.
我还可以看到与配置、任务详细信息相关联的内容如下: cleanIosTest iosTest
这就是我收到错误信息的原因。
我无法弄清楚如何更改“Sample Test”以使其不运行该配置。我已经尝试删除这些任务,应用并保存,但当我再次运行时它们仍会重新出现。我在build.gradle文件中找不到任何iOS特定的测试相关内容。
build.gradle.app
示例测试看起来像这样:
配置如下: 请问有没有人知道我怎样才能解决这个问题而不需要下载xCode?我很乐意分享其他信息,但对于这个问题,我并不确定应该分享什么信息。
顺便提一下,我创建了另一个没有那行代码的配置,但每当我按下第一个测试的绿色PLAY按钮时,它总是默认使用
当我运行common示例测试时,出现如下错误: e: org.jetbrains.kotlin.konan.MissingXcodeException: An error occurred during an xcrun execution. Make sure that Xcode and its command line tools are properly installed.
我还可以看到与配置、任务详细信息相关联的内容如下: cleanIosTest iosTest
这就是我收到错误信息的原因。
我无法弄清楚如何更改“Sample Test”以使其不运行该配置。我已经尝试删除这些任务,应用并保存,但当我再次运行时它们仍会重新出现。我在build.gradle文件中找不到任何iOS特定的测试相关内容。
build.gradle.app
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}
repositories {
google()
jcenter()
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId 'org.jetbrains.kotlin.mpp_app_android'
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
kotlin {
android("android")
// This is for iPhone emulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
iosX64("ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
implementation kotlin('stdlib')
}
}
androidTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
}
iosTest {
}
}
}
// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
def target = project.findProperty('kotlin.target') ?: 'ios'
dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask
doLast {
def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
def targetDir = getProperty('configuration.build.dir')
copy {
from srcFile.parent
into targetDir
include 'app.framework/**'
include 'app.framework.dSYM'
}
}
}
示例测试看起来像这样:
package sample
import kotlin.test.Test
import kotlin.test.assertTrue
class SampleTests {
@Test
fun testMe() {
assertTrue(Sample().checkMe() > 0)
}
@Test
fun testProxy() {
assertTrue(Proxy().proxyHello().isNotEmpty())
}
}
配置如下: 请问有没有人知道我怎样才能解决这个问题而不需要下载xCode?我很乐意分享其他信息,但对于这个问题,我并不确定应该分享什么信息。
顺便提一下,我创建了另一个没有那行代码的配置,但每当我按下第一个测试的绿色PLAY按钮时,它总是默认使用
Sample Test
配置并带有iOS任务。
test<Debug | Realease>UnitTest
是一个解决方法,它可以让您运行所有测试,并且不像“播放按钮”那样可以选择单个测试运行。 - shadowsheepjvm
或iOS
选项。 - greysqrl