AndroidNativeActivity sample: migrate to KTS
This commit is contained in:
committed by
Ilya Matveev
parent
e95be11ade
commit
edda913b04
@@ -1,98 +0,0 @@
|
|||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
|
||||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
|
||||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
||||||
classpath 'com.android.tools.build:gradle:3.3.1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
google()
|
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
|
||||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-dev' }
|
|
||||||
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
|
|
||||||
}
|
|
||||||
|
|
||||||
apply plugin: 'org.jetbrains.kotlin.multiplatform'
|
|
||||||
apply plugin: 'com.android.application'
|
|
||||||
|
|
||||||
def appDir = file("$buildDir/Polyhedron")
|
|
||||||
def libsDir = file("$appDir/libs")
|
|
||||||
Map<String, String> libsDirMapping = [
|
|
||||||
'arm32' : "$libsDir/armeabi-v7a",
|
|
||||||
'arm64' : "$libsDir/arm64-v8a"
|
|
||||||
]
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdkVersion 28
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
applicationId 'com.jetbrains.konan_activity2'
|
|
||||||
minSdkVersion 9
|
|
||||||
targetSdkVersion 28
|
|
||||||
|
|
||||||
ndk {
|
|
||||||
abiFilters 'armeabi-v7a', 'arm64-v8a'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
root 'src/arm32Main'
|
|
||||||
jniLibs.srcDir libsDir
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
[new Tuple(presets.androidNativeArm32, 'arm32'), new Tuple(presets.androidNativeArm64, 'arm64')].each {
|
|
||||||
targetFromPreset(it[0], it[1]) {
|
|
||||||
binaries {
|
|
||||||
executable() {
|
|
||||||
entryPoint = 'sample.androidnative.main'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compilations.main.cinterops {
|
|
||||||
bmpformat
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
arm64Main.dependsOn arm32Main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disable generating Kotlin metadata.
|
|
||||||
tasks.compileKotlinMetadata.enabled = false
|
|
||||||
|
|
||||||
afterEvaluate {
|
|
||||||
kotlin.targets { targets ->
|
|
||||||
[arm32, arm64].collect { target ->
|
|
||||||
String buildType = 'RELEASE' // Change to 'DEBUG' to include debug symbols.
|
|
||||||
Object linkTask = binaries.getExecutable(buildType).linkTask
|
|
||||||
|
|
||||||
// Rename binary files to 'libpoly.so' and put them to the appropriate location.
|
|
||||||
File binaryFile = binaries.getExecutable(buildType).outputFile
|
|
||||||
linkTask.doLast {
|
|
||||||
copy {
|
|
||||||
from binaryFile
|
|
||||||
into libsDirMapping[target.targetName]
|
|
||||||
rename {
|
|
||||||
'libpoly.so'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.preBuild.dependsOn linkTask
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetPreset
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
kotlin("multiplatform")
|
||||||
|
id("com.android.application") version("3.3.1")
|
||||||
|
}
|
||||||
|
|
||||||
|
val appDir = buildDir.resolve("Polyhedron")
|
||||||
|
val libsDir = appDir.resolve("libs")
|
||||||
|
|
||||||
|
val androidPresets = mapOf(
|
||||||
|
"arm32" to ("androidNativeArm32" to "$libsDir/armeabi-v7a"),
|
||||||
|
"arm64" to ("androidNativeArm64" to "$libsDir/arm64-v8a")
|
||||||
|
)
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion(28)
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId = "com.jetbrains.konan_activity2"
|
||||||
|
minSdkVersion(9)
|
||||||
|
targetSdkVersion(28)
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
abiFilters("armeabi-v7a", "arm64-v8a")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
val main by getting {
|
||||||
|
setRoot("src/arm32Main")
|
||||||
|
jniLibs.srcDir(libsDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
androidPresets.forEach { (targetName, presetInfo) ->
|
||||||
|
val (presetName, _) = presetInfo
|
||||||
|
val preset = kotlin.presets[presetName] as KotlinNativeTargetPreset
|
||||||
|
targetFromPreset(preset, targetName) {
|
||||||
|
binaries {
|
||||||
|
executable {
|
||||||
|
entryPoint = "sample.androidnative.main"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
compilations["main"].cinterops {
|
||||||
|
val bmpformat by creating
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
val arm32Main by getting
|
||||||
|
val arm64Main by getting
|
||||||
|
arm64Main.dependsOn(arm32Main)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable generating Kotlin metadata.
|
||||||
|
tasks.compileKotlinMetadata {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
androidPresets.forEach { (targetName, presetInfo) ->
|
||||||
|
val target = kotlin.targets[targetName] as KotlinNativeTarget
|
||||||
|
val (_, libDir) = presetInfo
|
||||||
|
|
||||||
|
NativeBuildType.values().forEach {
|
||||||
|
val executable = target.binaries.getExecutable(it)
|
||||||
|
val linkTask = executable.linkTask
|
||||||
|
val binaryFile = executable.outputFile
|
||||||
|
|
||||||
|
linkTask.doLast {
|
||||||
|
copy {
|
||||||
|
from(binaryFile)
|
||||||
|
into(libDir)
|
||||||
|
rename { "libpoly.so" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.preBuild {
|
||||||
|
dependsOn(linkTask)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
pluginManagement {
|
||||||
|
val kotlin_version: String by settings
|
||||||
|
resolutionStrategy {
|
||||||
|
eachPlugin {
|
||||||
|
if (requested.id.id == "org.jetbrains.kotlin.multiplatform") {
|
||||||
|
useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
|
||||||
|
}
|
||||||
|
if (requested.id.id == "com.android.application") {
|
||||||
|
useModule("com.android.tools.build:gradle:${requested.version}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
google()
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlin-dev")
|
||||||
|
maven("https://dl.bintray.com/kotlin/kotlin-eap")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user