线上APP出现BUG问题,但是BUG信息是混淆后的类文件路径,不利于BUG原因的查询和解决,首先我们要做的就是保存对应线上版本的混淆Mapping文件。
//针对多渠道,打包后自动将对应APP和Mapping文件备份,防止重复打包覆盖。(放在APP下的build.gradle)
/执行productFlavors 同名任务的时候,就会执行
tasks.whenTaskAdded { task ->
android.productFlavors.all { flavor ->
if (task.name.equalsIgnoreCase("assemble" + flavor.name)) {
task.doLast {
copyFile();
}
}
}
}
void copyFile(){
String desktopDir = "$rootDir"
println(desktopDir)
def dayTime = new java.text.SimpleDateFormat("yy_MM_dd").format(new Date())
def secondTime = new java.text.SimpleDateFormat("HH-mm-ss").format(new Date())
File cacheFile = new File(desktopDir + java.io.File.separator + "cache" + java.io.File.separator + dayTime);
if (!cacheFile.exists()) {
cacheFile.mkdirs();
}
android.productFlavors.all { flavorTow ->
copy {
from "$buildDir" + '/outputs/apk'
//注意通配符
include "*" + flavorTow.name + "*.apk"
into cacheFile.getPath()
rename {
flavorTow.name + android.defaultConfig.versionName + "_" + secondTime + ".apk"
}
}
copy {
from "$buildDir" + '/outputs/mapping/' + flavorTow.name + "/release"
include "mapping.txt"
into cacheFile.getPath()
rename {
flavorTow.name + android.defaultConfig.versionName + "_" + secondTime + ".txt"
}
}
}
}
打开Studio 内置的Proguard,还原错误信息
调用UI界面工具
***MacBook-Pro:****ketan$/Users/**/Library/Android/sdk/tools/proguard/bin/proguardgui.sh
//采用命令
retrace.bat -verbose mapping.txt stacktrace.txt > out.txt