Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename outputFileName for androidTest.apk?

After searching 2 days on the internet I wasn't able to find a way to rename the output file name of android-test.apk (for instrumented tests). I am building debug and instrumented tests apk with assembleAndroidTest and assembleDebug.

For debug build I managed to change the name and add version, but I couldn't do it for androidTest.apk. How can I add the same version and other name for test apk? Here is my build.gradle (module)

 android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    project.archivesBaseName = "Automator"
    defaultConfig {
        applicationId "com.xxx.automator"
        minSdkVersion 18
        targetSdkVersion 29
        versionCode 1
        versionName "1.1"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            android.applicationVariants.all { variant ->
                variant.outputs.all {
                    def appName = "Automator"
                    outputFileName = appName + "-${variant.versionName}.apk"
                }
            }
        }
    }

}
like image 311
Andrei Morosan Avatar asked Nov 23 '25 03:11

Andrei Morosan


1 Answers

Add this code to your app build.gradle:

android {
    // Make custom APK name for test builds
    testVariants.all { testVariant ->
        testVariant.outputs.all { output ->
            outputFileName = "CustomNameTest.apk"
        }
    }
}
like image 51
Voster Dred Avatar answered Nov 24 '25 18:11

Voster Dred