android - 为什么 ProGuard 不混淆这些类?

标签 android android-gradle-plugin proguard android-proguard

我想弄清楚 ProGuard 在使用 Gradle 构建的 Android 项目中是如何工作的。

鉴于我的 Gradle DSL:

    buildTypes {
    debug {
        versionNameSuffix = ".D"
    }
    release {
    }
    all {
        minifyEnabled = true
        proguardFile "proguard-configur.txt"
    }
}

并给出我的 proguard-configur.txt 文件:

# Allow obfuscation of android.support.v7.internal.view.menu.**
# to avoid problem on Samsung(and other) 4.2.2 devices with appcompat v21
# see https://code.google.com/p/android/issues/detail?id=78377
-optimizations !class/merging/*,!code/allocation/variable
-keepattributes **
-keep class !android.support.v7.internal.view.menu.**,** {*;}
-keep class !android.support.** {*;}
-dontpreverify
-dontwarn **

我在这里期望的行为是保留除支持库之外的所有类,因此,支持库将被混淆和优化。 尽管如此,它并没有经过优化,而且似乎也没有被混淆:

<root>: 64710
    <default>: 1
    android: 15856
        accessibilityservice: 6
        accounts: 23
        animation: 38
        app: 437
        appwidget: 7
        bluetooth: 2
        content: 397
            pm: 85
            res: 95
        database: 91
            sqlite: 23
        graphics: 275
            drawable: 85
                shapes: 2
            pdf: 3
        hardware: 4
            display: 3
        location: 35
        media: 200
            session: 72
        net: 62
            http: 6
            wifi: 6
        os: 236
        preference: 22
        print: 22
            pdf: 5
        provider: 15
        speech: 6
            tts: 6
        support: 12406
            annotation: 3
            v4: 7030
                accessibilityservice: 41
                app: 1438
                content: 232
                    pm: 1
                    res: 8
                database: 3
                graphics: 122
                    drawable: 96
                hardware: 19
                    display: 19
                internal: 74
                    view: 74
                media: 1108
                    routing: 96
                    session: 766
                net: 64
                os: 21
                print: 82
                provider: 96
                speech: 14
                    tts: 14
                text: 88
                util: 265
                view: 2290
                    accessibility: 847
                widget: 1072
            v7: 5373
                app: 458
                appcompat: 15
                cardview: 8
                gridlayout: 7
                internal: 2172
                    app: 267
                    text: 3
                    transition: 2
                    view: 608
                        menu: 512
                    widget: 1290
                recyclerview: 1
                view: 25
                widget: 2687
        telephony: 4
        text: 53
            method: 3
            style: 4
        transition: 16
        util: 66
        view: 807
            accessibility: 164
            animation: 35
            inputmethod: 3
        webkit: 73
        widget: 553

那么,问题很明确了:为什么不对 android.support 和后代进行混淆和优化?

最佳答案

我不知道,但你可以检查为什么 proguard 保持类: http://proguard.sourceforge.net/manual/usage.html

搜索-whyareyoukeeping

关于android - 为什么 ProGuard 不混淆这些类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30910884/

相关文章:

Android - 如何检查 Proguard 混淆是否有效?

java - Android - 使用两个 xml 文件显示单个 Activity

android - java.util.zip.ZipException Android Studio

java - 添加监听器导致崩溃?

android - aar 对比 "plain module"的优势

安卓 gradle 构建 : Share library between parent and child

java - Proguard 的 -whyareyoukeeping 的输出在哪里?

android - ProGuard:找不到引用的类 com.google.android.gms.R

android - 从图像中识别眼睛

android - 找不到来源