Android ProGuard 多个映射文件用于拆分 APK?



>我在 Android 工作室中成功生成了签名的 APK,通过 ABI 拆分它们并为每个 APK 分配不同的版本代码,方法是将以下代码添加到我的build.gradle文件中:

// Map for the version code that gives each ABI a value.
ext.abiCodes = ["armeabi-v7a":1, "arm64-v8a":2, "x86":3, "x86_64":4]
import com.android.build.OutputFile
// For each APK output variant, override versionCode with a combination of
// ext.abiCodes + variant.versionCode. In this example, variant.versionCode
// is equal to defaultConfig.versionCode. If you configure product flavors that
// define their own versionCode, variant.versionCode uses that value instead.
android.applicationVariants.all { variant ->
// Assigns a different version code for each output APK
// other than the universal APK.
variant.outputs.each { output ->
// Stores the value of ext.abiCodes that is associated with the ABI for this variant.
def baseAbiVersionCode =
// Determines the ABI for this variant and returns the mapped value.
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
// Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes,
// the following code does not override the version code for universal APKs.
// However, because we want universal APKs to have the lowest version code,
// this outcome is desirable.
if (baseAbiVersionCode != null) {
// Assigns the new version code to versionCodeOverride, which changes the version code
// for only the output APK, not for the variant itself. Skipping this step simply
// causes Gradle to use the value of variant.versionCode for the APK.
output.versionCodeOverride =
baseAbiVersionCode + variant.versionCode
}
}
}

现在,我想使用 ProGuard (minifyEnabled true) 来混淆我的代码。如官方 android 文档中所述,请务必为您发布的每个 APK 保留mapping.txt文件,以便解密通过 Google Play 开发者控制台收到的崩溃报告的混淆堆栈跟踪。但是当我生成按 ABI 拆分的 APK 时,我只在<module-name>/build/outputs/mapping/release/目录中找到一个mapping.txt文件。

我的问题:有人可以确认这个单一的mapping.txt文件将允许我解码被 ABI 拆分的 4 个 APK 的混淆堆栈跟踪吗?如果没有,如何生成 4 个不同的映射文件?

我尝试根据我在这篇文章中找到的代码片段生成不同的映射文件,本质上是尝试复制和重命名在多 APK 生成过程中创建的mapping.txt文件,但我仍然只得到一个映射文件:

applicationVariants.all { variant ->
if (variant.getBuildType().isMinifyEnabled()) {
variant.assemble.doLast {
copy {
from variant.mappingFile
into "${rootDir}/proguardTools"
rename { String fileName ->
"mapping-${variant.name}.txt"
}
}
}
}
}

我对gradle很陌生,我发现它的语法非常混乱。任何帮助将不胜感激。

我最终使用 Firebase 崩溃报告测试了堆栈跟踪去混淆(即无需将我的应用程序的崩溃测试版本部署到 Google Play 商店),我可以确认在Android Studio 中生成签名 APK 时创建的mapping.txt文件确实可以正确对堆栈跟踪进行去混淆对应于不同 ABI 类型的 APK 上发生的崩溃。

最新更新