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 | a409156 | 2016-02-23 11:51:31 -0800 | [diff] [blame] | 6 | compileSdkVersion 23 |
| 7 | buildToolsVersion "23.0.2" |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 8 | |
| 9 | defaultConfig { |
| 10 | applicationId "net.named_data.nfd" |
Ivan Yeo | 432488f | 2015-02-02 19:35:23 -0800 | [diff] [blame] | 11 | minSdkVersion 15 |
| 12 | targetSdkVersion 19 |
Alexander Afanasyev | 7545e95 | 2016-01-31 12:53:27 -0800 | [diff] [blame] | 13 | versionCode 4001 |
| 14 | versionName "0.2.1 (NFD 0.4.0-3-g4100646)" |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 15 | } |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 16 | compileOptions { |
| 17 | sourceCompatibility JavaVersion.VERSION_1_7 |
| 18 | targetCompatibility JavaVersion.VERSION_1_7 |
| 19 | } |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 20 | buildTypes { |
| 21 | release { |
| 22 | minifyEnabled false |
| 23 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
| 24 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 25 | debug { |
| 26 | debuggable true |
| 27 | jniDebuggable true |
| 28 | } |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 29 | } |
| 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 Afanasyev | 2a78ac6 | 2015-03-15 14:02:34 -0700 | [diff] [blame] | 40 | packagingOptions { |
| 41 | exclude 'META-INF/LICENSE.txt' |
| 42 | exclude 'META-INF/NOTICE.txt' |
| 43 | } |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 44 | |
| 45 | splits { |
| 46 | abi { |
| 47 | enable true // enable ABI split feature to create one APK per ABI |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 48 | 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] | 49 | } |
| 50 | } |
| 51 | |
| 52 | // map for the version code |
| 53 | // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-* |
| 54 | project.ext.versionCodes = ['armeabi': 1, |
| 55 | 'armeabi-v7a': 2, |
| 56 | 'arm64-v8a': 3, |
| 57 | 'mips': 5, |
| 58 | 'mips64': 6, |
| 59 | 'x86': 8, |
| 60 | 'x86_64': 9] |
| 61 | |
| 62 | android.applicationVariants.all { variant -> |
| 63 | // assign different version code for each output |
| 64 | variant.outputs.each { output -> |
| 65 | output.versionCodeOverride = project.ext.versionCodes.get( |
| 66 | output.getFilter( |
| 67 | com.android.build.OutputFile.ABI), 0) * 1000000 + |
| 68 | defaultConfig.versionCode |
| 69 | } |
| 70 | } |
| 71 | |
Alexander Afanasyev | 9388694 | 2016-02-09 16:00:24 -0800 | [diff] [blame] | 72 | task copyNdnCxxHeaders(type: Copy) { |
| 73 | from('src/main/jni/ndn-cxx/src') { |
| 74 | include '**/*.hpp' |
| 75 | } |
| 76 | into 'build/generated/source/include/ndn-cxx' |
| 77 | } |
| 78 | |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 79 | // call regular ndk-build(.cmd) script from app directory |
| 80 | task ndkBuild(type: Exec) { |
Alexander Afanasyev | 9388694 | 2016-02-09 16:00:24 -0800 | [diff] [blame] | 81 | dependsOn copyNdnCxxHeaders |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 82 | def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath] |
| 83 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 84 | if (System.env.NDK_BUILD_PARALLEL != null) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 85 | args.add("-j" + System.env.NDK_BUILD_PARALLEL) |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 86 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 87 | else { |
| 88 | args.add("-j" + Runtime.runtime.availableProcessors()) |
| 89 | } |
| 90 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 91 | if (System.env.NDK_BUILD_ABI != null) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 92 | args.add("APP_ABI=" + System.env.NDK_BUILD_ABI) |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 93 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 94 | |
| 95 | if (System.env.NDK_DEBUG != null) { |
| 96 | args.add("NDK_DEBUG=1") |
| 97 | } |
| 98 | commandLine args |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | tasks.withType(JavaCompile) { |
| 102 | compileTask -> compileTask.dependsOn ndkBuild |
| 103 | } |
| 104 | |
| 105 | task cleanNative(type: Exec) { |
| 106 | commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean' |
| 107 | } |
| 108 | |
| 109 | clean.dependsOn cleanNative |
| 110 | } |
| 111 | |
| 112 | def getNdkBuildCmd() { |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 113 | def ndk_build = getNdkDir() + "/ndk-build" |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 114 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 115 | ndk_build += ".cmd" |
| 116 | } |
| 117 | |
| 118 | return ndk_build |
| 119 | } |
| 120 | |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 121 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 122 | def getNdkDir() { |
| 123 | if (System.env.ANDROID_NDK_ROOT != null) |
| 124 | return System.env.ANDROID_NDK_ROOT |
| 125 | |
| 126 | Properties properties = new Properties() |
| 127 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 128 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 129 | def ndk_dir = properties.getProperty('ndk.dir', null) |
| 130 | if (ndk_dir == null) { |
| 131 | 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.") |
| 132 | } |
| 133 | return ndk_dir |
| 134 | } |
| 135 | |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 136 | repositories { |
| 137 | mavenLocal() |
| 138 | mavenCentral() |
Alexander Afanasyev | 0a15b6d | 2016-01-31 12:13:28 -0800 | [diff] [blame] | 139 | maven { |
| 140 | url "https://oss.sonatype.org/content/repositories/snapshots/" |
| 141 | } |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 144 | dependencies { |
| 145 | compile fileTree(dir: 'libs', include: ['*.jar']) |
Alexander Afanasyev | a409156 | 2016-02-23 11:51:31 -0800 | [diff] [blame] | 146 | compile 'com.android.support:appcompat-v7:23.1.1' |
| 147 | compile 'com.android.support:support-v4:23.1.1' |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 148 | |
Alexander Afanasyev | 0a15b6d | 2016-01-31 12:13:28 -0800 | [diff] [blame] | 149 | compile('com.intel.jndn.management:jndn-management:1.1.0') { |
| 150 | exclude group: 'net.named-data', module: 'jndn' |
| 151 | } |
| 152 | compile('net.named-data:jndn-android:0.10') { |
Alexander Afanasyev | f7b6236 | 2015-09-10 23:29:47 -0700 | [diff] [blame] | 153 | exclude group: 'org.xerial' |
| 154 | } |
| 155 | compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1' |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 156 | compile 'joda-time:joda-time:2.7' |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 157 | } |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 158 | |
| 159 | Properties properties = new Properties() |
| 160 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 161 | |
| 162 | if (properties['keystore'] == null || properties['keystore.password'] == null || |
| 163 | properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) { |
| 164 | println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.") |
| 165 | } |
| 166 | else { |
| 167 | android { |
| 168 | signingConfigs { |
| 169 | release { |
| 170 | storeFile file(properties['keystore']) |
| 171 | storePassword properties['keystore.password'] |
| 172 | keyAlias properties['keystore.key.alias'] |
| 173 | keyPassword properties['keystore.key.password'] |
| 174 | } |
| 175 | } |
| 176 | buildTypes { |
| 177 | release { |
| 178 | signingConfig signingConfigs.release |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if (properties['google-play'] != null) { |
| 185 | apply plugin: 'net.named-data.playground.play' |
| 186 | |
| 187 | play { |
| 188 | track = 'alpha' |
| 189 | jsonFile = file(properties['google-play']) |
| 190 | } |
| 191 | } |