Skip to content

Instantly share code, notes, and snippets.

@MinceMan
Created June 10, 2015 20:53
Show Gist options
  • Save MinceMan/24fc2c43ee27b218d57a to your computer and use it in GitHub Desktop.
Save MinceMan/24fc2c43ee27b218d57a to your computer and use it in GitHub Desktop.
Change output file name for Android with build.gradle
apply plugin: 'com.android.library'
/** This closure will rename your output file with your outputName, versionName and git commit. */
android.metaClass.renameVariants = { String moduleName, String outputName ->
def isApplication = binding.variables.containsKey('applicationVariants')
def variants = isApplication ? applicationVariants : libraryVariants
def gitCommit = "git rev-parse --short HEAD".execute().text.trim()
def ext = isApplication ? '.apk' : '.aar'
variants.all { -> outputs.each {
output ->
def File file = output.outputFile
def name = file.name
name = name.replace(moduleName, outputName)
name = name.replace(ext,
"-" + defaultConfig.versionName +
'-' + gitCommit + ext)
output.outputFile = new File(file.parent, name)
}
}
}
android {
compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_TARGET_SDK_VERSION)
versionCode Integer.parseInt(project.SDK_VERSION_CODE)
versionName project.SDK_VERSION_NAME
renameVariants('module', 'SweetProjectName')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment