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

Android ProGuard multiple mapping files for split APKs?

我在 Android studio 中成功生成签名 APK,通过 ABI 拆分它们并为每个分配不同的版本代码,方法是将以下代码添加到我的 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) 来混淆我的代码。如 official android documentation 中所述,重要的是为您发布的每个 APK 保留 mapping.txt 文件,以便解密通过 Google Play 开发者控制台收到的崩溃报告的混淆堆栈跟踪。但是当我生成 ABI 拆分的 APK 时,我只在 <module-name>/build/outputs/mapping/release/ 目录中找到一个 mapping.txt 文件。

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

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

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 上发生的崩溃