blob: 94fcb918b4a30524f08059bc7f7bc4719020bc1f [file] [log] [blame]
Alexander Afanasyevddaa8312015-01-27 16:33:45 -08001import org.apache.tools.ant.taskdefs.condition.Os
2
3apply plugin: 'com.android.application'
4
5android {
Ivan Yeo432488f2015-02-02 19:35:23 -08006 compileSdkVersion 19
Alexander Afanasyevddaa8312015-01-27 16:33:45 -08007 buildToolsVersion "21.1.2"
8
9 defaultConfig {
10 applicationId "net.named_data.nfd"
Ivan Yeo432488f2015-02-02 19:35:23 -080011 minSdkVersion 15
12 targetSdkVersion 19
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080013 versionCode 2001
14 versionName "0.2.1"
15 }
16 buildTypes {
17 release {
18 minifyEnabled false
19 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080021 debug {
22 debuggable true
23 jniDebuggable true
24 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080025 }
26 sourceSets {
27 main {
28 java.srcDirs "src/main/java"
29 res.srcDirs "src/main/res"
30 jniLibs.srcDir 'src/main/libs'
31 jni.srcDirs = [] //disable automatic ndk-build call
32 }
33 androidTest.setRoot('tests')
34 androidTest.java.srcDirs = ['tests/src']
35 }
36
37 splits {
38 abi {
39 enable true // enable ABI split feature to create one APK per ABI
40 universalApk true //generate an additional APK that targets all the ABIs
41 }
42 }
43
44 // map for the version code
45 // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
46 project.ext.versionCodes = ['armeabi': 1,
47 'armeabi-v7a': 2,
48 'arm64-v8a': 3,
49 'mips': 5,
50 'mips64': 6,
51 'x86': 8,
52 'x86_64': 9]
53
54 android.applicationVariants.all { variant ->
55 // assign different version code for each output
56 variant.outputs.each { output ->
57 output.versionCodeOverride = project.ext.versionCodes.get(
58 output.getFilter(
59 com.android.build.OutputFile.ABI), 0) * 1000000 +
60 defaultConfig.versionCode
61 }
62 }
63
64 // call regular ndk-build(.cmd) script from app directory
65 task ndkBuild(type: Exec) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080066 def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]
67
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080068 if (System.env.NDK_BUILD_PARALLEL != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080069 args.add("-j" + System.env.NDK_BUILD_PARALLEL)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080070 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080071 else {
72 args.add("-j" + Runtime.runtime.availableProcessors())
73 }
74
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080075 if (System.env.NDK_BUILD_ABI != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080076 args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080077 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080078
79 if (System.env.NDK_DEBUG != null) {
80 args.add("NDK_DEBUG=1")
81 }
82 commandLine args
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080083 }
84
85 tasks.withType(JavaCompile) {
86 compileTask -> compileTask.dependsOn ndkBuild
87 }
88
89 task cleanNative(type: Exec) {
90 commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
91 }
92
93 clean.dependsOn cleanNative
94}
95
96def getNdkBuildCmd() {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080097 def ndk_build = getNdkDir() + "/ndk-build"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080098 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
99 ndk_build += ".cmd"
100 }
101
102 return ndk_build
103}
104
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800105def getNdkDir() {
106 if (System.env.ANDROID_NDK_ROOT != null)
107 return System.env.ANDROID_NDK_ROOT
108
109 Properties properties = new Properties()
110 properties.load(project.rootProject.file('local.properties').newDataInputStream())
111 def ndk_dir = properties.getProperty('ndk.dir', null)
112 if (ndk_dir == null) {
113 throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
114 }
115 return ndk_dir
116}
117
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800118dependencies {
119 compile fileTree(dir: 'libs', include: ['*.jar'])
Ivan Yeo432488f2015-02-02 19:35:23 -0800120 compile 'com.android.support:appcompat-v7:20.0.0'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800121 compile 'com.android.support:support-v4:21.0.3'
122}