Skip to content

Commit

Permalink
samples: Port android build to stable android gradle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmat192 committed Nov 13, 2017
1 parent 97f666e commit 3a1a6fd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ kotstd/ll
backend.native/tests/teamcity-test.property

# Sample output
samples/**/*.kt.bc-build
samples/**/*.kt.bc-build
samples/androidNativeActivity/Polyhedron
104 changes: 47 additions & 57 deletions samples/androidNativeActivity/build.gradle
Original file line number Diff line number Diff line change
@@ -1,94 +1,84 @@
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"
}
}
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'
}

0 comments on commit 3a1a6fd

Please sign in to comment.