blob: a18648dcce362d2c534ba39075d6ba4890babef3 [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 {
Ivan Yeo215fc2a2015-03-17 22:35:04 -07006 compileSdkVersion 21
Alexander Afanasyevddaa8312015-01-27 16:33:45 -08007 buildToolsVersion "21.1.2"
8
9 defaultConfig {
10 applicationId "net.named_data.nfd"
Ivan Yeo432488f2015-02-02 19:35:23 -080011 minSdkVersion 15
12 targetSdkVersion 19
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080013 versionCode 3005
14 versionName "0.3.4"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080015 }
Alexander Afanasyev03177422015-03-11 13:38:05 -070016 compileOptions {
17 sourceCompatibility JavaVersion.VERSION_1_7
18 targetCompatibility JavaVersion.VERSION_1_7
19 }
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080020 buildTypes {
21 release {
22 minifyEnabled false
23 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 Afanasyevddaa8312015-01-27 16:33:45 -080044
45 splits {
46 abi {
47 enable true // enable ABI split feature to create one APK per ABI
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -080048 universalApk false // don't generate an additional APK that targets all the ABIs
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080049 }
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 Afanasyev3d62ddd2015-02-12 16:59:52 -080074 def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]
75
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080076 if (System.env.NDK_BUILD_PARALLEL != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080077 args.add("-j" + System.env.NDK_BUILD_PARALLEL)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080078 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080079 else {
80 args.add("-j" + Runtime.runtime.availableProcessors())
81 }
82
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080083 if (System.env.NDK_BUILD_ABI != null) {
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080084 args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
Alexander Afanasyev087c7c12015-02-02 00:21:21 -080085 }
Alexander Afanasyev3d62ddd2015-02-12 16:59:52 -080086
87 if (System.env.NDK_DEBUG != null) {
88 args.add("NDK_DEBUG=1")
89 }
90 commandLine args
Alexander Afanasyevddaa8312015-01-27 16:33:45 -080091 }
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
104def getNdkBuildCmd() {
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800105 def ndk_build = getNdkDir() + "/ndk-build"
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800106 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
107 ndk_build += ".cmd"
108 }
109
110 return ndk_build
111}
112
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800113
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800114def 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 Afanasyevbd74ad22016-01-06 18:09:10 -0800120
Alexander Afanasyev087c7c12015-02-02 00:21:21 -0800121 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 Afanasyev03177422015-03-11 13:38:05 -0700128repositories {
129 mavenLocal()
130 mavenCentral()
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800131 maven {
132 url "https://oss.sonatype.org/content/repositories/snapshots/"
133 }
Alexander Afanasyev03177422015-03-11 13:38:05 -0700134}
135
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800136dependencies {
137 compile fileTree(dir: 'libs', include: ['*.jar'])
Ivan Yeo215fc2a2015-03-17 22:35:04 -0700138 compile 'com.android.support:appcompat-v7:21.0.3'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800139 compile 'com.android.support:support-v4:21.0.3'
Alexander Afanasyev03177422015-03-11 13:38:05 -0700140
Alexander Afanasyev0a15b6d2016-01-31 12:13:28 -0800141 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 Afanasyevf7b62362015-09-10 23:29:47 -0700145 exclude group: 'org.xerial'
146 }
147 compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
Alexander Afanasyev03177422015-03-11 13:38:05 -0700148 compile 'joda-time:joda-time:2.7'
Alexander Afanasyevddaa8312015-01-27 16:33:45 -0800149}
Alexander Afanasyevbd74ad22016-01-06 18:09:10 -0800150
151Properties properties = new Properties()
152properties.load(project.rootProject.file('local.properties').newDataInputStream())
153
154if (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}
158else {
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
176if (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}