build.gradle 7.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*******************************************************************************
 *     Tablexia
 * 
 *     Copyright (C) 2013  CZ NIC z.s.p.o. <podpora at nic dot cz>
 * 
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

/*
21
* Release singing information have to be stored in ~/.gradle/gradle.properties file
22 23 24
*
* gradle.properties:
*
25 26 27 28
*    TABLEXIA_RELEASE_KEYSTORE=<path to keystore file>
*    TABLEXIA_RELEASE_KEYSTORE_PASSWORD=***********
*    TABLEXIA_RELEASE_KEY_ALIAS=<keystorealias>
*    TABLEXIA_RELEASE_KEY_PASSWORD=***********
29 30 31 32 33 34 35
*
*
*/

import java.util.regex.Pattern

buildscript {
36 37
    repositories {
        mavenCentral()
38
    }
39
    dependencies {
40
        classpath 'com.android.tools.build:gradle:0.11.+'
41
        classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
42 43 44
    }
}

45
apply plugin: 'android-sdk-manager'
46
apply plugin: 'android'
47
apply plugin: 'eclipse'
48

49
configurations {
50 51
    unitTest
    unitTestCompile.extendsFrom runtime, unitTest
52 53
    unitTestRuntime.extendsFrom unitTestCompile
}
54

55 56
repositories {
    mavenCentral()
57
    maven{url 'https://mint.splunk.com/gradle/'} // bugsense gradle repository
58 59 60 61
    maven{url 'https://repository-achartengine.forge.cloudbees.com/snapshot/'} // achartengine repository
}

dependencies {
62
    unitTest files('unitTestLibs/android-19.jar')
63
    unitTest files('libraries/AndEngine-1.0.0-SNAPSHOT/build/intermediates/classes/release/')
64
    unitTest 'junit:junit:4.11'
65
    unitTest files('build/intermediates/classes/cs/debug')
66 67
    
    compile files('libs/activeandroid-3.1-SNAPSHOT.jar')
68
    compile files('libs/libGoogleAnalyticsServices.jar')  
69
    compile project(':libraries:AndEngine-1.0.0-SNAPSHOT')
70
    compile 'com.android.support:support-v4:19.0.1'
71
    //compile 'com.google.android.gms:play-services:4.+'
72
    compile 'org.achartengine:achartengine:1.2.0'
73
    compile "com.splunk.mint:mint:4.0.6"
74 75
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'org.roboguice:roboguice:2.0'
76
    compile 'org.apache.commons:commons-lang3:3.1'
77
    compile 'com.google.guava:guava:15.0'
78
}
79
    
80
sourceSets {
81 82 83 84 85
    main {
        java {
            srcDir 'src/main/java'
        }
    }
86
    unitTest {
87 88 89 90
        java {
            srcDir 'src/test/java'
        }
    }
91 92
}

93 94 95 96 97

task createObb{
     description = "Create all OBB packages"
}

98 99
android {
    compileSdkVersion 19
100
    buildToolsVersion "19.1.0"
101 102 103 104 105 106 107 108 109 110 111 112 113

	sourceSets {
	    main {
	        manifest {
	            srcFile 'AndroidManifest.xml'
	        }
	        res {
	            srcDir 'res'
	        }
	        assets {
	            srcDir 'assets'
	        }
	    }
114 115 116 117 118 119 120 121 122
	    
	    sk {
	       res {
                srcDir 'flavors/sk/res'
                }
           assets {
                srcDir 'flavors/sk/assets'
           }
	    }
123 124 125 126 127 128
	}
    
    defaultConfig {
        targetSdkVersion 19
        versionName getVersionNameFromGit()
        versionCode getVersionCodeFromGit()
129
        //applicationId "cz.nic.tablexia"
130 131 132 133 134
    }

    lintOptions {
           abortOnError false
    }
135 136
   
    productFlavors{
137 138
        cs {
            applicationId "cz.nic.tablexia"
139 140
        }
        
141 142 143
        sk {
            applicationId "cz.nic.tablexia.sk"
            versionName getVersionNameFromGit()+"-SK"
144
        }
145 146
        all{currentFlavor ->
		    task ("create"+ currentFlavor.name.substring(0, 1).toUpperCase() + currentFlavor.name.substring(1)+"Obb", type:Zip){
Luboš Horáček's avatar
Luboš Horáček committed
147
		        archiveName = "main.${defaultConfig.versionCode}.${currentFlavor.applicationId}.obb"
148 149 150 151 152 153 154 155 156 157 158 159 160 161
		    
				ext.destDir = new File(buildDir, "obb/${currentFlavor.name}")
				ext.destFile = new File(destDir, archiveName)
				duplicatesStrategy  DuplicatesStrategy.EXCLUDE
				doFirst {
				        destDir.mkdirs()
				}
			    description = "Creates expansion file for APK flavour ${currentFlavor.name}"	
				destinationDir = new File(buildDir, "obb/${currentFlavor.name}");
				entryCompression = ZipEntryCompression.STORED
				from "flavors/${currentFlavor.name}/obb", "obb"
				tasks.createObb.dependsOn("create"+ currentFlavor.name.substring(0, 1).toUpperCase() + currentFlavor.name.substring(1)+"Obb")
		    }
        }
162 163 164 165 166 167 168
    }

    buildTypes {
        release {
            debuggable false
        }
    }
169
    
170 171 172 173 174
	applicationVariants.all { variant ->
	    def file = variant.outputFile
	    variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")) 
	}
    
175
     if (project.hasProperty('TABLEXIA_RELEASE_KEYSTORE') && project.hasProperty('TABLEXIA_RELEASE_KEYSTORE_PASSWORD') 
176 177 178
        && project.hasProperty('TABLEXIA_RELEASE_KEY_ALIAS') && project.hasProperty('TABLEXIA_RELEASE_KEY_PASSWORD')) {
        signingConfigs {
            release {
179 180 181 182
                  storeFile file(TABLEXIA_RELEASE_KEYSTORE)
                  storePassword TABLEXIA_RELEASE_KEYSTORE_PASSWORD
                  keyAlias TABLEXIA_RELEASE_KEY_ALIAS
                  keyPassword TABLEXIA_RELEASE_KEY_PASSWORD
183 184 185 186 187 188 189
            }
        }

        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
190 191
        }
    }
192
}
193

194
eclipse {
195 196 197 198 199 200
    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
201 202 203 204

        sourceSets {
            main {
                java.srcDirs.addAll( project.sourceSets.main.java.srcDirs.path)
205
                java.srcDirs.addAll( project.sourceSets.unitTest.java.srcDirs.path)
206 207 208 209
                java.srcDirs 'gen'
            }
        }
    
210 211
        plusConfigurations += configurations.compile
        plusConfigurations += configurations.unitTestCompile
212
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
213 214
        downloadSources = true
        downloadJavadoc = false
215 216 217
        
        file {
            whenMerged { classpath ->
218
                configurations.unitTest.each {value -> classpath.entries.findAll { entry -> entry.path == value.path }*.exported = false }
219 220
            }
        }
221 222 223
    }

    project {
224
        natures.clear()
225
        natures 'com.android.ide.eclipse.adt.AndroidNature'
226
        natures 'org.eclipse.jdt.core.javanature'
227 228 229 230 231 232
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
233
}
234 235

task wrapper(type: Wrapper) {
Luboš Horáček's avatar
Luboš Horáček committed
236
    gradleVersion = '1.11'
237
}
238

239
task unitTest(type:Test, dependsOn: assemble) {
240 241
	scanForTestClasses = false
    include "cz/nic/tablexia/test/**/*Test.class"
242
    description = "run unit tests"
243 244
    testClassesDir = project.sourceSets.unitTest.output.classesDir
    classpath = project.sourceSets.unitTest.runtimeClasspath
245
}
246

247

248

249
check.dependsOn unitTest
250 251 252 253

def getVersionNameFromGit() {
    def stdout = new ByteArrayOutputStream()
    exec {
Luboš Horáček's avatar
Luboš Horáček committed
254
        commandLine 'git', 'describe', '--tags', '--always'
255 256 257
        standardOutput = stdout
    }
    return stdout.toString().trim()
258 259
}

260 261 262 263 264 265 266
def getVersionCodeFromGit() {
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-list', 'HEAD', '--count'
        standardOutput = stdout
    }
    return stdout.toString().trim().toInteger()
267
}
268

269

270 271
assemble.dependsOn = ['assembleRelease', 'createObb']

272
project.ext.set("archivesBaseName", "tablexia");