forked from koral--/android-gif-drawable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ndk.gradle
69 lines (58 loc) · 1.69 KB
/
ndk.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import org.apache.tools.ant.taskdefs.condition.Os
def isDebugBuild() {
!gradle.startParameter.taskNames.contains("uploadArchives") && VERSION_NAME.contains("SNAPSHOT")
}
def shouldAddFlavors() {
def flavors = ['armeabi', 'armeabi-v7a', 'x86', 'mips', 'arm64-v8a', 'mips64', 'x86_64']
boolean applyFlavors = false
gradle.startParameter.taskNames.each() {
String normalizedTaskName = it.toLowerCase(Locale.ROOT)
flavors.each() {
applyFlavors |= normalizedTaskName.contains(it)
}
}
applyFlavors
}
def addFlavors() {
android productFlavors {
flavors.each() {
String flavor = it
"${it}" {
ndk {
abiFilter flavor
}
}
}
fat
}
}
def getNdkBuildCommand() {
def command = "${android.ndkDirectory}/ndk-build"
Os.isFamily(Os.FAMILY_WINDOWS) ? "${command}.cmd" : command
}
android {
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set .so files location to libs
jni.srcDirs = [] //disable automatic ndk-build call
}
def srcDir = file('src/main/jni').absolutePath
task buildNative(type: Exec) {
environment 'NDK_DEBUG', isDebugBuild() ? '1' : '0'
commandLine getNdkBuildCommand(),
'-C', srcDir,
'all'
}
task cleanNative(type: Exec) {
commandLine getNdkBuildCommand(),
'-C', srcDir,
'clean'
}
buildTypes.debug.jniDebuggable isDebugBuild()
if (shouldAddFlavors()) {
addFlavors()
}
}
clean.dependsOn cleanNative
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}