blob: dadd233c15cd55d9ea7e603c2325f9a523ccb255 [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 Afanasyev27f43392018-07-27 16:18:50 -040011 targetSdkVersion 26
12 versionCode 4009
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -040013 versionName "0.6.2-1 (NFD 0.6.2-11-gd657d53)"
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 {
45 abortOnError false
46 }
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 Afanasyev3d62ddd2015-02-12 16:59:52 -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 {
93 args.add("-j" + Runtime.runtime.availableProcessors())
94 }
95
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080096 if (System.env.NDK_BUILD_ABI != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -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 Afanasyevda066292017-11-12 23:02:31 -0500101 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 Afanasyev14fd3e22018-07-04 14:20:53 -0400151 implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
152 implementation 'com.android.support:support-v4:28.0.0-alpha3'
153 implementation 'com.android.volley:volley:1.1.1'
Alexander Afanasyev03177422015-03-11 13:38:05 -0700154
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400155 implementation('net.named-data.jndn-extra:jndn-management:1.2.0') {
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800156 exclude group: 'net.named-data', module: 'jndn'
157 }
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400158 implementation('net.named-data:jndn-android:0.17') {
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700159 exclude group: 'org.xerial'
Alexander Afanasyevda066292017-11-12 23:02:31 -0500160 exclude group: 'com.google.android'
Alexander Afanasyevf7b62362015-09-10 23:29:47 -0700161 }
Alexander Afanasyev14fd3e22018-07-04 14:20:53 -0400162 implementation 'net.named-data.jndn-extra:jndn-xx-util:0.0.2'
163 implementation 'joda-time:joda-time:2.10'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800164}
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800165
166Properties properties = new Properties()
167properties.load(project.rootProject.file('local.properties').newDataInputStream())
168
169if (properties['keystore'] == null || properties['keystore.password'] == null ||
170 properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) {
171 println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.")
172}
173else {
174 android {
175 signingConfigs {
176 release {
177 storeFile file(properties['keystore'])
178 storePassword properties['keystore.password']
179 keyAlias properties['keystore.key.alias']
180 keyPassword properties['keystore.key.password']
181 }
182 }
183 buildTypes {
184 release {
185 signingConfig signingConfigs.release
186 }
187 }
188 }
189}
190
191if (properties['google-play'] != null) {
Alexander Afanasyev0e164652017-12-07 17:32:05 -0500192 // apply plugin: 'net.named-data.playground.play'
193 apply plugin: 'com.github.triplet.play'
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800194
195 play {
196 track = 'alpha'
197 jsonFile = file(properties['google-play'])
198 }
199}