Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apply plugin: 'com.android.application'
- apply plugin: 'android-apt'
- import org.apache.tools.ant.filters.*;
- def AAVersion = '3.2'
- Date.metaClass.'static'.fromString = { str ->
- com.mdimension.jchronic.Chronic.parse(str).beginCalendar.time
- }
- project.ext {
- buildBranch = "NA"
- buildDate = new Date()
- buildGuid = "NA"
- buildNumber = 9999
- buildVersion = '1.0.0'
- debugAPKFileSpec = "NA"
- releaseAPKFileSpec = "NA"
- }
- def getBuildBranch() {
- if( System.getenv("BUILD_BRANCH") != null ) {
- project.buildBranch = System.getenv("BUILD_BRANCH");
- } else {
- def stdout = new ByteArrayOutputStream()
- exec{
- commandLine('git','rev-parse','--abbrev-ref','HEAD');
- standardOutput = stdout;
- }
- project.buildBranch = stdout.toString().trim();
- }
- return project.buildBranch;
- }
- def getBuildDate() {
- if( System.getenv("BUILD_DATE") != null ) {
- project.buildDate = Date.fromString(System.getenv("BUILD_DATE"));
- }
- return project.buildDate;
- }
- def getBuildGuid() {
- if( System.getenv("BUILD_GUID") != null ) {
- project.buildGuid = System.getenv("BUILD_GUID");
- } else {
- def stdout = new ByteArrayOutputStream()
- exec{
- commandLine("git", "rev-parse", "HEAD");
- standardOutput = stdout;
- }
- project.buildGuid = stdout.toString().trim().substring(0,11);
- }
- return project.buildGuid;
- }
- def getBuildKey() {
- if( System.getenv("BUILD_KEY") != null ) {
- project.buildGuid = System.getenv("BUILD_KEY");
- } else {
- project.buildGuid = InetAddress.getLocalHost().getHostName() + "-" + ((Date)getBuildDate()).time;
- }
- return project.buildGuid;
- }
- def getBuildNumber() {
- if( System.getenv("BUILD_NUMBER") != null ) {
- project.buildNumber = Integer.parseInt(System.getenv("BUILD_NUMBER"));
- }
- return project.buildNumber;
- }
- def getBuildVersion() {
- if( System.getenv("BUILD_VERSION") != null ) {
- project.buildVersion = System.getenv("BUILD_VERSION");
- }
- return project.buildVersion;
- }
- buildscript {
- repositories {
- mavenCentral()
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.5.0'
- classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
- classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.5.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
- apt {
- arguments {
- resourcePackageName 'com.scout.ui'
- androidManifestFile variant.outputs[0].processResources.manifestFile
- }
- }
- android {
- compileSdkVersion 23
- buildToolsVersion "23.0.1"
- defaultConfig {
- applicationId "com.scout.scoutandroidapp"
- minSdkVersion 16
- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
- targetSdkVersion 23
- versionCode getBuildNumber()
- versionName getBuildVersion()
- }
- signingConfigs {
- release {
- storeFile file("../keystore")
- storePassword "STOREPASS"
- keyAlias "KEYALIAS"
- keyPassword "KEYPASS"
- }
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- signingConfig signingConfigs.release
- }
- debug {
- debuggable true
- }
- }
- applicationVariants.all { variant ->
- variant.outputs.each { output ->
- delete output.outputFile.parent;
- }
- }
- applicationVariants.all { variant ->
- variant.outputs.each { output ->
- output.outputFile = new File(
- output.outputFile.parent,
- output.outputFile.name.replace(".apk", "-${variant.versionName}.${variant.versionCode}.apk").replace("app-", "scout-android-app-")
- )
- if(output.outputFile.name.toLowerCase().contains("-debug-")) {
- project.debugAPKFileSpec = output.outputFile.parent + "/" + output.outputFile.name;
- }
- }
- }
- }
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- apt "org.androidannotations:androidannotations:$AAVersion"
- compile "org.androidannotations:androidannotations-api:$AAVersion"
- compile 'com.android.support:support-v4:23.1.1'
- compile 'com.android.support:appcompat-v7:23.1.1'
- compile 'com.android.support:recyclerview-v7:23.1.1'
- compile 'com.android.support:cardview-v7:23.1.1'
- compile 'com.android.support:design:23.1.1'
- compile 'com.squareup.retrofit:retrofit:1.9.0'
- compile files('libs/ormlite-android-4.48.jar')
- compile files('libs/ormlite-core-4.48.jar')
- compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
- compile 'de.greenrobot:eventbus:2.4.0'
- compile 'net.hockeyapp.android:HockeySDK:3.5.0'
- compile 'com.squareup.picasso:picasso:2.5.2'
- compile 'de.hdodenhof:circleimageview:2.0.0'
- compile('com.github.afollestad.material-dialogs:core:0.8.5.3@aar') {
- transitive = true
- }
- compile('com.mikepenz:materialdrawer:4.6.4@aar') {
- transitive = true
- }
- androidTestCompile ('com.android.support.test:runner:0.4.1') {
- exclude module: 'support-annotations'
- }
- androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.1') {
- exclude module: 'support-annotations'
- }
- }
- task deleteBuildInfo(type: Delete) {
- delete 'src/main/assets/build.json'
- }
- task deleteReleaseNotes(type: Delete) {
- delete 'HockeyAppDistributionReleaseNotes.txt'
- }
- task updateBuildInfo(type: Copy, dependsOn: deleteBuildInfo) {
- from '../build.json.sample'
- into 'src/main/assets'
- rename 'build.json.sample', 'build.json'
- filter(ReplaceTokens, tokens: [
- BUILD_BRANCH: getBuildBranch(),
- BUILD_DATE: getBuildDate().getDateTimeString(),
- BUILD_DIR: System.getenv('PWD'),
- BUILD_GUID: getBuildGuid(),
- BUILD_HOST: InetAddress.getLocalHost().getCanonicalHostName(),
- BUILD_KEY: getBuildKey(),
- BUILD_NUMBER: getBuildNumber().toString(),
- BUILD_USER: System.getenv('USER'),
- BUILD_VERSION: getBuildVersion()
- ])
- }
- task updateReleaseNotes(type: Copy, dependsOn: deleteReleaseNotes) {
- from '../HockeyAppDistributionReleaseNotes.md.sample'
- into '..'
- rename 'HockeyAppDistributionReleaseNotes.md.sample',
- 'HockeyAppDistributionReleaseNotes.md'
- filter(ReplaceTokens, tokens: [
- BUILD_BRANCH: getBuildBranch(),
- BUILD_DATE: getBuildDate().getDateTimeString(),
- BUILD_DIR: System.getenv('PWD'),
- BUILD_GUID: getBuildGuid(),
- BUILD_HOST: InetAddress.getLocalHost().getCanonicalHostName(),
- BUILD_KEY: getBuildKey(),
- BUILD_NUMBER: getBuildNumber().toString(),
- BUILD_USER: System.getenv('USER'),
- BUILD_VERSION: getBuildVersion()
- ])
- }
- preBuild.dependsOn(['updateBuildInfo','updateReleaseNotes']);
- task signJar << {
- def cmdLine = "jarsigner -storepass 'STOREPASS' -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.keystore " +
- "./app/build/outputs/apk/scout-android-app-release-unsigned-1.0.0." + getBuildNumber() + ".apk " +
- "-signedjar ./app/build/outputs/apk/scout-android-app-release-signed-1.0.0." + getBuildNumber() + ".apk KEYSTORE"
- println ("signJar cmdLine: " + cmdLine)
- exec {
- executable "sh"
- args "-c", cmdLine
- }
- }
- task alignJar << {
- def cmdLine = "zipalign -v 4 ./app/build/outputs/apk/scout-android-app-release-signed-1.0.0." + getBuildNumber() + ".apk " +
- "scout-android-app-release-signed-aligned-1.0.0." + getBuildNumber() + ".apk"
- println ("alignJar cmdLine: " + cmdLine)
- exec {
- executable "sh"
- args "-c", cmdLine
- }
- }
- task publishToHockeyApp {
- doLast {
- def puckCommandLine = "app_id='APIID' -api_token='APITOKEN' -submit='auto' -force='true' -download='true' -notify='true' -open='nothing' -notes_path='../HockeyAppDistributionReleaseNotes.md' -notes_type=markdown '$project.debugAPKFileSpec'";
- println("puckCommandLine: " + puckCommandLine);
- exec {
- executable "sh"
- args "-c", "/usr/local/bin/puck " + puckCommandLine
- }
- }
- }
- //alignJar.dependsOn(['signJar']);
- //publishToHockeyApp.dependsOn(['alignJar']);
- preBuild {
- doLast {
- println ("I am the prebuild task.");
- }
- }
- clean {
- doFirst {
- println ("I am the clean task. first");
- }
- println "I am clean task. middle"
- doLast {
- println ("I am the clean task. last");
- }
- }
- build {
- doLast {
- println ("I am the build tasks.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement