Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apply plugin: 'com.android.application'
- apply plugin: 'io.fabric'
- apply plugin: 'spoon'
- repositories {
- maven { url 'https://maven.fabric.io/public' }
- }
- buildscript {
- repositories {
- jcenter()
- mavenCentral()
- maven { url 'https://maven.fabric.io/public' }
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.5.0'
- classpath 'io.fabric.tools:gradle:1.21.2'
- classpath('com.squareup.spoon:spoon-runner:1.2.0') {
- exclude module: 'guava'
- }
- classpath('com.stanfy.spoon:spoon-gradle-plugin:1.0.2') {
- exclude module: 'guava'
- }
- classpath 'com.google.guava:guava:17.0'
- }
- }
- allprojects {
- repositories {
- jcenter()
- }
- }
- /**
- * CODE BASE VERSION
- *
- * This is hardcoded in the source code and reflects the version number of the source code.
- * This MUST be updated after at the start of every sprint. If a release to the public is
- * done we do a major version number increase, e.g. 1.3, 1.4, 1.5. If there is no release
- * to the public we will increment the minor version number, e.g. 1.5.1, 1.5.2, 1.5.3 etc.
- */
- def codeBaseVersion = "1.5"
- def buildConfigVersionFolder
- /**
- * Task Name: fetchResources
- * Description: This task fetches the white_labelling.xml file, and app resources from version control
- */
- task fetchResources(type: Exec) {
- def doPull = false;
- def resFolder = new File("$projectDir/res-repo")
- if (resFolder.exists()) {
- doPull = true;
- }
- def tfs = new XmlParser().parse("$projectDir/tfs.xml")
- def tfsUser = tfs.@tfsUser
- def tfsPassword = tfs.@tfsPassword
- def tfsUrl = tfs.@tfsUrl
- def gitFetchResources = exec {
- ignoreExitValue = true
- executable 'git'
- if (!doPull) {
- println "Cloning Resources"
- workingDir "$projectDir"
- args "clone", String.valueOf("http://$tfsUser:$tfsPassword@$tfsUrl"), "res-repo"
- } else {
- println "Pulling Resources"
- workingDir "$projectDir/res-repo"
- args "pull"
- }
- }
- println "gitFetchResources: " + gitFetchResources
- }
- /**
- * Task Name: updateBuildConfigVersionFolder
- * Description: This task determines the build config folder that should be used
- */
- task updateBuildConfigVersionFolder(type: Exec, dependsOn: 'fetchResources') {
- def lastFileName = codeBaseVersion
- new File("$projectDir/res-repo/buildConfig").eachFile() { file->
- if (file.isDirectory()) {
- lastFileName = file.getName()
- if (file.getName().equals(codeBaseVersion)) {
- buildConfigVersionFolder = file.getName()
- }
- }
- }
- if (!buildConfigVersionFolder) {
- buildConfigVersionFolder = lastFileName
- }
- println "buildConfigVersionFolder: " + buildConfigVersionFolder
- }
- /**
- * Task Name: genNewKey
- * Description: This task creates the .properties and .jks files for each product flavor if it does not already exist.
- */
- task genNewKey(type: Exec) {
- // Read the configuration from the XML file
- def applications = new XmlParser().parse("$projectDir/res-repo/buildConfig/$buildConfigVersionFolder/white_labelling.xml")
- applications.application.each { app ->
- // Configure the Product Flavors
- def appFlavor = new Expando()
- appFlavor.appName = app.@appName
- appFlavor.keyPassword = app.keystore.get(0).@keyPassword
- appFlavor.keyAlias = app.keystore.get(0).@keyAlias
- // Start the Signing Process
- appFlavor.keyStorePropertiesFileName = 'keystore-' << appFlavor.appName.toLowerCase() << '.properties'
- appFlavor.keyStoreJksFileName = 'release-' << appFlavor.appName.toLowerCase() << '.jks'
- // Create the keystore-*.properties file if it does not exist
- def keyStorePropertiesFile = new File("$projectDir/sign", appFlavor.keyStorePropertiesFileName.toString())
- if (!keyStorePropertiesFile.exists()) {
- def propertiesBuilder = new StringBuilder("keystore=keystore/" << appFlavor.keyStoreJksFileName << "\n")
- propertiesBuilder.append("storePassword=" << appFlavor.keyPassword << "\n")
- propertiesBuilder.append("keyAlias=" << appFlavor.keyAlias << "\n")
- propertiesBuilder.append("keyPassword=" << appFlavor.keyPassword << "\n")
- keyStorePropertiesFile.withWriter { writer ->
- writer << propertiesBuilder.toString()
- }
- }
- // Create the release-*.jks file if it does not exist
- def keyStoreJksFile = new File("$projectDir/keystore", appFlavor.keyStoreJksFileName.toString())
- if (!keyStoreJksFile.exists()) {
- def genKey = exec {
- ignoreExitValue = true
- executable 'keytool'
- args '-genkey', '-noprompt', '-alias', String.valueOf("$appFlavor.keyAlias"), '-keystore', String.valueOf("$projectDir/keystore/$appFlavor.keyStoreJksFileName"), '-storepass', "$appFlavor.keyPassword", '-dname', "CN=netstar.altech.co.za, OU=DEVELOPMENT, O=NETSTAR, L=JHB, ST=GAUTENG, C=ZA", '-keypass', String.valueOf("$appFlavor.keyPassword"), '-validity', String.valueOf(10000)
- }
- println "genNewKey: " + genKey
- }
- }
- }
- /**
- * Task Name: genVersionName
- * Description: This task generates the version using the following format: {BASE_VERSION}.{YY}{MM}.{DD}{BUILD_NUMBER}, e.g. 1.4.1601.0402
- */
- task genVersionName(type: Exec) {
- def date = new Date()
- def buildDate = date.format("yyMM.dd")
- def buildNumber = 1
- File buildNumberFile = rootProject.file("$projectDir/build_number.properties")
- if (buildNumberFile.exists()) {
- Properties properties = new Properties()
- properties.load(new FileInputStream(buildNumberFile))
- def lastBuildDate = properties['buildDate']
- if (lastBuildDate.equals(buildDate)) {
- buildNumber = Integer.parseInt(String.valueOf(properties['buildNumber'])) + 1
- }
- properties.setProperty('buildDate', buildDate)
- properties.setProperty('buildNumber', String.valueOf(buildNumber))
- properties.store(buildNumberFile.newWriter(), null)
- }
- codeBaseVersion = "$codeBaseVersion.$buildDate" + String.format("%02d", buildNumber)
- println "codeBaseVersion: " + codeBaseVersion
- }
- android {
- compileSdkVersion 23
- buildToolsVersion '23.0.2'
- useLibrary 'org.apache.http.legacy'
- compileOptions {
- encoding 'UTF-8'
- sourceCompatibility JavaVersion.VERSION_1_6
- targetCompatibility JavaVersion.VERSION_1_6
- }
- defaultConfig {
- applicationId 'za.co.altech.netstar.safeandsound'
- minSdkVersion 17
- targetSdkVersion 23
- versionCode 9
- versionName codeBaseVersion
- // Enable multiDex support
- multiDexEnabled true
- }
- /**
- * Read the white labelling config from the XML file
- */
- def productFlavorMap = [:]
- def applications = new XmlParser().parse("$projectDir/res-repo/buildConfig/$buildConfigVersionFolder/white_labelling.xml")
- applications.application.each { app ->
- // Step 1: Configure the Product Flavor
- def appFlavor = new Expando()
- appFlavor.appName = app.@appName
- appFlavor.appId = app.@appId
- appFlavor.versionCode = app.@versionCode
- appFlavor.versionName = codeBaseVersion
- appFlavor.menuItems = app.menuItems
- appFlavor.map = app.map
- appFlavor.apiAddresses = app.apiAddresses
- // Step 2: Create the res directory if it does not exist
- appFlavor.resFolderName = "$projectDir/src/main/res-" << appFlavor.appName.toLowerCase()
- def resFolder = new File(appFlavor.resFolderName.toString())
- if( !resFolder.exists() ) {
- resFolder.mkdirs()
- }
- // Step 3: Copy the images from the repo directory into the correct res folder
- def resRepoDir = "$projectDir/" << app.images.get(0).@resourceDirectory
- copy {
- from "${resRepoDir}"
- into "${appFlavor.resFolderName}"
- include 'drawable-*/**'
- includeEmptyDirs = false
- }
- // Step 4: Create the values directory if it does not exist
- def valuesFolderName = appFlavor.resFolderName
- valuesFolderName = valuesFolderName << '/values'
- def valuesFolder = new File(valuesFolderName.toString())
- if( !valuesFolder.exists() ) {
- valuesFolder.mkdirs()
- }
- // Step 5: Create the colors.xml file
- def colorsBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
- colorsBuilder.append("<resources>\n")
- app.colors.color.each { color ->
- colorsBuilder.append('\t<color name="' + color.@name.toString() + '">' + color.text().toString() + '</color>\n')
- }
- colorsBuilder.append("</resources>")
- new File( valuesFolder, 'colors.xml' ).withWriter { writer ->
- writer << colorsBuilder.toString()
- }
- // Step 6: Create the strings.xml file
- def stringsBuilder = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
- stringsBuilder.append("<resources>\n")
- app.strings.string.each { string ->
- stringsBuilder.append('\t<string name="' + string.@name.toString() + '">' + string.text().toString() + '</string>\n')
- }
- stringsBuilder.append("</resources>")
- new File( valuesFolder, 'strings.xml' ).withWriter { writer ->
- writer << stringsBuilder.toString()
- }
- // Step 7: Set the keystore-*.properties file name for the flavor
- appFlavor.keyStorePropertiesFileName = 'keystore-' << appFlavor.appName.toLowerCase() << '.properties'
- // Step 8: Finally add the application flavor to the map
- productFlavorMap.put(app.@appName, appFlavor)
- }
- // Update the source sets
- sourceSets {
- main {
- java.srcDirs = ['src/main/java']
- res.srcDirs = ['src/main/res']
- resources.srcDirs = ['src/main/res']
- }
- productFlavorMap.each { flavorName, appFlavor ->
- "$flavorName" {
- res.srcDirs = ['src/main/res-' << appFlavor.appName.toLowerCase()]
- resources.srcDirs = ['src/main/res-' << appFlavor.appName.toLowerCase()]
- }
- }
- }
- // Update the signing configs
- productFlavorMap.each { flavorName, appFlavor ->
- File signFile = rootProject.file("$projectDir/sign/$appFlavor.keyStorePropertiesFileName")
- if (signFile.exists()) {
- Properties properties = new Properties()
- properties.load(new FileInputStream(signFile))
- signingConfigs {
- "$flavorName" {
- storeFile rootProject.file(properties['keystore'])
- storePassword properties['storePassword']
- keyAlias properties['keyAlias']
- keyPassword properties['keyPassword']
- }
- }
- }
- }
- // Hide / show menu items
- productFlavors {
- productFlavorMap.each { flavorName, appFlavor ->
- "$flavorName" {
- applicationId appFlavor.appId
- versionCode appFlavor.versionCode.toInteger()
- versionName appFlavor.versionName
- // Create the Build Config for the menu items
- appFlavor.menuItems.menuItem.each { menuItem ->
- buildConfigField "boolean", menuItem.@name.toString(), 'Boolean.parseBoolean("' + menuItem.text().toString() + '")'
- }
- // Create the Build Config for the default center position of the map
- buildConfigField "double", "CENTER_LAT", 'Double.parseDouble("' + appFlavor.map.get(0).@centerLat.toString() + '")'
- buildConfigField "double", "CENTER_LON", 'Double.parseDouble("' + appFlavor.map.get(0).@centerLon.toString() + '")'
- buildConfigField "int", "CENTER_ZOOM_LEVEL", 'Integer.parseInt("' + appFlavor.map.get(0).@centerZoomLevel.toString() + '")'
- // Create the Build Config for the api addresses
- buildConfigField "String", "DEV_URL", '"' + appFlavor.apiAddresses.get(0).@devUrl.toString() + '"'
- buildConfigField "String", "PROD_URL", '"' + appFlavor.apiAddresses.get(0).@prodUrl.toString() + '"'
- }
- }
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
- productFlavorMap.each { flavorName, appFlavor ->
- productFlavors."$flavorName".signingConfig signingConfigs."$flavorName"
- }
- }
- debug {
- minifyEnabled false
- }
- }
- lintOptions {
- abortOnError false
- }
- }
- dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- compile project(':locationModule')
- compile project(':lineChartModule')
- compile 'com.android.support:support-v4:23.1.1'
- compile 'com.android.support:support-v13:23.1.1'
- compile 'com.android.support:appcompat-v7:23.1.1'
- compile 'com.android.support:cardview-v7:23.1.1'
- compile 'com.android.support:recyclerview-v7:23.1.1'
- compile 'com.android.support:design:23.1.1'
- compile 'com.mcxiaoke.volley:library:1.0.19'
- compile 'com.google.code.gson:gson:2.4'
- compile 'de.greenrobot:eventbus:2.4.1'
- compile 'com.wdullaer:materialdatetimepicker:1.5.3'
- // Multi Dex
- compile 'com.android.support:multidex:1.0.1'
- // Crash Analytics
- compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
- transitive = true;
- }
- // Unit Tests
- testCompile 'junit:junit:4.12'
- testCompile 'org.assertj:assertj-core:1.7.0'
- testCompile('org.robolectric:shadows-play-services:3.0') {
- exclude module: 'commons-logging'
- exclude module: 'httpclient'
- }
- testCompile 'org.robolectric:shadows-support-v4:3.0'
- testCompile 'org.robolectric:shadows-multidex:3.0'
- testCompile 'org.mockito:mockito-core:1.10.19'
- // Instrumentation Tests
- androidTestCompile 'org.assertj:assertj-core:1.7.0'
- androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.2'
- androidTestCompile 'com.squareup.spoon:spoon-client:1.1.10'
- }
- spoon {
- // Enable debug output
- debug = true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement