KMM构建在添加KMMBridge插件后失败,如果存在依赖。

huangapple go评论105阅读模式
英文:

KMM build fails after adding KMMBridge plugin, if dependencies exist

问题

我正在尝试创建一个使用KMMBridge发布到Cocoapods的KMM项目。这对于仅返回字符串的基本项目运行正常,但当添加依赖以进行HTTP请求或解析JSON时,它停止工作。

我遵循了开始使用Kotlin Multiplatform Mobile的指南,并在完成后开始将KMMBridge代码添加到Gradle脚本中。只需添加KMMBridge插件

id("co.touchlab.faktory.kmmbridge") version "0.3.7"

这会导致以下错误的构建失败:

  1. Caused by: java.lang.IllegalArgumentException: This fat framework already has a binary for architecture `arm64` (shared for target `ios_arm64`)

项目可以在这里找到:https://github.com/ionel71089/KotlinMultiplatformSandbox

这是shared模块的build.gradle.kts文件:

  1. val ktorVersion = "2.2.4"
  2. version = "0.1"
  3. plugins {
  4. kotlin("multiplatform")
  5. id("com.android.library")
  6. kotlin("plugin.serialization") version "1.8.20"
  7. kotlin("native.cocoapods")
  8. id("co.touchlab.faktory.kmmbridge") version "0.3.4" // breaks build
  9. // `maven-publish`
  10. }
  11. kotlin {
  12. android {
  13. compilations all {
  14. kotlinOptions {
  15. jvmTarget = "1.8"
  16. }
  17. }
  18. }
  19. listOf(
  20. iosX64(),
  21. iosArm64(),
  22. iosSimulatorArm64()
  23. ).forEach {
  24. it.binaries.framework {
  25. baseName = "shared"
  26. }
  27. }
  28. sourceSets {
  29. val commonMain by getting {
  30. dependencies {
  31. implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
  32. implementation("io.ktor:ktor-client-core:$ktorVersion")
  33. implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
  34. implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
  35. }
  36. }
  37. val commonTest by getting {
  38. dependencies {
  39. implementation(kotlin("test"))
  40. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
  41. }
  42. }
  43. val androidMain by getting {
  44. dependencies {
  45. implementation("io.ktor:ktor-client-android:$ktorVersion")
  46. }
  47. }
  48. val androidUnitTest by getting
  49. val iosX64Main by getting
  50. val iosArm64Main by getting
  51. val iosSimulatorArm64Main by getting
  52. val iosMain by creating {
  53. dependsOn(commonMain)
  54. iosX64Main.dependsOn(this)
  55. iosArm64Main.dependsOn(this)
  56. iosSimulatorArm64Main.dependsOn(this)
  57. dependencies {
  58. implementation("io.ktor:ktor-client-darwin:$ktorVersion")
  59. }
  60. }
  61. val iosX64Test by getting
  62. val iosArm64Test by getting
  63. val iosSimulatorArm64Test by getting
  64. val iosTest by creating {
  65. dependsOn(commonTest)
  66. iosX64Test.dependsOn(this)
  67. iosArm64Test.dependsOn(this)
  68. iosSimulatorArm64Test.dependsOn(this)
  69. }
  70. }
  71. cocoapods {
  72. summary = "KMMBridgeSampleKotlin"
  73. homepage = "https://touchlab.dev"
  74. ios.deploymentTarget = "13"
  75. }
  76. }
  77. android {
  78. namespace = "com.example.kotlinmultiplatformsandbox"
  79. compileSdk = 33
  80. defaultConfig {
  81. minSdk = 24
  82. targetSdk = 33
  83. }
  84. }
  85. /*
  86. addGithubPackagesRepository()
  87. kmmbridge {
  88. mavenPublishArtifacts()
  89. githubReleaseVersions()
  90. spm()
  91. cocoapods("git@github.com:ionel71089/PublicPodspecs.git")
  92. versionPrefix.set("0.8")
  93. }
  94. */

**注意:**我也尝试将依赖项添加到一个简单的KMMBridge示例项目中,但也没有成功(https://github.com/ionel71089/KMMBridgeSampleKotlin)。

英文:

I'm trying to create a KMM project that publishes to Cocoapods using KMMBridge. This works fine for a basic project that only returns a strings, but when adding dependencies to make a http requests or parse json, it stops working.

I followed the Get started with Kotlin Multiplatform Mobile and after finishing, I started adding the KMMBridge code to the Gradle script. Just adding the KMMBridge plugin

id("co.touchlab.faktory.kmmbridge") version "0.3.7"

breaks the build with the following error:

  1. Caused by: java.lang.IllegalArgumentException: This fat framework already has a binary for architecture `arm64` (shared for target `ios_arm64`)

Project can be found here: https://github.com/ionel71089/KotlinMultiplatformSandbox

Here is the build.gradle.kts file for the shared module:

  1. val ktorVersion = "2.2.4"
  2. version = "0.1"
  3. plugins {
  4. kotlin("multiplatform")
  5. id("com.android.library")
  6. kotlin("plugin.serialization") version "1.8.20"
  7. kotlin("native.cocoapods")
  8. id("co.touchlab.faktory.kmmbridge") version "0.3.4" // breaks build
  9. // `maven-publish`
  10. }
  11. kotlin {
  12. android {
  13. compilations.all {
  14. kotlinOptions {
  15. jvmTarget = "1.8"
  16. }
  17. }
  18. }
  19. listOf(
  20. iosX64(),
  21. iosArm64(),
  22. iosSimulatorArm64()
  23. ).forEach {
  24. it.binaries.framework {
  25. baseName = "shared"
  26. }
  27. }
  28. sourceSets {
  29. val commonMain by getting {
  30. dependencies {
  31. implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
  32. implementation("io.ktor:ktor-client-core:$ktorVersion")
  33. implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
  34. implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
  35. }
  36. }
  37. val commonTest by getting {
  38. dependencies {
  39. implementation(kotlin("test"))
  40. implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
  41. }
  42. }
  43. val androidMain by getting {
  44. dependencies {
  45. implementation("io.ktor:ktor-client-android:$ktorVersion")
  46. }
  47. }
  48. val androidUnitTest by getting
  49. val iosX64Main by getting
  50. val iosArm64Main by getting
  51. val iosSimulatorArm64Main by getting
  52. val iosMain by creating {
  53. dependsOn(commonMain)
  54. iosX64Main.dependsOn(this)
  55. iosArm64Main.dependsOn(this)
  56. iosSimulatorArm64Main.dependsOn(this)
  57. dependencies {
  58. implementation("io.ktor:ktor-client-darwin:$ktorVersion")
  59. }
  60. }
  61. val iosX64Test by getting
  62. val iosArm64Test by getting
  63. val iosSimulatorArm64Test by getting
  64. val iosTest by creating {
  65. dependsOn(commonTest)
  66. iosX64Test.dependsOn(this)
  67. iosArm64Test.dependsOn(this)
  68. iosSimulatorArm64Test.dependsOn(this)
  69. }
  70. }
  71. cocoapods {
  72. summary = "KMMBridgeSampleKotlin"
  73. homepage = "https://touchlab.dev"
  74. ios.deploymentTarget = "13"
  75. }
  76. }
  77. android {
  78. namespace = "com.example.kotlinmultiplatformsandbox"
  79. compileSdk = 33
  80. defaultConfig {
  81. minSdk = 24
  82. targetSdk = 33
  83. }
  84. }
  85. /*
  86. addGithubPackagesRepository()
  87. kmmbridge {
  88. mavenPublishArtifacts()
  89. githubReleaseVersions()
  90. spm()
  91. cocoapods("git@github.com:ionel71089/PublicPodspecs.git")
  92. versionPrefix.set("0.8")
  93. }
  94. */

Note: I've also tried adding the dependencies to a trivial KMMBridge sample project, but that didn't work either (https://github.com/ionel71089/KMMBridgeSampleKotlin).

答案1

得分: 1

你重复了你的框架定义。请参阅KMMBridge故障排除文档:

https://kmmbridge.touchlab.co/docs/TROUBLESHOOTING#error-this-fat-framework-already-has-a-binary-for-architecture-x64-common-for-target-ios_x64-or-similar-for-arm

英文:

You're duplicating your framework definitions. See the KMMBridge Troubleshooting doc:

https://kmmbridge.touchlab.co/docs/TROUBLESHOOTING#error-this-fat-framework-already-has-a-binary-for-architecture-x64-common-for-target-ios_x64-or-similar-for-arm

huangapple
  • 本文由 发表于 2023年4月11日 16:37:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定