aboutsummaryrefslogtreecommitdiffstats
path: root/main/build.gradle
blob: 06a36e88ce416fb47dd6802164829ea5b8f6e586 (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'findbugs'

/*
Before use unit test :
Replace all custom namepace with xmlns:cgeo="http://schemas.android.com/apk/res-auto"


Usage :

check dependencies :
gradle dependencies main:dependencies

build & test:
gradle clean assembleDebug connectedAndroidTest

debug:
gradle  connectedAndroidTest --debug --stacktrace

for CI? :
gradle deviceCheck
gradle connectedCheck

 */
//Testing guide : http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Testing
//https://github.com/stephanenicolas/Quality-Tools-for-Android

def AAVersion = '3.2'
def RXJavaVersion = '1.0.8'
def RXAndroidVersion = '0.24.0'
def JacksonCoreVersion = '2.5.1'
def JacksonDatabindVersion = '2.5.1'
def JacksonAnnotationsVersion = '2.5.1'
def CommonsCollections4Version = '4.0'
def CommonsLang3Version = '3.3.2'
def CommonsIoVersion = '2.4'
group = 'cgeo.geocaching'
version = '0.0.1'

android {
    //compileSdkVersion "Google Inc.:Google APIs:19"
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

     compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    def Properties versionProps = new Properties()
    versionProps.load(new FileInputStream(file('version.properties')))

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionName versionProps['name']
        versionCode versionProps['code'].toInteger()

        // NOTE: must match the package in the test directory and must be different from the app package
        testApplicationId "cgeo.geocaching.test"

        testInstrumentationRunner "cgeo.junit.CgeoTestRunner"

        //testHandlingProfiling true
        testFunctionalTest true
    }

    //Conditional signing
    //Uncomment and set the 4 key properties (#key.store, ...) in gradle.properties
    signingConfigs {
        release 
    }


    buildTypes {
        debug {
            //packageNameSuffix ".debug"
            //zipAlign = true
            debuggable true
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            versionNameSuffix " Debug " + versionProps['betaNumber']
        }
        release {
            debuggable true
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
            signingConfig signingConfigs.release
        }
    }

    testBuildType "debug" //the default BuildType

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            //java.srcDirs = ['src', 'thirdparty', 'annotation_gen']
            java.srcDirs = ['src', 'thirdparty']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        //new instrumentTest name
        androidTest.setRoot('../tests')
        androidTest{
            manifest.srcFile '../tests/AndroidManifest.xml'
            java.srcDirs = ['../tests/java']
            res.srcDirs = ['../tests/res', 'res']
            resources.srcDirs = ['../tests/res', 'res']
        }
    }
    testOptions {
        resultsDir = "$project.buildDir/build/test-results"
    }

    lintOptions {
        //checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }

}

if (project.hasProperty('key.store') &&
        project.hasProperty('key.store.password') &&
        project.hasProperty('key.alias.password')) {
     android.signingConfigs.release.storeFile = file(project.property('key.store'))
     android.signingConfigs.release.storePassword = property('key.store.password')
     android.signingConfigs.release.keyPassword = property('key.alias.password')
     android.signingConfigs.release.keyAlias = property('key.alias')
} else {
   android.buildTypes.release.signingConfig = null
}

dependencies {
    apt( "org.androidannotations:androidannotations:$AAVersion"){
        exclude module:'androidannotations-api'
    }
    compile "org.androidannotations:androidannotations-api:$AAVersion"

    compile project(":mapswithme-api")
    compile project(":showcaseview")

    compile files('libs/httpclientandroidlib-1.1.2.jar')
    compile files('libs/locus-api-4.0.jar')
    //https://mapsforge.googlecode.com/files/mapsforge-map-0.2.4.jar
    compile files('libs/mapsforge-map-0.2.4.jar')
    compile files('libs/mapsforge-map-0.3.0-jar-with-dependencies.jar')

    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.google.android.gms:play-services:6.5.+'

    compile 'com.jakewharton:butterknife:6.1.0'
    compile "org.apache.commons:commons-collections4:$CommonsCollections4Version"
    compile "org.apache.commons:commons-lang3:$CommonsLang3Version"
    compile "commons-io:commons-io:$CommonsIoVersion"
    compile 'com.google.code.findbugs:annotations:3.0.0'

    compile "io.reactivex:rxjava:$RXJavaVersion"
    compile "io.reactivex:rxandroid:$RXAndroidVersion"

    compile "com.fasterxml.jackson.core:jackson-core:$JacksonCoreVersion"
    compile "com.fasterxml.jackson.core:jackson-databind:$JacksonDatabindVersion"
    compile "com.fasterxml.jackson.core:jackson-annotations:$JacksonAnnotationsVersion"

    //TEST
    //compile files('compile-libs/androidannotations-3.2.jar')
    //compile files('compile-libs/findbugs-ant.jar')
    //compile files('compile-libs/findbugs-jsr305.jar')  //CheckForNull conflict with com.google.code.findbugs:annotations
    compile files('compile-libs/org.eclipse.jdt.annotation_1.1.0.v20130513-1648.jar')

    //Robotium / Robolectric??
    androidTestCompile files('../tests/libs/android-junit-report-1.5.8.jar')
    androidTestCompile files('../tests/libs/robotium-solo-3.6.jar')
    //androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.0.1'
}

/*
 ANDROID ANNOTATIONS
 */

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName 'cgeo.geocaching'

        // If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
        // resourcePackageName android.defaultConfig.packageName

        // You can set optional annotation processing options here, like these commented options:
        // logLevel 'INFO'
        // logFile '/var/log/aa.log'
    }
}

/*
 FINDBUGS

 Usage : gradle check

 */

//http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.quality.FindBugsExtension.html
findbugs {
    toolVersion = "3.0.0"
    //sourceSets = [sourceSets.main]
    ignoreFailures = true
    reportsDir = file("$project.buildDir/reports")
    effort = "max"
    reportLevel = "high"
    //visitors = ["FindSqlInjection", "SwitchFallthrough"]
    //omitVisitors = ["FindNonShortCircuit"]
    //includeFilter = file("$rootProject.projectDir/project/findbugs/inclusions.xml")
    excludeFilter = file("$rootProject.projectDir/project/findbugs/exclusions.xml")

}

/*
*
*
* END of useful build
* Following task are for samples
*
 */

task logInfo {
    logging.captureStandardOutput LogLevel.INFO
    doFirst {
        println 'A task message which is logged at INFO level'
    }
}

/*
 UNIT TEST
 */
/*
sourceSets {
    unitTest {
        java.srcDir file('../tests/src')
        //java.srcDirs =  ['src', 'thirdparty', 'annotation_gen', '../tests']
        resources.srcDir file('../tests/res')
        //manifest.srcFile '../tests/AndroidManifest.xml'
    }
}
dependencies {
    //unitTestCompile files("$project.buildDir/classes/release")
    unitTestCompile files("$project.buildDir/classes/debug")
    unitTestCompile 'junit:junit:4.8.2'
    unitTestCompile 'com.google.android:android-test:4.1.1.4'

    unitTestCompile 'com.googlecode.androidannotations:androidannotations-api:$AAVersion'
    unitTestCompile 'com.jakewharton:butterknife:6.1.0'
    unitTestCompile 'org.apache.commons:commons-collections4:4.0'
    unitTestCompile 'commons-io:commons-io:2.4'
    unitTestCompile 'org.apache.commons:commons-lang3:$CommonsLang3Version'
    unitTestCompile 'com.google.code.findbugs:annotations:3.0.0'
    unitTestCompile 'com.netflix.rxjava:rxjava-core:$RXVersion'
    unitTestCompile 'com.netflix.rxjava:rxjava-android:$RXVersion'
}

// extend the runtime
configurations {
    unitTestCompile.extendsFrom runtime
    unitTestRuntime.extendsFrom unitTestCompile
}

// add the unitTest task
//task unitTest(type:Test, dependsOn: assemble) {
task unitTest(type:Test, dependsOn: assembleDebug) {
    description = "run unit tests"
    testClassesDir = project.sourceSets.unitTest.output.classesDir
    classpath = project.sourceSets.unitTest.runtimeClasspath
}
// bind to check
check.dependsOn unitTest
//build.dependsOn unitTest
*/

//run gradle compileTest

/*
 PLACEHOLDER
 */

//Not working...copy templates/keys.xml in res/values for the moment
task prep() {
    /*
    requiredProperties "maps.api.key", "maps.api.key.market", "ocde.okapi.consumer.key", "ocde.okapi.consumer.secret", "ocpl.okapi.consumer.key", "ocpl.okapi.consumer.secret"
    doFirst {
        logger.info("prep... ")

        copy {
            from "templates"
            include "*.xml"
            into "res/values"
            filter(org.apache.tools.ant.filters.ReplaceTokens, tokens:  project.ext.filterTokens)
        }
    }
    */
}
task prep2() {
/*
        //http://goo.gl/bqnwjJ
        copy{
            from("${buildDir}/manifests"){
                include "${variant.dirName}/AndroidManifest.xml"
            }
            into("${buildDir}/manifests/$variant.name")

            // define a variable for your key:
            def gmaps_key = "<your-key>"

            filter{
                String line -> line.replaceAll("<meta-data android:name=\"com.google.android.maps.v2.API_KEY\" android:value=\"\"/>",
                                               "<meta-data android:name=\"com.google.android.maps.v2.API_KEY\" android:value=\"" + gmaps_key + "\"/>")
            }

            // set the path to the modified Manifest:
            variant.processResources.manifestFile = file("${buildDir}/manifests/${variant.name}/${variant.dirName}/AndroidManifest.xml")
        }


         */
}

android.applicationVariants.all{ variant ->
    variant.mergeResources.doLast{
        logger.info("rootProject.projectDir="+rootProject.projectDir)
        prep{}
    }
}

//http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments
task addTest {
    def src = ['tests/java']
    def file = file("app.iml")

    doLast {
        try {
            def parsedXml = (new XmlParser()).parse(file)
            def node = parsedXml.component[1].content[0]
            src.each {
                def path = 'file://$MODULE_DIR$/' + "${it}"
                def set = node.find { it.@url == path }
                if (set == null) {
                    new Node(node, 'sourceFolder', ['url': 'file://$MODULE_DIR$/' + "${it}", 'isTestSource': "true"])
                    def writer = new StringWriter()
                    new XmlNodePrinter(new PrintWriter(writer)).print(parsedXml)
                    file.text = writer.toString()
                }
            }
        } catch (FileNotFoundException e) {
            // nop, iml not found
        }
    }
}
/*
// always do the addtest on prebuild
gradle.projectsEvaluated {
    preBuild.dependsOn(addTest)
}*/