blob: de674a8c8ab4c183d57add173f4f403f6c3ae20e [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 {
Alexander Afanasyevb72e1442017-07-10 13:10:11 -07006 compileSdkVersion 26
Alexander Afanasyevda066292017-11-12 23:02:31 -05007 buildToolsVersion "26.0.3"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -08008
9 defaultConfig {
10 applicationId "net.named_data.nfd"
Alexander Afanasyevda066292017-11-12 23:02:31 -050011 minSdkVersion 23
12 targetSdkVersion 23
Alexander Afanasyev0e164652017-12-07 17:32:05 -050013 versionCode 4007
Alexander Afanasyev79a0fff2017-12-05 12:45:14 -050014 versionName "0.3.0 (NFD 0.6.0, ndn-cxx 0.6.0)"
Alexander Afanasyevda066292017-11-12 23:02:31 -050015 multiDexEnabled true
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080016 }
Alexander Afanasyev03177422015-03-11 13:38:05 -070017 compileOptions {
Alexander Afanasyev4a20a882017-12-07 17:44:07 -050018 sourceCompatibility JavaVersion.VERSION_1_8
19 targetCompatibility JavaVersion.VERSION_1_8
Alexander Afanasyev03177422015-03-11 13:38:05 -070020 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080021 buildTypes {
22 release {
Alexander Afanasyevda066292017-11-12 23:02:31 -050023 minifyEnabled true
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080024 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080026 debug {
27 debuggable true
28 jniDebuggable true
29 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080030 }
31 sourceSets {
32 main {
33 java.srcDirs "src/main/java"
34 res.srcDirs "src/main/res"
35 jniLibs.srcDir 'src/main/libs'
36 jni.srcDirs = [] //disable automatic ndk-build call
37 }
38 androidTest.setRoot('tests')
39 androidTest.java.srcDirs = ['tests/src']
40 }
Alexander Afanasyev2a78ac62015-03-15 14:02:34 -070041 packagingOptions {
42 exclude 'META-INF/LICENSE.txt'
43 exclude 'META-INF/NOTICE.txt'
44 }
Alexander Afanasyevda066292017-11-12 23:02:31 -050045 lintOptions {
46 abortOnError false
47 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080048
49 splits {
50 abi {
51 enable true // enable ABI split feature to create one APK per ABI
Alexander Afanasyev0e164652017-12-07 17:32:05 -050052 reset()
53 include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080054 universalApk false // don't generate an additional APK that targets all the ABIs
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080055 }
56 }
57
58 // map for the version code
59 // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
Alexander Afanasyevda066292017-11-12 23:02:31 -050060 project.ext.versionCodes = [//'armeabi': 1, // Deprecated in r16. Will be removed in r17. No hard float.
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080061 'armeabi-v7a': 2,
62 'arm64-v8a': 3,
Alexander Afanasyevda066292017-11-12 23:02:31 -050063 // 'mips': 5, // Deprecated in r16. Will be removed in r17. Uses hard-float, and assumes a CPU:FPU clock ratio of 2:1 for maximum compatibility. Provides neither micromips nor MIPS16.
64 // 'mips64': 6, // Deprecated in r16. WIll be removed in r17
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080065 'x86': 8,
66 'x86_64': 9]
67
68 android.applicationVariants.all { variant ->
69 // assign different version code for each output
70 variant.outputs.each { output ->
71 output.versionCodeOverride = project.ext.versionCodes.get(
72 output.getFilter(
73 com.android.build.OutputFile.ABI), 0) * 1000000 +
74 defaultConfig.versionCode
75 }
76 }
77
Alexander Afanasyev93886942016-02-09 16:00:24 -080078 task copyNdnCxxHeaders(type: Copy) {
79 from('src/main/jni/ndn-cxx/src') {
80 include '**/*.hpp'
81 }
82 into 'build/generated/source/include/ndn-cxx'
83 }
84
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080085 // call regular ndk-build(.cmd) script from app directory
86 task ndkBuild(type: Exec) {
Alexander Afanasyev93886942016-02-09 16:00:24 -080087 dependsOn copyNdnCxxHeaders
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080088 def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]
89
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080090 if (System.env.NDK_BUILD_PARALLEL != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080091 args.add("-j" + System.env.NDK_BUILD_PARALLEL)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080092 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080093 else {
94 args.add("-j" + Runtime.runtime.availableProcessors())
95 }
96
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080097 if (System.env.NDK_BUILD_ABI != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080098 args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080099 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -0800100
101 if (System.env.NDK_DEBUG != null) {
Alexander Afanasyevda066292017-11-12 23:02:31 -0500102 args.add("V=1")
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -0800103 }
104 commandLine args
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800105 }
106
107 tasks.withType(JavaCompile) {
108 compileTask -> compileTask.dependsOn ndkBuild
109 }
110
111 task cleanNative(type: Exec) {
112 commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
113 }
114
115 clean.dependsOn cleanNative
116}
117
118def getNdkBuildCmd() {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800119 def ndk_build = getNdkDir() + "/ndk-build"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800120 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
121 ndk_build += ".cmd"
122 }
123
124 return ndk_build
125}
126
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800127
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800128def getNdkDir() {
129 if (System.env.ANDROID_NDK_ROOT != null)
130 return System.env.ANDROID_NDK_ROOT
131
132 Properties properties = new Properties()
133 properties.load(project.rootProject.file('local.properties').newDataInputStream())
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800134
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800135 def ndk_dir = properties.getProperty('ndk.dir', null)
136 if (ndk_dir == null) {
137 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.")
138 }
139 return ndk_dir
140}
141
Alexander Afanasyev03177422015-03-11 13:38:05 -0700142repositories {
143 mavenLocal()
144 mavenCentral()
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800145 maven {
146 url "https://oss.sonatype.org/content/repositories/snapshots/"
147 }
Alexander Afanasyev03177422015-03-11 13:38:05 -0700148}
149
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800150dependencies {
Alexander Afanasyevda066292017-11-12 23:02:31 -0500151 implementation fileTree(dir: 'libs', include: ['*.jar'])
152 implementation 'com.android.support:appcompat-v7:26.1.0'
153 implementation 'com.android.support:support-v4:26.1.0'
Haitao Zhang129388e2017-03-31 16:07:36 -0700154 implementation 'com.android.volley:volley:1.0.0'
Alexander Afanasyev03177422015-03-11 13:38:05 -0700155
Alexander Afanasyevda066292017-11-12 23:02:31 -0500156 implementation('com.intel.jndn.management:jndn-management:1.1.3') {
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800157 exclude group: 'net.named-data', module: 'jndn'
158 }
Alexander Afanasyevda066292017-11-12 23:02:31 -0500159 implementation('net.named-data:jndn-android:0.15') {
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700160 exclude group: 'org.xerial'
Alexander Afanasyevda066292017-11-12 23:02:31 -0500161 exclude group: 'com.google.android'
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700162 }
Alexander Afanasyevda066292017-11-12 23:02:31 -0500163 implementation 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
164 implementation 'joda-time:joda-time:2.9.9'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800165}
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800166
167Properties properties = new Properties()
168properties.load(project.rootProject.file('local.properties').newDataInputStream())
169
170if (properties['keystore'] == null || properties['keystore.password'] == null ||
171 properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) {
172 println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.")
173}
174else {
175 android {
176 signingConfigs {
177 release {
178 storeFile file(properties['keystore'])
179 storePassword properties['keystore.password']
180 keyAlias properties['keystore.key.alias']
181 keyPassword properties['keystore.key.password']
182 }
183 }
184 buildTypes {
185 release {
186 signingConfig signingConfigs.release
187 }
188 }
189 }
190}
191
192if (properties['google-play'] != null) {
Alexander Afanasyev0e164652017-12-07 17:32:05 -0500193 // apply plugin: 'net.named-data.playground.play'
194 apply plugin: 'com.github.triplet.play'
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800195
196 play {
197 track = 'alpha'
198 jsonFile = file(properties['google-play'])
199 }
200}