blob: df4909717c93fbaf8e99f78480746bc278eca568 [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 }
21 }
22 sourceSets {
23 main {
24 java.srcDirs "src/main/java"
25 res.srcDirs "src/main/res"
26 jniLibs.srcDir 'src/main/libs'
27 jni.srcDirs = [] //disable automatic ndk-build call
28 }
29 androidTest.setRoot('tests')
30 androidTest.java.srcDirs = ['tests/src']
31 }
32
33 splits {
34 abi {
35 enable true // enable ABI split feature to create one APK per ABI
36 universalApk true //generate an additional APK that targets all the ABIs
37 }
38 }
39
40 // map for the version code
41 // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
42 project.ext.versionCodes = ['armeabi': 1,
43 'armeabi-v7a': 2,
44 'arm64-v8a': 3,
45 'mips': 5,
46 'mips64': 6,
47 'x86': 8,
48 'x86_64': 9]
49
50 android.applicationVariants.all { variant ->
51 // assign different version code for each output
52 variant.outputs.each { output ->
53 output.versionCodeOverride = project.ext.versionCodes.get(
54 output.getFilter(
55 com.android.build.OutputFile.ABI), 0) * 1000000 +
56 defaultConfig.versionCode
57 }
58 }
59
60 // call regular ndk-build(.cmd) script from app directory
61 task ndkBuild(type: Exec) {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080062 def ndkBuildParallel = Runtime.runtime.availableProcessors()
63 if (System.env.NDK_BUILD_PARALLEL != null) {
64 ndkBuildParallel = System.env.NDK_BUILD_PARALLEL
65 }
66 def ndkBuildAbi = "all"
67 if (System.env.NDK_BUILD_ABI != null) {
68 ndkBuildAbi = System.env.NDK_BUILD_ABI
69 }
70 commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, '-j', ndkBuildParallel, "APP_ABI=" + ndkBuildAbi
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080071 }
72
73 tasks.withType(JavaCompile) {
74 compileTask -> compileTask.dependsOn ndkBuild
75 }
76
77 task cleanNative(type: Exec) {
78 commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
79 }
80
81 clean.dependsOn cleanNative
82}
83
84def getNdkBuildCmd() {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080085 def ndk_build = getNdkDir() + "/ndk-build"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080086 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
87 ndk_build += ".cmd"
88 }
89
90 return ndk_build
91}
92
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080093def getNdkDir() {
94 if (System.env.ANDROID_NDK_ROOT != null)
95 return System.env.ANDROID_NDK_ROOT
96
97 Properties properties = new Properties()
98 properties.load(project.rootProject.file('local.properties').newDataInputStream())
99 def ndk_dir = properties.getProperty('ndk.dir', null)
100 if (ndk_dir == null) {
101 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.")
102 }
103 return ndk_dir
104}
105
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800106dependencies {
107 compile fileTree(dir: 'libs', include: ['*.jar'])
Ivan Yeo432488f2015-02-02 19:35:23 -0800108 compile 'com.android.support:appcompat-v7:20.0.0'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800109 compile 'com.android.support:support-v4:21.0.3'
110}