I am trying to set up Android Library via Kotlin Multiplatform Library.
I am getting error:
Plugin [id: 'com.android.library'] was not found in any of the following sources:
Please help me by pointing out what is wrong and how to resolve this issue.
My plugin set up is this(with supposedly proper buildscript):
plugins {
id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
id("com.android.library")
id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
id("com.squareup.sqldelight")
}
when I replace that with following
plugins {
id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
id("org.jetbrains.kotlin.plugin.serialization").version("1.3.72")
}
apply plugin: 'com.android.library'
apply plugin: 'com.squareup.sqldelight'
it's working fine. I am not sure what causes the issue.
Following is the complete build.gradle:
buildscript {
repositories {
mavenCentral()
jcenter()
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.plugin.serialization").version("1.3.72")
id("com.android.library")
id("org.jetbrains.kotlin.multiplatform").version("1.3.72")
id("com.squareup.sqldelight")
}
repositories {
mavenCentral()
jcenter()
google()
}
group 'com.jolas.sdk.kn.newsycore'
version '0.0.1'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
def ktor_version = '1.3.2'
kotlin {
android {
publishLibraryVariants("release", "debug")
}
// 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:$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:sqlite-driver:1.3.0"
}
}
iosMain {
dependencies {
implementation kotlin('stdlib')
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "com.squareup.sqldelight:native-driver:1.3.0"
}
}
}
}
sqldelight {
NewsyDatabase {
packageName = "com.jolas.sdk.kn.newsycore"
}
}
configurations {
compileClasspath
}
Nelson is correct regarding the pluginManagement
block, but there is an additional requirement for a plugin to be found without additional configuration. If you require plugins { id("com.android.application") version "3.6.1" }
, Gradle would search for the following Maven artifact: com.android.application:com.android.application.gradle.plugin:3.6.1
. This is a convention. When developing your custom plugin, Gradle's default java-gradle-plugin
will provide such an artifact out of the box. See the corresponding section of Gradle docs for more details.
To override module resolution for any plugin, you can use the resolutionStrategy
block. I've got the following for Android plugins:
pluginManagement {
repositories {
google()
gradlePluginPortal()
jcenter()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:${requested.version}")
} else if(requested.id.namespace == "com.google.gms") {
useModule("com.google.gms:${requested.id.name}:${requested.version}")
}
}
}
}
Having this in your settings.gradle.kts
will allow you to use the usual plugins
block as follows:
plugins {
id("com.android.application") version "3.6.1"
id("com.google.gms.google-services") version "4.3.3"
}
Of course, to re-use the same version of the plugin in all submodules you can go with the usual route of apply false
:
/build.gradle.kts:
plugins {
id("com.android.application") version "3.6.1" apply false
id("com.android.library") version "3.6.1" apply false
// ...
}
/lib/build.gradle.kts:
plugins {
id("com.android.library")
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With