aboutsummaryrefslogtreecommitdiffstats
path: root/iget_android/app/build.gradle
blob: 13321fc08f8a390f45ebc524644907139a659baa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.iget.ccnx"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "0.0.1 ( 0.0.1)"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    signingConfigs {
        release {
            storeFile file("iget.keystore")
            storePassword "icn_iget"
            keyAlias "iget"
            keyPassword "icn_iget"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationVariants.all { variant ->
            	variant.outputs.each { output ->
                	project.ext { appName = 'iget' }
                	def newName = output.outputFile.name
                	newName = newName.replace("app", "$project.ext.appName-$System.env.ABI")
                	output.outputFile = new File(output.outputFile.parent, newName)
            	}
        	}
	    	signingConfig signingConfigs.release
        }
        debug {
            debuggable true
            jniDebuggable true
        }
    }
    sourceSets {
        main {
            java.srcDirs "src/main/java"
            res.srcDirs "src/main/res"
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = [] //disable automatic ndk-build call
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    splits {
        abi {
            enable true // enable ABI split feature to create one APK per ABI
            universalApk false // don't generate an additional APK that targets all the ABIs
            reset()
            include 'armeabi-v7a'
        }
    }

    // map for the version code
    // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
    project.ext.versionCodes = ['armeabi': 1,
                                'armeabi-v7a': 2,
                                'arm64-v8a': 3,
                                'mips': 5,
                                'mips64': 6,
                                'x86': 8,
                                'x86_64': 9]

    android.applicationVariants.all { variant ->
        // assign different version code for each output
        variant.outputs.each { output ->
            output.versionCodeOverride = project.ext.versionCodes.get(
                    output.getFilter(
                            com.android.build.OutputFile.ABI), 0) * 1000000 +
                    defaultConfig.versionCode
        }
    }

    task copyNdnCxxHeaders(type: Copy) {
        from('src/main/jni/ndn-cxx/src') {
            include '**/*.hpp'
        }
        into 'build/generated/source/include/ndn-cxx'
    }

    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        dependsOn copyNdnCxxHeaders
        def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]

        if (System.env.NDK_BUILD_PARALLEL != null) {
           args.add("-j" + System.env.NDK_BUILD_PARALLEL)
        }
        else {
           args.add("-j" + Runtime.runtime.availableProcessors())
        }

        if (System.env.NDK_BUILD_ABI != null) {
           args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
        }

        if (System.env.NDK_DEBUG != null) {
           args.add("NDK_DEBUG=1")
        }
        commandLine args
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    task cleanNative(type: Exec) {
        commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
    }

    clean.dependsOn cleanNative
    //dexOptions {
     //   incremental true
    //}
    dexOptions {
        incremental true
    }
}

def getNdkBuildCmd() {
    def ndk_build = getNdkDir() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndk_build += ".cmd"
    }

    return ndk_build
}


def getNdkDir() {
    if (System.env.ANDROID_NDK_ROOT != null)
        return System.env.ANDROID_NDK_ROOT

    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())

    def ndk_dir = properties.getProperty('ndk.dir', null)
    if (ndk_dir == null) {
        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.")
    }
    return ndk_dir
}

repositories {
    mavenLocal()
    mavenCentral()
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile('com.intel.jndn.management:jndn-management:1.1.2') {
        exclude group: 'net.named-data', module: 'jndn'
    }
    compile('net.named-data:jndn-android:0.13') {
        exclude group: 'org.xerial'
    }
    compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
    compile 'joda-time:joda-time:2.7'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())


if (properties['google-play'] != null) {
    apply plugin: 'net.named-data.playground.play'

    play {
        track = 'alpha'
        jsonFile = file(properties['google-play'])
    }
}