|
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 { |
|
val main by getting { |
|
setRoot("src/androidMain") |
|
} |
|
val test by getting { |
|
setRoot("src/androidTest") |
|
} |
|
} |
|
|
|
lintOptions { |
|
isAbortOnError = false |
|
} |
|
|
|
packagingOptions { |
|
exclude("META-INF/*.kotlin_module") |
|
} |
|
|
|
} |
|
|
|
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 { |
|
val main by getting { |
|
val carthageBuildDir = "$projectDir/Carthage/Build/iOS" |
|
cinterops(Action { |
|
val bugsnag by creating { |
|
defFile("src/iosMain/cinterop/bugsnag.def") |
|
includeDirs.allHeaders("$carthageBuildDir/Bugsnag.framework/Headers") |
|
} |
|
}) |
|
linkerOpts("-F$carthageBuildDir") |
|
} |
|
} |
|
mavenPublication { |
|
artifactId = "${project.name}-$id" |
|
} |
|
} |
|
} |
|
|
|
sourceSets { |
|
|
|
val commonMain by getting { |
|
dependencies { |
|
implementation(kotlin("stdlib-common")) |
|
} |
|
} |
|
|
|
val androidMain by getting { |
|
dependencies { |
|
implementation(kotlin("stdlib")) |
|
implementation(kotlin("reflect")) |
|
|
|
implementation("com.bugsnag:bugsnag-android:4.11.0") |
|
} |
|
} |
|
|
|
val iosMain by getting { |
|
|
|
} |
|
|
|
val iosSimMain by getting { |
|
dependsOn(iosMain) |
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// 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::class) { |
|
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") |
Thanks for the helpful infos!
It looks like with Kotlin 1.3.50 linkerOpts doesn't exist anymore on the
KotlinNativeCompilation
target. It exsist in theDefaultCInteropSettings
, but that prints out a warning that it's not used anymore.Is
target.binaries.forEach { it.linkerOpts ... }
the correct way to handle this? I've tried it but so far I failed atReason: image not found
Edit: for unit tests and their dynamic frameworks: copy the frameworks to the location of the kexe in a directory called
Frameworks
and voilà, it works.