-
-
Save fluidsonic/04f7b15c4bc5263cd5f82632697804a4 to your computer and use it in GitHub Desktop.
Kotlin Multiplatform Android Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.android.build.gradle.api.AndroidSourceSet | |
import com.android.build.gradle.internal.dsl.BuildType | |
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet | |
group = "test" | |
version = "0.9.0" | |
plugins { | |
id("com.android.library") version "3.3.1" | |
kotlin("multiplatform") version "1.3.21" | |
} | |
repositories { | |
google() | |
jcenter() | |
mavenCentral() | |
} | |
kotlin { | |
android() | |
sourceSets { | |
commonMain { | |
dependencies { | |
implementation(kotlin("stdlib-common")) | |
} | |
} | |
androidMain { | |
dependsOn(commonMain) | |
dependencies { | |
implementation(kotlin("stdlib-jdk8")) | |
} | |
} | |
} | |
} | |
android { | |
compileSdkVersion(28) | |
defaultConfig { | |
minSdkVersion(24) | |
targetSdkVersion(28) | |
} | |
buildTypes { | |
release { | |
isMinifyEnabled = false | |
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") | |
} | |
} | |
compileOptions { | |
sourceCompatibility = JavaVersion.VERSION_1_8 | |
targetCompatibility = JavaVersion.VERSION_1_8 | |
} | |
sourceSets { | |
main { | |
setRoot("src/androidMain") | |
} | |
} | |
} | |
tasks.withType<Wrapper> { | |
distributionType = Wrapper.DistributionType.ALL | |
gradleVersion = "5.2.1" | |
} | |
// DSL | |
val NamedDomainObjectContainer<AndroidSourceSet>.main | |
get() = named<AndroidSourceSet>("main") | |
val NamedDomainObjectContainer<BuildType>.release | |
get() = named<BuildType>("release") | |
val NamedDomainObjectContainer<KotlinSourceSet>.androidMain: KotlinSourceSet | |
get() = this["androidMain"] | |
fun KotlinSourceSet.dependsOn(other: NamedDomainObjectProvider<KotlinSourceSet>) = | |
dependsOn(other.get()) | |
inline operator fun KotlinSourceSet.invoke(configure: KotlinSourceSet.() -> Unit) = | |
configure() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pluginManagement { | |
repositories { | |
gradlePluginPortal() | |
jcenter() | |
google() | |
} | |
resolutionStrategy { | |
eachPlugin { | |
if (requested.id.id == "kotlin-multiplatform") { | |
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") | |
} | |
if (requested.id.id.startsWith("com.android.")) { | |
useModule("com.android.tools.build:gradle:${requested.version}") | |
} | |
} | |
} | |
} | |
rootProject.name = "test" | |
enableFeaturePreview("GRADLE_METADATA") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment