Automatically archive APKs in Android Studio

Add to the bottom of your app/build.gradle

task deployApks(type:Copy) {
    description = "Copies APKs and Proguard mappings to the deploy directory"
    def appName = "posture";
    def versionDir = android.defaultConfig.versionName+"_"+android.defaultConfig.versionCode;

    println("Copies APK and Proguard to " + versionDir)

    from 'build/outputs/mapping/release/'
    include '**/mapping.txt'
    into '../.admin/deploy/' + versionDir
    rename ('mapping.txt', "${versionDir}-mapping.txt")

    from ('.') {
        exclude '**/build', '**/src'

    include '*.apk'
    into '../.admin/deploy/' + versionDir
    rename ('app-release.apk', "${appName}-${versionDir}.apk")
See also:


Build your signed APK via Android Studio

Build > Signed APK > [Enter Your Signing Credentials] > Done

Run ./gradlew deployApks

Magic Happens

A a shiny new .admin folder with archived apks, version numbers and mappings!

Kind thanks to AlekzKuperFilmz for the cover image.