2

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"
                }
            }
        }
    }

}
mohammadReza Abiri
  • 1,759
  • 1
  • 9
  • 20
  • Andrei Morosan refer [this](https://stackoverflow.com/questions/27678398/change-generated-apk-name-from-app-debug-apk) may it will help you. – Nilesh Panchal Sep 18 '19 at 12:03
  • @NileshPanchal I already used that for debug and release build. But I couldn't find a way to do it for instrumented tests. – Andrei Morosan Sep 18 '19 at 18:28
  • Maybe this [link](https://developer.android.com/studio/build/gradle-tips#change-the-test-build-type) can help you. – tadev Sep 19 '19 at 05:15
  • Did you find a solution? I'm also facing this problem. – Warcello Nov 26 '19 at 16:50
  • Unfortunately not. Because I want to generate separate names at build time. One name for debug/release and another name for instrumented tests. – Andrei Morosan Nov 28 '19 at 13:32

2 Answers2

6

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"
        }
    }
}
Voster Dred
  • 61
  • 1
  • 2
3

Put the following code in your app 'build.gradle' file

android {

buildTypes {
        applicationVariants.all { variant ->
            variant.outputs.all {
                outputFileName = "Your_Desired_Name.apk"
            }
        }
}

This will work with latest sdk as well as latest os version.

Nilesh Panchal
  • 1,059
  • 1
  • 10
  • 24
  • Unfortunately this is not working. Because I want to generate separate names at build time. One name for debug/release and another name for instrumented tests. – Andrei Morosan Nov 28 '19 at 13:32