Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 1 | import org.apache.tools.ant.taskdefs.condition.Os |
| 2 | |
| 3 | apply plugin: 'com.android.application' |
| 4 | |
| 5 | android { |
Alexander Afanasyev | b72e144 | 2017-07-10 13:10:11 -0700 | [diff] [blame] | 6 | compileSdkVersion 26 |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 7 | buildToolsVersion "26.0.3" |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 8 | |
| 9 | defaultConfig { |
| 10 | applicationId "net.named_data.nfd" |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 11 | minSdkVersion 23 |
| 12 | targetSdkVersion 23 |
Alexander Afanasyev | 0e16465 | 2017-12-07 17:32:05 -0500 | [diff] [blame] | 13 | versionCode 4007 |
Alexander Afanasyev | 79a0fff | 2017-12-05 12:45:14 -0500 | [diff] [blame] | 14 | versionName "0.3.0 (NFD 0.6.0, ndn-cxx 0.6.0)" |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 15 | multiDexEnabled true |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 16 | } |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 17 | compileOptions { |
Alexander Afanasyev | 4a20a88 | 2017-12-07 17:44:07 -0500 | [diff] [blame^] | 18 | sourceCompatibility JavaVersion.VERSION_1_8 |
| 19 | targetCompatibility JavaVersion.VERSION_1_8 |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 20 | } |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 21 | buildTypes { |
| 22 | release { |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 23 | minifyEnabled true |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 25 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 26 | debug { |
| 27 | debuggable true |
| 28 | jniDebuggable true |
| 29 | } |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 30 | } |
| 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 Afanasyev | 2a78ac6 | 2015-03-15 14:02:34 -0700 | [diff] [blame] | 41 | packagingOptions { |
| 42 | exclude 'META-INF/LICENSE.txt' |
| 43 | exclude 'META-INF/NOTICE.txt' |
| 44 | } |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 45 | lintOptions { |
| 46 | abortOnError false |
| 47 | } |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 48 | |
| 49 | splits { |
| 50 | abi { |
| 51 | enable true // enable ABI split feature to create one APK per ABI |
Alexander Afanasyev | 0e16465 | 2017-12-07 17:32:05 -0500 | [diff] [blame] | 52 | reset() |
| 53 | include "armeabi-v7a", "arm64-v8a", "x86", "x86_64" |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 54 | universalApk false // don't generate an additional APK that targets all the ABIs |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
| 58 | // map for the version code |
| 59 | // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-* |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 60 | project.ext.versionCodes = [//'armeabi': 1, // Deprecated in r16. Will be removed in r17. No hard float. |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 61 | 'armeabi-v7a': 2, |
| 62 | 'arm64-v8a': 3, |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 63 | // '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 Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 65 | '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 Afanasyev | 9388694 | 2016-02-09 16:00:24 -0800 | [diff] [blame] | 78 | 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 Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 85 | // call regular ndk-build(.cmd) script from app directory |
| 86 | task ndkBuild(type: Exec) { |
Alexander Afanasyev | 9388694 | 2016-02-09 16:00:24 -0800 | [diff] [blame] | 87 | dependsOn copyNdnCxxHeaders |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 88 | def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath] |
| 89 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 90 | if (System.env.NDK_BUILD_PARALLEL != null) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 91 | args.add("-j" + System.env.NDK_BUILD_PARALLEL) |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 92 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 93 | else { |
| 94 | args.add("-j" + Runtime.runtime.availableProcessors()) |
| 95 | } |
| 96 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 97 | if (System.env.NDK_BUILD_ABI != null) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 98 | args.add("APP_ABI=" + System.env.NDK_BUILD_ABI) |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 99 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 100 | |
| 101 | if (System.env.NDK_DEBUG != null) { |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 102 | args.add("V=1") |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 103 | } |
| 104 | commandLine args |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 105 | } |
| 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 | |
| 118 | def getNdkBuildCmd() { |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 119 | def ndk_build = getNdkDir() + "/ndk-build" |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 120 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 121 | ndk_build += ".cmd" |
| 122 | } |
| 123 | |
| 124 | return ndk_build |
| 125 | } |
| 126 | |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 128 | def 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 Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 134 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 135 | 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 Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 142 | repositories { |
| 143 | mavenLocal() |
| 144 | mavenCentral() |
Alexander Afanasyev | 0a15b6d | 2016-01-31 12:13:28 -0800 | [diff] [blame] | 145 | maven { |
| 146 | url "https://oss.sonatype.org/content/repositories/snapshots/" |
| 147 | } |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 150 | dependencies { |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 151 | 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 Zhang | 129388e | 2017-03-31 16:07:36 -0700 | [diff] [blame] | 154 | implementation 'com.android.volley:volley:1.0.0' |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 155 | |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 156 | implementation('com.intel.jndn.management:jndn-management:1.1.3') { |
Alexander Afanasyev | 0a15b6d | 2016-01-31 12:13:28 -0800 | [diff] [blame] | 157 | exclude group: 'net.named-data', module: 'jndn' |
| 158 | } |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 159 | implementation('net.named-data:jndn-android:0.15') { |
Alexander Afanasyev | f7b6236 | 2015-09-10 23:29:47 -0700 | [diff] [blame] | 160 | exclude group: 'org.xerial' |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 161 | exclude group: 'com.google.android' |
Alexander Afanasyev | f7b6236 | 2015-09-10 23:29:47 -0700 | [diff] [blame] | 162 | } |
Alexander Afanasyev | da06629 | 2017-11-12 23:02:31 -0500 | [diff] [blame] | 163 | implementation 'net.named-data.jndn-xx:jndn-xx-util:0.0.1' |
| 164 | implementation 'joda-time:joda-time:2.9.9' |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 165 | } |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 166 | |
| 167 | Properties properties = new Properties() |
| 168 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 169 | |
| 170 | if (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 | } |
| 174 | else { |
| 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 | |
| 192 | if (properties['google-play'] != null) { |
Alexander Afanasyev | 0e16465 | 2017-12-07 17:32:05 -0500 | [diff] [blame] | 193 | // apply plugin: 'net.named-data.playground.play' |
| 194 | apply plugin: 'com.github.triplet.play' |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 195 | |
| 196 | play { |
| 197 | track = 'alpha' |
| 198 | jsonFile = file(properties['google-play']) |
| 199 | } |
| 200 | } |