1

The default output file for Android builds in Cordova (7.0) is platforms/android/build/outputs/apk/android-debug.apk.

How can I modify this so it becomes something like myappname-xxx.apk, where xxx is the output from git describe.

Possibly relevant: How to set versionName in APK filename using gradle?

glennr
  • 2,069
  • 2
  • 26
  • 37

2 Answers2

1

Just thought I'd update the answer here in-case anyone else is looking for newer android build tools. You can use the build-extras.gradle as previously answered but your script should look something like below.

def applicationName = "your-application-name";

android.applicationVariants.all { variant ->
    variant.outputs.all {
        def newApkName
        newApkName = "${applicationName}-${variant.versionName}.apk"
        outputFileName = new File(newApkName)
    }
}
0

Cordova uses gradle to do its Android builds. The gradle build configuration is in platforms/android/build.gradle but you shouldn't edit this file. Extensions can be added by adding a file named build-extras.gradle to platforms/android/ as documented here. My project uses gulp so I used that to copy it from my project's source directory.

build-extras.gradle should contain (source):

def getVersionName = { ->
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'git', 'describe', '--tags', '--dirty'
            standardOutput = stdout
        }
        return stdout.toString().trim()
    }
    catch (ignored) {
        return null;
    }
}

android {
    buildTypes {
        debug {
            applicationVariants.all { variant ->
                variant.outputs.each { output ->
                    def file = output.outputFile
                    output.outputFile = new File(file.parent,
                        file.name.replace("android", "myappname")
                            .replace(".apk", "-" + getVersionName() + ".apk"))

                }
            }
        }
    }
}
glennr
  • 2,069
  • 2
  • 26
  • 37