Skip to content

Commit 3a1a6fd

Browse files
committed
samples: Port android build to stable android gradle plugin
1 parent 97f666e commit 3a1a6fd

File tree

2 files changed

+49
-58
lines changed

2 files changed

+49
-58
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ kotstd/ll
5353
backend.native/tests/teamcity-test.property
5454

5555
# Sample output
56-
samples/**/*.kt.bc-build
56+
samples/**/*.kt.bc-build
57+
samples/androidNativeActivity/Polyhedron
Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,84 @@
11
buildscript {
22
repositories {
3-
jcenter()
4-
}
5-
dependencies {
6-
classpath 'com.android.tools.build:gradle-experimental:0.9.2'
7-
}
8-
9-
repositories {
3+
jcenter()
104
mavenCentral()
115
maven {
126
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
137
}
148
}
159
dependencies {
1610
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:+"
11+
classpath "com.android.tools.build:gradle:2.3.3"
1712
}
1813
}
1914

20-
allprojects {
21-
repositories {
22-
jcenter()
23-
}
15+
repositories {
16+
jcenter()
2417
}
2518

26-
apply plugin: "konan"
19+
apply plugin: 'konan'
20+
apply plugin: 'com.android.application'
2721

28-
def platforms = ["armeabi-v7a", "arm64-v8a"]
29-
konan.targets = ["android_arm32", "android_arm64"]
22+
konan.targets = ['android_arm32', 'android_arm64']
23+
24+
def outDir = file('Polyhedron')
25+
def libsDir = file("$outDir/libs")
26+
def platforms = [
27+
"armeabi-v7a": [konanTarget: "android_arm32"],
28+
"arm64-v8a" : [konanTarget: "android_arm64"]
29+
]
3030

3131
konanArtifacts {
3232
program('Polyhedron') {
33-
baseDir 'Polyhedron'
3433
artifactName 'libpoly'
3534
}
3635
}
3736

38-
apply plugin: "com.android.model.application"
39-
40-
model {
41-
android {
42-
compileSdkVersion = 25
43-
buildToolsVersion = '25.0.2'
37+
task copyLibs(type: Copy) {
38+
dependsOn konanArtifacts.Polyhedron
39+
destinationDir libsDir
4440

45-
defaultConfig {
46-
applicationId = 'com.android.konan_activity'
47-
minSdkVersion.apiLevel 9
48-
targetSdkVersion.apiLevel 25
41+
platforms.each { name, platform ->
42+
into(name) {
43+
from konanArtifacts.Polyhedron."${platform.konanTarget}".artifact
4944
}
45+
}
46+
}
5047

51-
ndk {
52-
moduleName = "polyhedron"
53-
}
48+
task deleteOut(type: Delete) {
49+
delete outDir
50+
}
5451

55-
productFlavors {
56-
create("arm") {
57-
ndk {
58-
abiFilters.addAll(platforms)
59-
}
60-
}
61-
}
62-
}
52+
clean.dependsOn deleteOut
6353

64-
repositories {
65-
libs(PrebuiltLibraries) {
66-
libpoly {
67-
binaries.withType(SharedLibraryBinary) {
68-
def name = targetPlatform.getName()
69-
def index = platforms.indexOf(name)
70-
if (index >= 0)
71-
sharedLibraryFile = konanArtifacts.Polyhedron."${konan.targets[index]}".artifact
72-
}
73-
}
54+
tasks.matching { it.name == 'preBuild' }.all {
55+
it.dependsOn copyLibs
56+
}
57+
58+
android {
59+
compileSdkVersion 25
60+
buildToolsVersion '25.0.2'
61+
62+
defaultConfig {
63+
applicationId 'com.jetbrains.konan_activity2'
64+
minSdkVersion 9
65+
targetSdkVersion 25
66+
67+
ndk {
68+
abiFilters "armeabi-v7a", "arm64-v8a"
7469
}
7570
}
76-
android.sources {
71+
72+
sourceSets {
7773
main {
78-
jniLibs {
79-
dependencies {
80-
library "libpoly"
81-
}
82-
}
74+
jniLibs.srcDir libsDir
8375
}
8476
}
85-
}
8677

87-
tasks.matching { it.name == 'preBuild' }.all {
88-
it.dependsOn 'compileKonan'
8978
}
9079

91-
task buildApk(type: DefaultTask) {
92-
dependsOn "compileKonan"
80+
task buildApk(type: Copy) {
9381
dependsOn "assembleDebug"
82+
destinationDir outDir
83+
from 'build/outputs/apk'
9484
}

0 commit comments

Comments
 (0)