Hello everyone, does anyone know how to do a kotli...
# android
l
Hello everyone, does anyone know how to do a kotlin build.gradle function that will rename my .apk to: appName-variants-branchName.apk ?
not kotlin but kotlin colored 2
v
The gradle has no clue about your git branches. As of nice name I am using this for years. Probably you can do anything with that especially with kotlin gradle now: This is groovy
Copy code
// Human readable name of generated apks.
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
    outputFileName = "AppName ${versionName}($versionCode)-${variant.baseName}.apk"
}
}
ł
@Lukas Anda I did it this way:
Copy code
defaultConfig {
        applicationId = App.id
        minSdk = Versions.androidMinSdk
        targetSdk = Versions.androidTargetSdk
        versionCode = Versions.versionCode
        versionName = Versions.versionName +
            when (val name = System.getenv("BRANCH_NAME")) {
                null -> "-local-build"
                else -> "-$name"
            }
        setProperty("archivesBaseName", "$applicationId-v$versionCode($versionName)")
    }
And in github action like this:
Copy code
- name: Get branch name (merge)
        if: github.event_name != 'pull_request'
        shell: bash
        run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

      - name: Get branch name (pull request)
        if: github.event_name == 'pull_request'
        shell: bash
        run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
when it builds locally it adds local-build and when via github actions branch name
l
yeah I ended up doing something similar. Not the prettiest solution but it works