Анд*_*гач 14 android gradle kotlin kotlin-multiplatform
我的 KMP + Jetpack Compose 项目中继续出现 Gradle 配置错误
配置项目“:shared”时出现问题。
未找到名为“testApi”的配置。
我的设置是:
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)
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 {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.1")
}
}
val iosMain by getting
val iosTest by getting
}
}
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(21)
targetSdkVersion(30)
}
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val sdkName = System.getenv("SDK_NAME") ?: "iphonesimulator"
val targetName = "ios" + if (sdkName.startsWith("iphoneos")) "Arm64" else "X64"
val framework = kotlin.targets.getByName<KotlinNativeTarget>(targetName).binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
Run Code Online (Sandbox Code Playgroud)
注意:通过逐个删除配置,我似乎发现问题似乎出在 android 配置本身周围,所以如果我从中删除 android() 部分
kotlin {
android()
....
Run Code Online (Sandbox Code Playgroud)
只需使用简单的 jvm() 就可以了
Pan*_*lva 35
您可以在共享模块 Gradle 文件中使用以下代码作为解决方法
android {
configurations {
create("androidTestApi")
create("androidTestDebugApi")
create("androidTestReleaseApi")
create("testApi")
create("testDebugApi")
create("testReleaseApi")
}
}
Run Code Online (Sandbox Code Playgroud)
注意:这必须放在 kotlin {} 块之前
Kotlin 1.5 M1(待定)中的问题问题出在 Canary 或 AGP 7.0.0 中:
重要提示:确保文件是 groovy 或 dsl
前提条件:这些配置必须在项目的所有模块/子模块中完成,这些模块/子模块是 KMM,并且android {}块必须在kotlin {}块
对于 Kotlin DSL:
android {
configurations {
create("androidTestApi")
create("androidTestDebugApi")
create("androidTestReleaseApi")
create("testApi")
create("testDebugApi")
create("testReleaseApi")
}
}
kotlin { }
Run Code Online (Sandbox Code Playgroud)
对于 Groovy:
android {
configurations {
androidTestApi {}
androidTestDebugApi {}
androidTestReleaseApi {}
testApi {}
testDebugApi {}
testReleaseApi {}
}
}
kotlin { }
Run Code Online (Sandbox Code Playgroud)
此外,您应该使用 AGP 7.0,因为以前版本的 gradle 会产生问题。
dependencies {
implementation("com.android.tools.build:gradle:7.0.0-alpha11")
}
Run Code Online (Sandbox Code Playgroud)
暂时最多使用 beta 版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zipclasspath 'com.android.tools.build:gradle:4.2.0-beta06'祝你好运
| 归档时间: |
|
| 查看次数: |
2459 次 |
| 最近记录: |