小编Анд*_*гач的帖子

Kotlin 多平台配置问题

我的 KMP + Jetpack Compose 项目中继续出现 Gradle 配置错误

配置项目“:shared”时出现问题。

未找到名为“testApi”的配置。

我的设置是:

  1. Android Studio 北极狐 2020.3.1 Canary 3
  2. 项目级别设置
dependencies {
   classpath("com.android.tools.build:gradle:7.0.0-alpha03")
   classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20")
}
Run Code Online (Sandbox Code Playgroud)
  1. '共享模块'
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

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

kotlin {
    android()
    ios {
        binaries {
            framework {
                baseName = "shared"
            }
        }
    }
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
            }
        }
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.2.1")
            }
        }
        val androidTest by getting {
            dependencies { …
Run Code Online (Sandbox Code Playgroud)

android gradle kotlin kotlin-multiplatform

14
推荐指数
2
解决办法
2459
查看次数

实时数据后值是否需要observeOn?

在这种情况下需要观察或在 livedata 中发布值本身就足以正确处理它。

method()
  .subscribeOn(Schedulers.io())
  .observeOn(AndroidSchedulers.mainThread())
  .subscribe(
     { liveData.postValue(it) },
     { Timber.e(it) }
  )
Run Code Online (Sandbox Code Playgroud)

kotlin rx-java2 android-livedata

4
推荐指数
1
解决办法
338
查看次数