Skip to content

Instantly share code, notes, and snippets.

@Andra297
Forked from shakalaca/build.gradle
Created June 28, 2022 06:17
Show Gist options
  • Select an option

  • Save Andra297/6c98d3f54a09d61278670f5c4fc1b45a to your computer and use it in GitHub Desktop.

Select an option

Save Andra297/6c98d3f54a09d61278670f5c4fc1b45a to your computer and use it in GitHub Desktop.

Revisions

  1. @shakalaca shakalaca revised this gist Sep 3, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -65,3 +65,7 @@ def rename_and_moveout_apk(targetVariant) {
    rename ("$originApkFile.name", "$renameApkFile")
    }
    }

    clean.doLast {
    project.delete "$rootProject.projectDir/out"
    }
  2. @shakalaca shakalaca created this gist Sep 3, 2013.
    67 changes: 67 additions & 0 deletions build.gradle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    buildscript {
    repositories {
    mavenCentral()
    }
    dependencies {
    classpath 'com.android.tools.build:gradle:0.5.6'
    }
    }

    task wrapper(type: Wrapper) {
    gradleVersion = '1.7'
    }

    apply plugin: 'android'

    android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    buildTypes {
    debug {
    packageNameSuffix ".debug"
    versionNameSuffix "-SNAPSHOT"
    }
    }
    }

    android.applicationVariants.all { variant ->
    variant.assemble.doLast {
    rename_and_moveout_apk(variant)
    }
    }

    def rename_and_moveout_apk(targetVariant) {
    // get hash of current commit
    new ByteArrayOutputStream().withStream { os ->
    def result = exec {
    executable = 'git'
    args = ['rev-parse', '--short', 'HEAD']
    standardOutput = os
    }

    project.ext.gitHash = os.toString().trim();
    }

    // replace output apk name to <product>-<version>-<buildtype>-<githash>.apk
    def versionSuffix = targetVariant.buildType.versionNameSuffix ? targetVariant.buildType.versionNameSuffix : ""
    def versionName = targetVariant.mergedFlavor.versionName + versionSuffix + "-${gitHash}";

    if (targetVariant.zipAlign) {
    def originZipAlignedApkFile = targetVariant.outputFile;
    def renameZipAlignedApkFile = originZipAlignedApkFile.name.replace(targetVariant.buildType.name, versionName);
    copy {
    from "$originZipAlignedApkFile"
    into "$rootProject.projectDir/out"
    rename ("$originZipAlignedApkFile.name", "$renameZipAlignedApkFile")
    }
    }

    def originApkFile = targetVariant.packageApplication.outputFile;
    def renameApkFile = originApkFile.name.replace(targetVariant.buildType.name, versionName);
    copy {
    from "$originApkFile"
    into "$rootProject.projectDir/out"
    rename ("$originApkFile.name", "$renameApkFile")
    }
    }