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 | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 13 | versionCode 3005 |
| 14 | versionName "0.3.4" |
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 | |
| 72 | // call regular ndk-build(.cmd) script from app directory |
| 73 | task ndkBuild(type: Exec) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 74 | def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath] |
| 75 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 76 | if (System.env.NDK_BUILD_PARALLEL != null) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 77 | args.add("-j" + System.env.NDK_BUILD_PARALLEL) |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 78 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 79 | else { |
| 80 | args.add("-j" + Runtime.runtime.availableProcessors()) |
| 81 | } |
| 82 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 83 | if (System.env.NDK_BUILD_ABI != null) { |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 84 | args.add("APP_ABI=" + System.env.NDK_BUILD_ABI) |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 85 | } |
Alexander Afanasyev | 3d62ddd | 2015-02-12 16:59:52 -0800 | [diff] [blame] | 86 | |
| 87 | if (System.env.NDK_DEBUG != null) { |
| 88 | args.add("NDK_DEBUG=1") |
| 89 | } |
| 90 | commandLine args |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | tasks.withType(JavaCompile) { |
| 94 | compileTask -> compileTask.dependsOn ndkBuild |
| 95 | } |
| 96 | |
| 97 | task cleanNative(type: Exec) { |
| 98 | commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean' |
| 99 | } |
| 100 | |
| 101 | clean.dependsOn cleanNative |
| 102 | } |
| 103 | |
| 104 | def getNdkBuildCmd() { |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 105 | def ndk_build = getNdkDir() + "/ndk-build" |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 106 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 107 | ndk_build += ".cmd" |
| 108 | } |
| 109 | |
| 110 | return ndk_build |
| 111 | } |
| 112 | |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 113 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 114 | def getNdkDir() { |
| 115 | if (System.env.ANDROID_NDK_ROOT != null) |
| 116 | return System.env.ANDROID_NDK_ROOT |
| 117 | |
| 118 | Properties properties = new Properties() |
| 119 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | 087c7c1 | 2015-02-02 00:21:21 -0800 | [diff] [blame] | 121 | def ndk_dir = properties.getProperty('ndk.dir', null) |
| 122 | if (ndk_dir == null) { |
| 123 | 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.") |
| 124 | } |
| 125 | return ndk_dir |
| 126 | } |
| 127 | |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 128 | repositories { |
| 129 | mavenLocal() |
| 130 | mavenCentral() |
Alexander Afanasyev | 0a15b6d | 2016-01-31 12:13:28 -0800 | [diff] [blame] | 131 | maven { |
| 132 | url "https://oss.sonatype.org/content/repositories/snapshots/" |
| 133 | } |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 136 | dependencies { |
| 137 | compile fileTree(dir: 'libs', include: ['*.jar']) |
Alexander Afanasyev | a409156 | 2016-02-23 11:51:31 -0800 | [diff] [blame^] | 138 | compile 'com.android.support:appcompat-v7:23.1.1' |
| 139 | compile 'com.android.support:support-v4:23.1.1' |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 140 | |
Alexander Afanasyev | 0a15b6d | 2016-01-31 12:13:28 -0800 | [diff] [blame] | 141 | compile('com.intel.jndn.management:jndn-management:1.1.0') { |
| 142 | exclude group: 'net.named-data', module: 'jndn' |
| 143 | } |
| 144 | compile('net.named-data:jndn-android:0.10') { |
Alexander Afanasyev | f7b6236 | 2015-09-10 23:29:47 -0700 | [diff] [blame] | 145 | exclude group: 'org.xerial' |
| 146 | } |
| 147 | compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1' |
Alexander Afanasyev | 0317742 | 2015-03-11 13:38:05 -0700 | [diff] [blame] | 148 | compile 'joda-time:joda-time:2.7' |
Alexander Afanasyev | ddaa831 | 2015-01-27 16:33:45 -0800 | [diff] [blame] | 149 | } |
Alexander Afanasyev | bd74ad2 | 2016-01-06 18:09:10 -0800 | [diff] [blame] | 150 | |
| 151 | Properties properties = new Properties() |
| 152 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) |
| 153 | |
| 154 | if (properties['keystore'] == null || properties['keystore.password'] == null || |
| 155 | properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) { |
| 156 | println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.") |
| 157 | } |
| 158 | else { |
| 159 | android { |
| 160 | signingConfigs { |
| 161 | release { |
| 162 | storeFile file(properties['keystore']) |
| 163 | storePassword properties['keystore.password'] |
| 164 | keyAlias properties['keystore.key.alias'] |
| 165 | keyPassword properties['keystore.key.password'] |
| 166 | } |
| 167 | } |
| 168 | buildTypes { |
| 169 | release { |
| 170 | signingConfig signingConfigs.release |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | if (properties['google-play'] != null) { |
| 177 | apply plugin: 'net.named-data.playground.play' |
| 178 | |
| 179 | play { |
| 180 | track = 'alpha' |
| 181 | jsonFile = file(properties['google-play']) |
| 182 | } |
| 183 | } |