|
apply plugin: 'kotlin-multiplatform' |
|
|
|
kotlin { |
|
targets { |
|
|
|
//create a target for Android from presets.jvm |
|
fromPreset(presets.jvm, 'android') |
|
|
|
//Xcode sets SDK_NAME environment variable - based on whether the |
|
//target device is a simulator or a real device, the preset should vary |
|
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \ |
|
? presets.iosArm64 : presets.iosX64 |
|
|
|
//outputKinds - FRAMEWORK would mean that the shared code would be exported as a FRAMEWORK |
|
// EXECUTABLE - produces a standalone executable that can be used to run as an app |
|
fromPreset(iOSTarget, 'iOS') { |
|
compilations.main.outputKinds('FRAMEWORK') |
|
} |
|
} |
|
|
|
//we have 3 different sourceSets for common, android and iOS. |
|
//each sourceSet can have their own set of dependencies and configurations |
|
sourceSets { |
|
commonMain { |
|
dependencies { |
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common' |
|
} |
|
} |
|
|
|
androidMain { |
|
dependencies { |
|
implementation 'org.jetbrains.kotlin:kotlin-stdlib' |
|
} |
|
} |
|
iosMain { |
|
} |
|
} |
|
} |
|
|
|
|
|
configurations { |
|
compileClasspath |
|
} |
|
|
|
|
|
// This task attaches native framework built from ios module to Xcode project |
|
// Don't run this task directly, |
|
// Xcode runs this task itself during its build process when we configure it. |
|
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew) |
|
//and gradlw is in executable mode (chmod +x gradlew) |
|
|
|
task packForXCode(type: Sync) { |
|
final File frameworkDir = new File(buildDir, "xcode-frameworks") |
|
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG' |
|
|
|
inputs.property "mode", mode |
|
dependsOn kotlin.targets.iOS.compilations.main.linkTaskName("FRAMEWORK", mode) |
|
|
|
from { kotlin.targets.iOS.compilations.main.getBinary("FRAMEWORK", mode).parentFile } |
|
into frameworkDir |
|
|
|
doLast { |
|
new File(frameworkDir, 'gradlew').with { |
|
text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n" |
|
setExecutable(true) |
|
} |
|
} |
|
} |
|
|
|
tasks.build.dependsOn packForXCode |