我正在尝试为每个构建变体重命名我的APK文件,以包含应用程序名称,versionName,versionCode和内部版本号.到目前为止,除了应用程序名称之外,我的所有工

我想使用AndroidManifest.xml文件用于android:label的相同值.这来自字符串资源@ string / app_name.我已经看到了使用以下方法替换资源值的能力:

resValue "string", "app_name", "Some new value"

但我只想读取此值并使用它来命名我的APK文件.

android.applicationVariants.all { variant ->

variant.outputs.each { output ->

renameApk(variant, output)

}

}

def renameApk(variant, output) {

def apkPath = output.outputFile.parent

def baseName = project.archivesBaseName

baseName += "-${variant.buildType.name}"

// add version name and version code

baseName += "-v${variant.mergedFlavor.versionName}-${variant.mergedFlavor.versionCode}"

// if built on jenkins ci, add jenkins build number:

def buildNumber = System.getenv('BUILD_NUMBER')

if (buildNumber && buildNumber.size() > 0) {

baseName += "-b${buildNumber}"

}

// if the variant will not be zipAligned, specify that

if (!output.zipAlign) {

baseName += '-unaligned'

}

// set the output file

output.outputFile = new File(apkPath, "${baseName}.apk");

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐