标签: kotlin-multiplatform-mobile

KMM 与公共(共享)模块中的 Java 源

由于平台限制,我们无法将 Java 源代码与 Kotlin Multiplatform Mobile 一起使用。

但如果 Kotlin 与 Java 100% 兼容,为什么我们不能将 Java 与 Kotlin Multiplatform Mobile 一起使用呢?我的意思是不仅在 Android 或 JVM 部分使用它,而且在共享代码的公共部分使用它。我们可以用 Java 编写 iOS 应用程序:)

java kotlin kotlin-multiplatform kmm kotlin-multiplatform-mobile

7
推荐指数
1
解决办法
2304
查看次数

KMM - 在项目“:shared”中找不到错误任务“embedAndSignAppleFrameworkForXcode”

我创建了一个项目来演示 Kotlin Multiplatform Mobile。我在 Android 和 iOS 两种设备上成功构建并运行了它。之后,我在 iOS 上重新运行了该项目。它有一个错误。

> Configure project :shared
Kotlin Multiplatform Projects are an Alpha feature. See: https://kotlinlang.org/docs/reference/evolution/components-stability.html. To hide this message, add 'kotlin.mpp.stability.nowarn=true' to the Gradle properties.


FAILURE: Build failed with an exception.

* What went wrong:
Task 'embedAndSignAppleFrameworkForXcode' not found in project ':shared'.

* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more …
Run Code Online (Sandbox Code Playgroud)

kotlin kotlin-multiplatform-mobile

7
推荐指数
1
解决办法
6453
查看次数

找不到 Kotlin Multiplatrom Mobile 库的匹配变体

我有一个发布到 Maven Central的 Kotlin Multiplatform Mobile。我还尝试在非 KMM Android 应用程序中使用此库。当我在 android 应用程序中声明依赖项时,我收到此错误

Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve io.github.tyczj:tweedle-android:0.3.0.
     Required by:
         project :app
      > No matching variant of io.github.tyczj:tweedle-android:0.3.0 was found. The consumer was configured to find a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - Variant 'commonMainMetadataElements-published' capability io.github.tyczj:tweedle-android:0.3.0:
              - Incompatible because this component declares …
Run Code Online (Sandbox Code Playgroud)

android maven kotlin kotlin-multiplatform kotlin-multiplatform-mobile

6
推荐指数
1
解决办法
616
查看次数

如何添加/删除/编辑 kotlinx.serialization.json.JsonObject 的值

我目前正在努力寻找向现有资产添加财产的最佳方法jsonObject(kotlinx.serialization.json.JsonObject)

甚至我发现 JsonObject 内部有私有的不可变映射

private val content: Map<String, JsonElement>
Run Code Online (Sandbox Code Playgroud)

场景:假设我已经有一个jsonObject包含 50 个属性的对象,并且考虑到任何键上的 jsonObject 都可以具有任意数量的深度。

针对这种情况,我们如何高效地执行以下操作:

  1. 添加原始属性
  2. 更新原始属性
  3. 删除原始属性

仅供参考:即使我发现有一个名为JsonObjectBuilder的类,但它并不需要现有的 JsonElement / JsonObject / JsonArray 事实上,它会新创建另一个 jsonObject。

感谢您抽出时间阅读到这里

https://github.com/Kotlin/kotlinx.serialization/issues/1593

jetbrains-ide kotlin kotlin-multiplatform kotlin-multiplatform-mobile

6
推荐指数
1
解决办法
3381
查看次数

KMM:如何解决 abi 版本不兼容的问题。当前默认值为“1.4.2”,找到“1.5.0”。1.5.20编译器生成的库?

我正在制作一个KMM application,我已经完成了Android部分,没有任何问题,一切都很完美。

然而,当我启动iOS版本时,通过打开iosMyApp.xcworkspace文件并启动编译,会出现此错误。

The following Kotlin source sets were configured but not added to any Kotlin compilation:
 * androidAndroidTestRelease
 * androidTestFixtures
 * androidTestFixturesDebug
 * androidTestFixturesRelease
You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
w: skipping /Users/jeremieguillot/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-serialization-iosx64/1.6.3/1912839739c3051183691e878ef7e4d17366f4f4/ktor-client-serialization.klib. **Incompatible abi version. The current default is '1.4.2', found '1.5.0'. The library produced by 1.5.20 compiler**
e: Could not find "/Users/jeremieguillot/.gradle/caches/modules-2/files-2.1/io.ktor/ktor-client-serialization-iosx64/1.6.3/1912839739c3051183691e878ef7e4d17366f4f4/ktor-client-serialization.klib" in [/Users/jeremieguillot/AndroidStudioProjects/SpotABivouac/iosSpotApp/Pods, /Users/jeremieguillot/.konan/klib, /Users/jeremieguillot/.konan/kotlin-native-prebuilt-macos-1.5.10/klib/common, …
Run Code Online (Sandbox Code Playgroud)

android gradle ktor kotlin-multiplatform kotlin-multiplatform-mobile

6
推荐指数
1
解决办法
2405
查看次数

Kotlin 多平台项目 (KMM) 的测试覆盖率

我有一个项目(android 和 iOS),我在其中共享共享文件夹中的通用代码。我已经在 commonTest(unit-test) 文件夹下编写了单元测试,并在 androidTest(instrumentation test) 文件夹中编写了 Instrumentation 测试。当我进行单独测试时效果很好。但我也想看看报道。虽然我可以为 commonTest 执行“运行测试覆盖率”操作,但它不适用于 androidTest。任何在这里有帮助的工具。我尝试搜索并尝试了 jacoco 和 kover 的一些东西,但无济于事。

android android-testing test-coverage kotlin-multiplatform kotlin-multiplatform-mobile

6
推荐指数
0
解决办法
413
查看次数

kotlinx.serialization.SerializationException:找不到类“MultiPartFormDataContent”的序列化器

我正在尝试上传多个文件。

val ktorVersion = "1.5.0"
val serializationVersion = "1.0.1"
Run Code Online (Sandbox Code Playgroud)

我就是这样做的:

  override suspend fun uploadFiles(
    binaryFiles: Map<String,ByteArray>
  ): BaseResponse<List<String>> {
    return client.submitForm {

      url(fileUploadUrl)
      method = HttpMethod.Post
      body = MultiPartFormDataContent(
        formData {
          headers{
            append("Content-Type", "application/json")
            append("Authorization", "Bearer $token}")
          }
          binaryFiles.entries.forEach {
            append(
              key = "files",
              value = it.value,
              headers = Headers.build {
                append(HttpHeaders.ContentDisposition, "filename=${it.key}")
              }
            )
          }
        }
      )
    }
  }

Run Code Online (Sandbox Code Playgroud)

但它抛出异常

kotlinx.serialization.SerializationException: Serializer for class 'MultiPartFormDataContent' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
    at …
Run Code Online (Sandbox Code Playgroud)

android ktor kotlinx.serialization ktor-client kotlin-multiplatform-mobile

5
推荐指数
1
解决办法
3698
查看次数

如何使用登录 kotlin 多平台 Moblie

嘿,我在 Ktor 工作。我找到了这个答案来显示特定平台 iOS 和 Android 的日志。但是当我通过 gradle 构建它时,在终端上运行此命令时出现错误。正常构建成功,没有任何错误,但是当我使用以下命令时出现错误。

./gradlew build --warning-mode all 
Run Code Online (Sandbox Code Playgroud)

错误

* What went wrong:
Could not determine the dependencies of task ':kotlinmultiplatformsharedmodule:compileIosMainKotlinMetadata'.
> Could not resolve all artifacts for configuration ':kotlinmultiplatformsharedmodule:allSourceSetsCompileDependenciesMetadata'.
   > Could not resolve io.ktor:ktor-client-logging-native:2.0.1.
     Required by:
         project :kotlinmultiplatformsharedmodule
      > Could not resolve io.ktor:ktor-client-logging-native:2.0.1.
         > Could not get resource 'https://s3.amazonaws.com/salesforcesos.com/android/maven/release/io/ktor/ktor-client-logging-native/2.0.1/ktor-client-logging-native-2.0.1.pom'.
            > Could not GET 'https://s3.amazonaws.com/salesforcesos.com/android/maven/release/io/ktor/ktor-client-logging-native/2.0.1/ktor-client-logging-native-2.0.1.pom'. Received status code 403 from server: Forbidden
      > Could not resolve io.ktor:ktor-client-logging-native:2.0.1.
         > Could not get resource 'https://mobile-sdk.jumio.com/io/ktor/ktor-client-logging-native/2.0.1/ktor-client-logging-native-2.0.1.pom'. …
Run Code Online (Sandbox Code Playgroud)

android kotlin ktor kotlin-multiplatform kotlin-multiplatform-mobile

5
推荐指数
1
解决办法
4435
查看次数

未解决的参考 iosMain Kotlin Multiplatform

我有一个其他 KMM 项目正在使用的 Kotlin 多平台库。我正在尝试构建这些 KMM 项目之一的 iOS 应用程序,但首先我需要将库二进制文件发布到 Maven 存储库。

Unresolved reference当尝试构建 iOS ARM 64 二进制文件时,我正在使用的库之一失败了。它仅在 gradle task 上失败compileIosMainKotlinMetadata,构建项目工作完美,但由于此错误,我无法生成二进制文件。

这是我常见的多平台 lib 设置 gradle:( kotlin-multiplatform-lib-setup)

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    android {
        publishAllLibraryVariants()
    }
    ios()

    sourceSets {
         commonTest {
             dependencies {
                 implementation(kotlin("test-common"))
                 implementation(kotlin("test-annotations-common"))
             }
         }

        val androidTest by getting {
            dependencies {
                implementation(kotlin("test-junit"))
                implementation("junit:junit:4.13.2")
            }
        }
    }

    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
        kotlinOptions.jvmTarget = "1.8"
    }
}

android {
    compileSdkVersion(31)

    defaultConfig {
        minSdkVersion(23)
        targetSdkVersion(31)
    }

    compileOptions { …
Run Code Online (Sandbox Code Playgroud)

android gradle kotlin kotlin-multiplatform kotlin-multiplatform-mobile

5
推荐指数
1
解决办法
1615
查看次数

如何修复 Kotlin Multiplatform Mobile gradle 红色错误

我创建了一个新的 KMM 项目,但所有 Gradle 文件中都出现红色错误

医生:

[v] System                                           
    OS: macOS (12.5.1)
    CPU: Apple M1 Pro
[v] Java
    Java (openjdk version "17.0.4" 2022-07-19 LTS)
    Location: /Library/Java/JavaVirtualMachines/openjdk17-corretto/Contents/Home/bin/java
    
    JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk17-corretto/Contents/Home
    
    * Note that, by default, Android Studio uses bundled JDK for Gradle tasks execution.
          Gradle JDK can be configured in Android Studio Preferences under Build, Execution, Deployment -> Build Tools -> Gradle section
    
[v] Android Studio
    Android Studio (2021.2)
    Location: /Users/ahmedhnewa/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/212.5712.43.2112.8815526/Android Studio.app
    Bundled Java: openjdk 11.0.12 2021-07-20
    Kotlin Plugin: 212-1.7.10-release-333-AS5457.46
    Kotlin Multiplatform Mobile …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-studio gradle-kotlin-dsl kotlin-multiplatform-mobile

5
推荐指数
1
解决办法
4211
查看次数