Skip to content

Commit

Permalink
apk filename: shows appname, flavour, version, hash
Browse files Browse the repository at this point in the history
  • Loading branch information
Wikinaut committed Oct 20, 2017
1 parent d254f23 commit 2af8ec7
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 11 deletions.
62 changes: 61 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ android {
lintOptions {
abortOnError true
}

defaultConfig {
applicationId "net.programmierecke.radiodroid2"
minSdkVersion 14
targetSdkVersion 23

versionCode 47
versionName "0.37"
versionName "0.38"

// Define your application name here.
// It must neither be present in /res/values/strings.xml
// nor in /res/values/string_no_translate.xml
resValue 'string', 'app_name', 'RadioDroid'
}

buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -42,3 +49,56 @@ dependencies {
playCompile 'com.google.android.gms:play-services-cast:11.0.2'
playCompile 'com.google.android.gms:play-services-cast-framework:11.0.2'
}


// https://stackoverflow.com/questions/24649240/build-release-apk-with-customize-name-format-in-android-studio
// https://stackoverflow.com/questions/32092665/resolve-application-label-for-each-build-type/32220436#32220436
// https://stackoverflow.com/questions/18332474/how-to-set-versionname-in-apk-filename-using-gradle

android.applicationVariants.all { variant ->

variant.outputs.each { output ->

// get app_name field from defaultConfig
def appName = variant.mergedFlavor.resValues.get('app_name').getValue()

// concat new App name with each flavor's name
appName = "${appName}"
variant.productFlavors.each { flavor ->
appName += "-${flavor.name}"
}

// optionally add buildType name
appName += "-${variant.buildType.name}"

// your requirement: if buildType == debug, add DEV to App name
if (variant.buildType.name == "debug") {
appName += "-DEV"
}

// if you want, you can set a new resValue
// variant.resValue 'string', 'app_name', appName

/*
* Gets the version name from the latest Git tag
*/

def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
try {
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
} catch (Exception ignored) {
return "No commit hash"
}
}

def finalName = appName + "-" + versionName + "-"
finalName += getGitHash() + ".apk"
output.outputFile = new File(output.outputFile.parent, finalName)

}
}
1 change: 0 additions & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Jméno</string>
<string name="detail_tags">Tagy</string>
<string name="detail_country">Země</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Name</string>
<string name="detail_tags">Tags</string>
<string name="detail_country">Land</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Nombre</string>
<string name="detail_tags">Etiquetas</string>
<string name="detail_country">País</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fi/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Nimi</string>
<string name="detail_tags">Tunnisteet</string>
<string name="detail_country">Maa</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Nom</string>
<string name="detail_tags">Tags</string>
<string name="detail_country">Pays</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-sk/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Názov</string>
<string name="detail_tags">Značky</string>
<string name="detail_country">Krajina</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">RadioDroid</string>
<string name="detail_name">Name</string>
<string name="detail_tags">Tags</string>
<string name="detail_country">Country</string>
Expand Down
22 changes: 21 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:2.3.3'
}


repositories {
mavenCentral()
}

if (gradle.gradleVersion >= "2.2") {
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0+'
}
} else if (gradle.gradleVersion >= "2.1") {
dependencies {
classpath 'com.android.tools.build:gradle:0.14.0+'
}
} else {
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0+'
compile 'com.android.support:support-v4:13.0+'
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Aug 30 23:04:08 CEST 2016
#Fri Oct 20 02:33:26 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

0 comments on commit 2af8ec7

Please sign in to comment.