From 3a1a6fd6fbb2912c217434b58b313e498e89f321 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 8 Nov 2017 17:49:19 +0300 Subject: [PATCH] samples: Port android build to stable android gradle plugin --- .gitignore | 3 +- samples/androidNativeActivity/build.gradle | 104 ++++++++++----------- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 13e5b3fd5ee..ba6baa0b118 100644 --- a/.gitignore +++ b/.gitignore @@ -53,4 +53,5 @@ kotstd/ll backend.native/tests/teamcity-test.property # Sample output -samples/**/*.kt.bc-build \ No newline at end of file +samples/**/*.kt.bc-build +samples/androidNativeActivity/Polyhedron \ No newline at end of file diff --git a/samples/androidNativeActivity/build.gradle b/samples/androidNativeActivity/build.gradle index 05c446c05c3..75425d0a3f6 100644 --- a/samples/androidNativeActivity/build.gradle +++ b/samples/androidNativeActivity/build.gradle @@ -1,12 +1,6 @@ buildscript { repositories { - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle-experimental:0.9.2' - } - - repositories { + jcenter() mavenCentral() maven { url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies" @@ -14,81 +8,77 @@ buildscript { } dependencies { classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+" + classpath "com.android.tools.build:gradle:2.3.3" } } -allprojects { - repositories { - jcenter() - } +repositories { + jcenter() } -apply plugin: "konan" +apply plugin: 'konan' +apply plugin: 'com.android.application' -def platforms = ["armeabi-v7a", "arm64-v8a"] -konan.targets = ["android_arm32", "android_arm64"] +konan.targets = ['android_arm32', 'android_arm64'] + +def outDir = file('Polyhedron') +def libsDir = file("$outDir/libs") +def platforms = [ + "armeabi-v7a": [konanTarget: "android_arm32"], + "arm64-v8a" : [konanTarget: "android_arm64"] +] konanArtifacts { program('Polyhedron') { - baseDir 'Polyhedron' artifactName 'libpoly' } } -apply plugin: "com.android.model.application" - -model { - android { - compileSdkVersion = 25 - buildToolsVersion = '25.0.2' +task copyLibs(type: Copy) { + dependsOn konanArtifacts.Polyhedron + destinationDir libsDir - defaultConfig { - applicationId = 'com.android.konan_activity' - minSdkVersion.apiLevel 9 - targetSdkVersion.apiLevel 25 + platforms.each { name, platform -> + into(name) { + from konanArtifacts.Polyhedron."${platform.konanTarget}".artifact } + } +} - ndk { - moduleName = "polyhedron" - } +task deleteOut(type: Delete) { + delete outDir +} - productFlavors { - create("arm") { - ndk { - abiFilters.addAll(platforms) - } - } - } - } +clean.dependsOn deleteOut - repositories { - libs(PrebuiltLibraries) { - libpoly { - binaries.withType(SharedLibraryBinary) { - def name = targetPlatform.getName() - def index = platforms.indexOf(name) - if (index >= 0) - sharedLibraryFile = konanArtifacts.Polyhedron."${konan.targets[index]}".artifact - } - } +tasks.matching { it.name == 'preBuild' }.all { + it.dependsOn copyLibs +} + +android { + compileSdkVersion 25 + buildToolsVersion '25.0.2' + + defaultConfig { + applicationId 'com.jetbrains.konan_activity2' + minSdkVersion 9 + targetSdkVersion 25 + + ndk { + abiFilters "armeabi-v7a", "arm64-v8a" } } - android.sources { + + sourceSets { main { - jniLibs { - dependencies { - library "libpoly" - } - } + jniLibs.srcDir libsDir } } -} -tasks.matching { it.name == 'preBuild' }.all { - it.dependsOn 'compileKonan' } -task buildApk(type: DefaultTask) { - dependsOn "compileKonan" +task buildApk(type: Copy) { dependsOn "assembleDebug" + destinationDir outDir + from 'build/outputs/apk' } \ No newline at end of file