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

时间:2017-03-24 12:24:28

标签: android android-studio gradle android-gradle proguard

我在Android studio中成功生成已签名的APK,通过ABI将它们拆分并为每个分配不同的versionCode,方法是将以下代码添加到我的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时,我只在mapping.txt目录中找到一个<module-name>/build/outputs/mapping/release/文件。

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

我尝试根据我在this post中找到的代码段生成不同的映射文件,实际上是在复制和重命名{$ 1}}文件时,因为它们是在多APK生成过程中创建的,但我仍然只是获取一个映射文件:

mapping.txt

我是新手,我发现它的语法很混乱。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

我最终使用Firebase崩溃报告测试了堆栈跟踪反模糊处理(即无需将我的应用的崩溃测试版本部署到Google Play商店),我可以确认一个DECLARE cursor c_cur IS SELECT SZRUNSP_STUDENT_NO, SZRUNSP_STUDENT_NAME, SZRUNSP_SUSPEND_ACCOUNT, SZRUNSP_UNSUSPEND_DATE WHERE SZRUNSP_SUSPEND_ACCOUNT = ('N') ORDER BY SZRUNSP_UNSUSPEND_DATE ASC; BEGIN FOR rec in c_cur LOOP twbkfrmt.p_TableDataWhite (HTF.formtext ( cname => '', csize => 15, cmaxlength => 9, cvalue => rec.SZRUNSP_STUDENT_NO, cattributes => 'style="font-size:12px" readonly ' || disabled)) END LOOP; END; 文件在Android Studio中生成已签名的APK时创建的对于不同ABI类型对应的APK上发生的崩溃正确地反混淆堆栈跟踪