首页 > 解决方案 > 如何重命名 androidTest.apk 的 outputFileName?

问题描述

在互联网上搜索 2 天后,我找不到重命名 android-test.apk 的输出文件名(用于检测测试)的方法。我正在使用 assembleAndroidTest 和 assembleDebug 构建调试和检测测试 apk。

对于调试版本,我设法更改名称并添加版本,但我无法为 androidTest.apk 做到这一点。如何为测试 apk 添加相同的版本和其他名称?这是我的 build.gradle (模块)

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

}

标签: androidtestinggradlebuildinstrumentation

解决方案


将此代码添加到您的应用程序build.gradle

android {
    // Make custom APK name for test builds
    testVariants.all { testVariant ->
        testVariant.outputs.all { output ->
            outputFileName = "CustomNameTest.apk"
        }
    }
}

推荐阅读