|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset |
|
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess |
|
|
|
group = "com.example.lib" |
|
version = "1.2.3" |
|
|
|
repositories { |
|
google() |
|
jcenter() |
|
} |
|
|
|
plugins { |
|
id("maven-publish") |
|
id("com.android.library") version "3.2.1" |
|
id("org.jetbrains.kotlin.multiplatform") version "1.3.21" |
|
} |
|
|
|
android { |
|
|
|
compileSdkVersion(28) |
|
|
|
defaultConfig { |
|
minSdkVersion(16) |
|
targetSdkVersion(28) |
|
} |
|
|
|
sourceSets { |
|
getByName("main") { |
|
setRoot("src/androidMain") |
|
} |
|
getByName("test") { |
|
setRoot("src/androidTest") |
|
} |
|
} |
|
|
|
lintOptions { |
|
isAbortOnError = false |
|
} |
|
|
|
} |
|
|
|
kotlin { |
|
|
|
data class IosTarget(val name: String, val preset: String, val id: String) |
|
|
|
val iosTargets = listOf( |
|
IosTarget("ios", "iosArm64", "ios-arm64"), |
|
IosTarget("iosSim", "iosX64", "ios-x64") |
|
) |
|
|
|
android { |
|
publishAllLibraryVariants() |
|
} |
|
|
|
for ((targetName, presetName, id) in iosTargets) { |
|
targetFromPreset(presets.getByName<KotlinNativeTargetPreset>(presetName), targetName) { |
|
compilations { |
|
getByName("main") { |
|
val carthageBuildDir = "$projectDir/Carthage/Build/iOS" |
|
cinterops(Action { |
|
val bugsnag by creating { |
|
defFile("src/iosMain/cinterop/bugsnag.def") |
|
includeDirs.allHeaders("$carthageBuildDir/Bugsnag.framework/Headers") |
|
} |
|
}) |
|
} |
|
} |
|
mavenPublication { |
|
artifactId = "${project.name}-$id" |
|
} |
|
} |
|
} |
|
|
|
sourceSets { |
|
|
|
getByName("commonMain") { |
|
dependencies { |
|
implementation(kotlin("stdlib-common")) |
|
} |
|
} |
|
|
|
getByName("androidMain") { |
|
dependencies { |
|
implementation(kotlin("stdlib")) |
|
implementation(kotlin("reflect")) |
|
|
|
implementation("com.bugsnag:bugsnag-android:4.11.0") |
|
} |
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Create Carthage tasks |
|
listOf("bootstrap", "update").forEach { type -> |
|
task<Exec>("carthage${type.capitalize()}") { |
|
group = "carthage" |
|
executable = "carthage" |
|
args( |
|
type, |
|
"--platform", "iOS", |
|
"--no-use-binaries", // Provided binaries are sometimes problematic, remove this to speedup process |
|
"--cache-builds" |
|
) |
|
} |
|
} |
|
|
|
// Make CInterop tasks depend on Carthage |
|
tasks.withType<CInteropProcess> { |
|
dependsOn("carthageBootstrap") |
|
} |
|
|
|
// Delete build directory on clean |
|
tasks.named<Delete>("clean") { |
|
delete(buildDir) |
|
} |
|
|
|
// Temporary workaround for https://youtrack.jetbrains.com/issue/KT-27170 |
|
configurations.create("compileClasspath") |