Android Gradle,复制映射文件的任务
有必要使用Android Gradle,复制映射文件的任务,android,gradle,Android,Gradle,有必要使用mapping.txt文件来检查来自应用程序的崩溃(因为ProGuard),在许多情况下,开发人员忘记复制映射文件并对其进行备份,在下一个发行版之后,检查以前版本的错误将被更改,并且毫无用处 如何在发布后复制映射文件,并使用gradle任务自动将版本作为后缀复制到特定路径中的名称?这是我使用的代码段。它确实依赖于定义一个productFlavor,但这只是为了帮助命名文件,并允许在多个项目中重用相同的代码段,而无需修改,但是如果需要不同的文件名格式,可以重构该依赖关系 目前,apk和映
mapping.txt
文件来检查来自应用程序的崩溃(因为ProGuard
),在许多情况下,开发人员忘记复制映射文件并对其进行备份,在下一个发行版
之后,检查以前版本的错误将被更改,并且毫无用处
如何在发布后复制映射文件,并使用gradle任务自动将版本作为后缀复制到特定路径中的名称?这是我使用的代码段。它确实依赖于定义一个
productFlavor
,但这只是为了帮助命名文件,并允许在多个项目中重用相同的代码段,而无需修改,但是如果需要不同的文件名格式,可以重构该依赖关系
目前,apk和映射文件(如果需要)将以以下格式复制到定义的basePath:
文件路径\appname\appname构建类型versionname(versioncode)
e、 g
A:\Common\Apk\MyAppName\MyAppName发行版1.0(1).Apk
和
A:\Common\Apk\MyAppName\MyAppName发行版1.0(1)。映射
你认为合适就修改
android {
productFlavors {
MyAppName {
}
}
//region [ Copy APK and Proguard mapping file to archive location ]
def basePath = "A:\\Common\\Apk\\"
applicationVariants.all { variant ->
variant.outputs.each { output ->
// Ensure the output folder exists
def outputPathName = basePath + variant.productFlavors[0].name
def outputFolder = new File(outputPathName)
if (!outputFolder.exists()) {
outputFolder.mkdirs()
}
// set the base filename
def newName = variant.productFlavors[0].name + " " + variant.buildType.name + " " + defaultConfig.versionName + " (" + defaultConfig.versionCode + ")"
// The location that the mapping file will be copied to
def mappingPath = outputPathName + "\\" + newName + ".mapping"
// delete any existing mapping file
if (file(mappingPath).exists()) {
delete mappingPath
}
// Copy the mapping file if Proguard is turned on for this build
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
copy {
from variant.mappingFile
into output.outputFile.parent
rename { String fileName ->
newName + ".mapping"
}
}
}
}
// Set the filename and path that the apk will be created at
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
def path = outputPathName + "\\" + newName + ".apk"
if (file(path).exists()) {
delete path
}
output.outputFile = new File(path)
}
}
}
//endregion
}能否将此答案更新为最新的gradle版本?variant.assemble不受欢迎。您可以自由添加另一个答案,并更新代码。这不是我试图解决的问题。