Reputation: 518
I am trying to add a Kotlin-Multiplatform library as a dependency to Android Project. I am getting the following error:
ERROR: The module 'my-core' is an Android project without build variants, and cannot be built. Please fix the module's configuration in the build.gradle file and sync the project again.
The build.gradle for 'my-core' Kotlin-Multiplatform library is as follows:
buildscript {
repositories {
google()
}
dependencies {
classpath 'com.squareup.sqldelight:gradle-plugin:1.3.0'
classpath 'com.android.tools.build:gradle:3.6.3'
}
}
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.72'
}
repositories {
mavenCentral()
jcenter()
google()
}
def ktor_version = '1.3.2'
def sqldeligh_version = '1.3.0'
group 'com.zoho.im.core'
version '0.0.1'
apply plugin: 'com.squareup.sqldelight'
apply plugin: 'maven-publish'
apply plugin: 'com.android.library'
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode = 1
versionName = "0.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
//This is for MultiplatformSettings
debug {
// MPP libraries don't currently get this resolution automatically
matchingFallbacks = ['release']
}
}
}
kotlin {
android()
// This is for iPhone simulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
iosX64("ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
implementation kotlin('stdlib')
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "com.squareup.sqldelight:android-driver:$sqldeligh_version"
}
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "com.squareup.sqldelight:native-driver:$sqldeligh_version"
}
}
}
}
sqldelight {
IMDatabase {
packageName = "com.harley.core"
}
}
configurations {
compileClasspath
}
The android project that I imported into is just a simple fresh project. Please advice
Upvotes: 0
Views: 956
Reputation: 518
Replacing, io.ktor:ktor-client-serialization-native:$ktor_version
with io.ktor:ktor-client-serialization:$ktor_version
fixed the issue and the aar file is generated.
Side Note: this .aar file didn't pack androidMain dependencies. I had to manually add those dependencies(io.ktor:ktor-client-okhttp:$ktor_version, io.ktor:ktor-client-serialization-jvm:$ktor_version, com.squareup.sqldelight:android-driver:$sqldeligh_version) to consuming android project.
Upvotes: 1
Reputation: 1304
It might be because you have a native dependency in commonMain sourceset: io.ktor:ktor-client-serialization-native:$ktor_version
The metadata system wouldn't be able to find an appropriate target for this dependency, which might lead to the error you demonstrate. This is just me speculating.
Upvotes: 2