【问题标题】:KMM - How to add Retrofit into :shared module (commonMain)KMM - 如何将改造添加到 :shared 模块 (commonMain)
【发布时间】:2021-10-09 18:02:52
【问题描述】:

我想将 Retrofit 添加到 :shared 模块 (commonMain) 中。

sourceSets["commonMain"].dependencies {
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
}

但是在commonMain 我看不到改造类。在androidMain 我可以看到它。那是一种魔法。我没有将 Retrofit 添加到 androidMain

请帮助我。提前致谢。

【问题讨论】:

    标签: kotlin kotlin-multiplatform kotlin-multiplatform-mobile


    【解决方案1】:

    Retrofit 是一个 Java 和 Android 库,这意味着您只能在 KMP 中的 JVM 目标之间共享它。

    如果您正在构建 KMM 应用程序(iOS 和 Android 目标),则不能在共享代码中使用 Retrofit,除非您对其创建抽象,并提供本机/iOS 实现(这是一个繁琐的工作)。

    您可以改用Ktor

    【讨论】:

      猜你喜欢
      • 2021-09-09
      • 2022-10-20
      • 1970-01-01
      • 2022-11-02
      • 2012-09-09
      • 2016-05-27
      • 2020-11-16
      • 2013-11-01
      • 2011-09-05
      相关资源
      最近更新 更多