blob: 5d276d47281be7a53637fd52fe1f400b60cbd9c0 [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 Afanasyev14fd3e22018-07-04 14:20:53 -04006 compileSdkVersion 28
Alexander Afanasyevddaa8312015-01-27 16:33:45 -08007
8 defaultConfig {
9 applicationId "net.named_data.nfd"
Alexander Afanasyevda066292017-11-12 23:02:31 -050010 minSdkVersion 23
Alexander Afanasyev471bbff2019-03-09 11:35:04 -080011 targetSdkVersion 27
Alexander Afanasyeva5576252019-05-02 16:56:40 -040012 versionCode 4013
13 versionName "0.6.6-1 (NFD 0.6.6)"
Alexander Afanasyevda066292017-11-12 23:02:31 -050014 multiDexEnabled true
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080015 }
Alexander Afanasyev03177422015-03-11 13:38:05 -070016 compileOptions {
Alexander Afanasyev4a20a882017-12-07 17:44:07 -050017 sourceCompatibility JavaVersion.VERSION_1_8
18 targetCompatibility JavaVersion.VERSION_1_8
Alexander Afanasyev03177422015-03-11 13:38:05 -070019 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080020 buildTypes {
21 release {
Alexander Afanasyevda066292017-11-12 23:02:31 -050022 minifyEnabled true
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080023 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080025 debug {
26 debuggable true
27 jniDebuggable true
28 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080029 }
30 sourceSets {
31 main {
32 java.srcDirs "src/main/java"
33 res.srcDirs "src/main/res"
34 jniLibs.srcDir 'src/main/libs'
35 jni.srcDirs = [] //disable automatic ndk-build call
36 }
37 androidTest.setRoot('tests')
38 androidTest.java.srcDirs = ['tests/src']
39 }
Alexander Afanasyev2a78ac62015-03-15 14:02:34 -070040 packagingOptions {
41 exclude 'META-INF/LICENSE.txt'
42 exclude 'META-INF/NOTICE.txt'
43 }
Alexander Afanasyevda066292017-11-12 23:02:31 -050044 lintOptions {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -080045 abortOnError false
Alexander Afanasyevda066292017-11-12 23:02:31 -050046 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080047
48 splits {
49 abi {
50 enable true // enable ABI split feature to create one APK per ABI
Alexander Afanasyev0e164652017-12-07 17:32:05 -050051 reset()
52 include "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080053 universalApk false // don't generate an additional APK that targets all the ABIs
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080054 }
55 }
56
57 // map for the version code
58 // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
Alexander Afanasyevda066292017-11-12 23:02:31 -050059 project.ext.versionCodes = [//'armeabi': 1, // Deprecated in r16. Will be removed in r17. No hard float.
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080060 'armeabi-v7a': 2,
61 'arm64-v8a': 3,
Alexander Afanasyevda066292017-11-12 23:02:31 -050062 // '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.
63 // 'mips64': 6, // Deprecated in r16. WIll be removed in r17
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080064 'x86': 8,
65 'x86_64': 9]
66
67 android.applicationVariants.all { variant ->
68 // assign different version code for each output
69 variant.outputs.each { output ->
70 output.versionCodeOverride = project.ext.versionCodes.get(
71 output.getFilter(
72 com.android.build.OutputFile.ABI), 0) * 1000000 +
73 defaultConfig.versionCode
74 }
75 }
76
Alexander Afanasyev93886942016-02-09 16:00:24 -080077 task copyNdnCxxHeaders(type: Copy) {
78 from('src/main/jni/ndn-cxx/src') {
79 include '**/*.hpp'
80 }
81 into 'build/generated/source/include/ndn-cxx'
82 }
83
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080084 // call regular ndk-build(.cmd) script from app directory
85 task ndkBuild(type: Exec) {
Alexander Afanasyev93886942016-02-09 16:00:24 -080086 dependsOn copyNdnCxxHeaders
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080087 def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]
88
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080089 if (System.env.NDK_BUILD_PARALLEL != null) {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -080090 args.add("-j" + System.env.NDK_BUILD_PARALLEL)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080091 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080092 else {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -080093 args.add("-j" + Runtime.runtime.availableProcessors())
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080094 }
95
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080096 if (System.env.NDK_BUILD_ABI != null) {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -080097 args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080098 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080099
100 if (System.env.NDK_DEBUG != null) {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -0800101 args.add("V=1")
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -0800102 }
103 commandLine args
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800104 }
105
106 tasks.withType(JavaCompile) {
107 compileTask -> compileTask.dependsOn ndkBuild
108 }
109
110 task cleanNative(type: Exec) {
111 commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
112 }
113
114 clean.dependsOn cleanNative
115}
116
117def getNdkBuildCmd() {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800118 def ndk_build = getNdkDir() + "/ndk-build"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800119 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
120 ndk_build += ".cmd"
121 }
122
123 return ndk_build
124}
125
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800126
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800127def getNdkDir() {
128 if (System.env.ANDROID_NDK_ROOT != null)
129 return System.env.ANDROID_NDK_ROOT
130
131 Properties properties = new Properties()
132 properties.load(project.rootProject.file('local.properties').newDataInputStream())
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800133
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800134 def ndk_dir = properties.getProperty('ndk.dir', null)
135 if (ndk_dir == null) {
136 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.")
137 }
138 return ndk_dir
139}
140
Alexander Afanasyev03177422015-03-11 13:38:05 -0700141repositories {
142 mavenLocal()
143 mavenCentral()
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800144 maven {
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400145 url "https://oss.sonatype.org/content/repositories/releases/"
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800146 }
Alexander Afanasyev03177422015-03-11 13:38:05 -0700147}
148
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800149dependencies {
Alexander Afanasyevda066292017-11-12 23:02:31 -0500150 implementation fileTree(dir: 'libs', include: ['*.jar'])
Alexander Afanasyev5005fc52019-03-09 17:50:15 -0800151 implementation('com.google.android.material:material:1.1.0-alpha04') {
152 exclude group: 'com.google.guava', module: 'listenablefuture'
153 }
154 implementation('androidx.appcompat:appcompat:1.0.2') {
155 exclude group: 'com.google.guava', module: 'listenablefuture'
156 }
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400157 implementation 'com.android.volley:volley:1.1.1'
Alexander Afanasyev03177422015-03-11 13:38:05 -0700158
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400159 implementation('net.named-data.jndn-extra:jndn-management:1.2.0') {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -0800160 exclude group: 'net.named-data', module: 'jndn'
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800161 }
Alexander Afanasyev63e81f92019-02-05 13:30:26 -0500162 implementation('net.named-data:jndn-android:0.20') {
Alexander Afanasyev5005fc52019-03-09 17:50:15 -0800163 exclude group: 'org.xerial'
164 exclude group: 'com.google.android'
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700165 }
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400166 implementation 'net.named-data.jndn-extra:jndn-xx-util:0.0.2'
167 implementation 'joda-time:joda-time:2.10'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800168}
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800169
170Properties properties = new Properties()
171properties.load(project.rootProject.file('local.properties').newDataInputStream())
172
173if (properties['keystore'] == null || properties['keystore.password'] == null ||
Alexander Afanasyev5005fc52019-03-09 17:50:15 -0800174 properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) {
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800175 println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.")
176}
177else {
178 android {
179 signingConfigs {
180 release {
181 storeFile file(properties['keystore'])
182 storePassword properties['keystore.password']
183 keyAlias properties['keystore.key.alias']
184 keyPassword properties['keystore.key.password']
185 }
186 }
187 buildTypes {
188 release {
189 signingConfig signingConfigs.release
190 }
191 }
192 }
193}
194
195if (properties['google-play'] != null) {
Alexander Afanasyev0e164652017-12-07 17:32:05 -0500196 // apply plugin: 'net.named-data.playground.play'
197 apply plugin: 'com.github.triplet.play'
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800198
199 play {
200 track = 'alpha'
201 jsonFile = file(properties['google-play'])
202 }
203}