(未找到名为“iosMain”的KotlinSourceSet,)如何将android作为构建目标添加到Kotlin多平台项目中

oknrviil  于 11个月前  发布在  Android
关注(0)|答案(2)|浏览(102)

在网站stackoverflow.com上有这样一个主题:KotlinSourceSet with name 'androidMain' not found.
我有一个类似的问题:“未找到名为'iosMain'的KotlinSourceSet”。
我不太明白怎么解决,麻烦你帮帮忙。[![任务1][1][1] [![任务2][2]][2]
更新:解决了,现在我得到了:内置iOS应用程序:代码65失败.我应该怎么做来修复它?

yptwkmov

yptwkmov1#

泛型ios源集已被弃用,您现在必须更显式地指定目标。这意味着要添加目标而不是添加泛型ios(),您需要指定单独的目标:

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }

    // ios() // -> This has been deprecated
    iosArm64()
    iosX64()
    iosSimulatorArm64()

字符串
在指定源集时,添加它们的main/test目标:

sourceSets {
...
val iosArm64Main by getting {
    dependencies {
      ...
    }
}
val iosArm64Test by getting {
    dependencies {
      ...
    }
}
val iosX64Main by getting {
    dependencies {
      ...
    }
}
val iosSimulatorArm64Main by getting {
    dependencies {
      ...
    }
}

e4eetjau

e4eetjau2#

我也遇到了同样的问题。下面的代码对我有效。baseName可以是任何字符串。

listOf(
    iosX64(),
    iosArm64(),
    iosSimulatorArm64()
  ).forEach { iosTarget ->
    iosTarget.binaries.framework {
      baseName = "ComposeApp"
      isStatic = true
    }
  }

 sourceSets {
    val iosX64Main by getting
    val iosArm64Main by getting
    val iosSimulatorArm64Main by getting
    val iosMain by creating {
      dependsOn(commonMain.get())
      iosX64Main.dependsOn(this)
      iosArm64Main.dependsOn(this)
      iosSimulatorArm64Main.dependsOn(this)
    }
  }

字符串

相关问题