Android 未找到Kotlin Multiplatrom移动库的匹配变体
我有一个Kotlin多平台手机,我发布到Maven Central。我还尝试在非KMM Android应用程序中使用此库。当我在android应用程序中声明依赖项时,我得到了这个错误Android 未找到Kotlin Multiplatrom移动库的匹配变体,android,maven,kotlin,kotlin-multiplatform,kotlin-multiplatform-mobile,Android,Maven,Kotlin,Kotlin Multiplatform,Kotlin Multiplatform Mobile,我有一个Kotlin多平台手机,我发布到Maven Central。我还尝试在非KMM Android应用程序中使用此库。当我在android应用程序中声明依赖项时,我得到了这个错误 Execution failed for task ':app:checkDebugAarMetadata'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Could not res
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 a usage of 'kotlin-api' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'metadataApiElements-published' capability io.github.tyczj:tweedle-android:0.3.0:
- Incompatible because this component declares a usage of 'kotlin-metadata' of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'common' and the consumer needed a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm'
- Other compatible attribute:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Variant 'releaseApiElements-published' capability io.github.tyczj:tweedle-android:0.3.0 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Incompatible because this component declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
- Variant 'releaseRuntimeElements-published' capability io.github.tyczj:tweedle-android:0.3.0 declares a runtime of a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm':
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
我假设我的配置有问题,但我真的不知道这个错误告诉我什么,这是我第一次创建KMM库
这是我的build.gradle.kts
import org.gradle.api.tasks.bundling.Jar
plugins {
kotlin("multiplatform")
id("com.android.library")
id("kotlin-android-extensions")
id("kotlinx-serialization")
id("maven-publish")
id("signing")
}
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}
group = "io.github.tyczj"
version = "0.3.0"
kotlin {
android{
publishLibraryVariants("release")
}
ios {
binaries {
framework {
baseName = "tweedle"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:1.5.1")
implementation("io.ktor:ktor-client-json:1.5.1")
implementation("io.ktor:ktor-client-serialization:1.5.1")
implementation("io.ktor:ktor-client-logging:1.5.1")
implementation("ch.qos.logback:logback-classic:1.2.3")
// implementation("com.squareup.okio:okio:2.10.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2-native-mt"){
version {
strictly("1.4.2-native-mt")
}
}
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("androidx.core:core-ktx:1.3.2")
implementation("io.ktor:ktor-client-android:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2-native-mt")
implementation("com.github.scribejava:scribejava-apis:8.3.0")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.12")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:1.5.1")
}
}
// val iosTest by getting
}
}
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(26)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
packagingOptions {
excludes.add("META-INF/*.kotlin_module")
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
afterEvaluate {
publishing {
repositories {
maven {
name = "sonatype"
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = rootProject.ext["ossrhUsername"]?.toString()
password = rootProject.ext["ossrhPassword"]?.toString()
}
}
}
publications.withType<MavenPublication> {
artifact(javadocJar.get())
pom{
name.set("Tweedle")
description.set("Tweedle is an Android library built around the Twitter v2 API built fully in Kotlin using Kotlin Coroutines")
url.set("https://github.com/tyczj/Tweedle")
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("tyczj")
name.set("Jeff Tycz")
email.set("tyczj359@gmail.com")
}
}
scm {
url.set("https://github.com/tyczj/Tweedle")
}
}
}
}
}
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<org.jetbrains.kotlin.gradle.plugin.mpp.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)
ext["signing.keyId"] = rootProject.ext["signing.keyId"]?.toString()
ext["signing.password"] = rootProject.ext["signing.password"]?.toString()
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]?.toString()
signing {
sign(publishing.publications)
}
以及添加备用方案
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
val staging by creating{
setMatchingFallbacks(listOf("release", "debug"))
}
}
那没什么用
如果我创建了一个新的KMM项目,并且只尝试添加依赖项,我会发现一个不同的错误,就是
Failed building KotlinMPPGradleModel
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find tweedle-android-0.3.1-samplessources.jar (io.github.tyczj:tweedle-android:0.3.1).
我猜你们把图书馆出版成aar。在这种情况下,您应该显式地将@aar添加到gradle依赖项中
implementation 'io.github.tyczj:tweedle-android:0.3.0@aar'
当您包含一个不是为正确平台构建的依赖项时,会出现引用“samplessources”的错误消息。在中进行了一些讨论,在本例中,围绕发出更好的错误消息也进行了讨论
在您的例子中,它可能是由常见依赖项中的
实现(“ch.qos.logback:logback classic:1.2.3”)
触发的。这是一个JVM库,但您有一个iOS目标,因此它无法在您的通用依赖项中工作。将它移到您的Android依赖项上。我看到了一个非常类似的错误,我最初认为它与kapt有关,但我没有看到您在这里使用它。如果我在我的项目中使用kapt更改了一些配置,使用configurations[“kapt”].dependencies.add(..)
而不是kapt.annotationProcessor(..)
,我就避免了这个问题,但是项目没有在ide中构建,我认为我遇到了jdk11问题(包javax.annotationDNE),尽管在命令行上构建是成功的。我想我可以接受。希望这能给你一些想法。@tyxzj所以我试图在一个新项目中添加你的库,但没有添加。当我运行摇篮依赖关系图时,它显示+---com.tycz:tweedle android:0.3.2失败+---com.tycz:tweedle android调试:0.3.2失败仍然是相同的问题我将此依赖关系添加到我的项目中,并成功编译。这似乎是根本原因——冲突的来源。项目资源是否可用,以便我可以尝试测试自己?这一个适合我。1.注释行//实施项目(':tweedle')2。添加以下dep。分别用于发布和调试debugImplementation'io.github.tyczj:tweedle android调试:0.3。2@aar“releaseImplementation”io.github.tyczj:tweedle android:0.3。2@aar'我猜您还需要添加库依赖项debugImplementation('io.github.tyczj:tweedleandroid debug:0.3)。2@aar“){传递(真)}releaseImplementation('io.github.tyczj:tweedle android:0.3。2@aar“){可传递(true)}很抱歉反应太晚。尝试执行以下操作。在Tweedle/app/build.gradle文件中,只保留一个依赖项实现('io.github.tyczj:tweedleandroid:0.3)。2@aar“{transitive(true)}并将debug部分添加到buildType debug{matchingFallbacks=['release']}嗯,有趣的是,我只是在Ktor中调试请求时使用它,那么这是否意味着我将无法在iOS上记录请求?您可以在iOS上记录请求,但必须使用支持iOS的记录器才能这样做。有一个Logger.DEFAULT
或Logger.SIMPLE
内置,可以在iOS上转发到println()
,也可以创建自己的日志,转发到您选择的iOS日志API。您的意思是什么~“将其移动到您的Android依赖项。”
implementation 'io.github.tyczj:tweedle-android:0.3.0@aar'