blob: ab3ebab9a4657e7ec91df0ccb2ac036bf0acedd6 [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 Afanasyev79a0fff2017-12-05 12:45:14 -050013 versionCode 4006
14 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 {
18 sourceCompatibility JavaVersion.VERSION_1_7
19 targetCompatibility JavaVersion.VERSION_1_7
20 }
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 Afanasyevbd74ad22016-01-06 18:09:10 -080052 universalApk false // don't generate an additional APK that targets all the ABIs
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080053 }
54 }
55
56 // map for the version code
57 // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
Alexander Afanasyevda066292017-11-12 23:02:31 -050058 project.ext.versionCodes = [//'armeabi': 1, // Deprecated in r16. Will be removed in r17. No hard float.
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080059 'armeabi-v7a': 2,
60 'arm64-v8a': 3,
Alexander Afanasyevda066292017-11-12 23:02:31 -050061 // '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.
62 // 'mips64': 6, // Deprecated in r16. WIll be removed in r17
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080063 'x86': 8,
64 'x86_64': 9]
65
66 android.applicationVariants.all { variant ->
67 // assign different version code for each output
68 variant.outputs.each { output ->
69 output.versionCodeOverride = project.ext.versionCodes.get(
70 output.getFilter(
71 com.android.build.OutputFile.ABI), 0) * 1000000 +
72 defaultConfig.versionCode
73 }
74 }
75
Alexander Afanasyev93886942016-02-09 16:00:24 -080076 task copyNdnCxxHeaders(type: Copy) {
77 from('src/main/jni/ndn-cxx/src') {
78 include '**/*.hpp'
79 }
80 into 'build/generated/source/include/ndn-cxx'
81 }
82
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080083 // call regular ndk-build(.cmd) script from app directory
84 task ndkBuild(type: Exec) {
Alexander Afanasyev93886942016-02-09 16:00:24 -080085 dependsOn copyNdnCxxHeaders
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080086 def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]
87
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080088 if (System.env.NDK_BUILD_PARALLEL != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080089 args.add("-j" + System.env.NDK_BUILD_PARALLEL)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080090 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080091 else {
92 args.add("-j" + Runtime.runtime.availableProcessors())
93 }
94
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080095 if (System.env.NDK_BUILD_ABI != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080096 args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080097 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080098
99 if (System.env.NDK_DEBUG != null) {
Alexander Afanasyevda066292017-11-12 23:02:31 -0500100 args.add("V=1")
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -0800101 }
102 commandLine args
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800103 }
104
105 tasks.withType(JavaCompile) {
106 compileTask -> compileTask.dependsOn ndkBuild
107 }
108
109 task cleanNative(type: Exec) {
110 commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
111 }
112
113 clean.dependsOn cleanNative
114}
115
116def getNdkBuildCmd() {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800117 def ndk_build = getNdkDir() + "/ndk-build"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800118 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
119 ndk_build += ".cmd"
120 }
121
122 return ndk_build
123}
124
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800125
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800126def getNdkDir() {
127 if (System.env.ANDROID_NDK_ROOT != null)
128 return System.env.ANDROID_NDK_ROOT
129
130 Properties properties = new Properties()
131 properties.load(project.rootProject.file('local.properties').newDataInputStream())
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800132
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800133 def ndk_dir = properties.getProperty('ndk.dir', null)
134 if (ndk_dir == null) {
135 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.")
136 }
137 return ndk_dir
138}
139
Alexander Afanasyev03177422015-03-11 13:38:05 -0700140repositories {
141 mavenLocal()
142 mavenCentral()
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800143 maven {
144 url "https://oss.sonatype.org/content/repositories/snapshots/"
145 }
Alexander Afanasyev03177422015-03-11 13:38:05 -0700146}
147
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800148dependencies {
Alexander Afanasyevda066292017-11-12 23:02:31 -0500149 implementation fileTree(dir: 'libs', include: ['*.jar'])
150 implementation 'com.android.support:appcompat-v7:26.1.0'
151 implementation 'com.android.support:support-v4:26.1.0'
Haitao Zhang129388e2017-03-31 16:07:36 -0700152 implementation 'com.android.volley:volley:1.0.0'
Alexander Afanasyev03177422015-03-11 13:38:05 -0700153
Alexander Afanasyevda066292017-11-12 23:02:31 -0500154 implementation('com.intel.jndn.management:jndn-management:1.1.3') {
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800155 exclude group: 'net.named-data', module: 'jndn'
156 }
Alexander Afanasyevda066292017-11-12 23:02:31 -0500157 implementation('net.named-data:jndn-android:0.15') {
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700158 exclude group: 'org.xerial'
Alexander Afanasyevda066292017-11-12 23:02:31 -0500159 exclude group: 'com.google.android'
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700160 }
Alexander Afanasyevda066292017-11-12 23:02:31 -0500161 implementation 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
162 implementation 'joda-time:joda-time:2.9.9'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800163}
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800164
165Properties properties = new Properties()
166properties.load(project.rootProject.file('local.properties').newDataInputStream())
167
168if (properties['keystore'] == null || properties['keystore.password'] == null ||
169 properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) {
170 println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.")
171}
172else {
173 android {
174 signingConfigs {
175 release {
176 storeFile file(properties['keystore'])
177 storePassword properties['keystore.password']
178 keyAlias properties['keystore.key.alias']
179 keyPassword properties['keystore.key.password']
180 }
181 }
182 buildTypes {
183 release {
184 signingConfig signingConfigs.release
185 }
186 }
187 }
188}
189
190if (properties['google-play'] != null) {
191 apply plugin: 'net.named-data.playground.play'
192
193 play {
194 track = 'alpha'
195 jsonFile = file(properties['google-play'])
196 }
197}