我想弄清楚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和后代没有进行模糊处理和优化?
答案 0 :(得分:3)
我不知道,但你可以检查为什么proguard保持课程: http://proguard.sourceforge.net/manual/usage.html
搜索 -whyareyoukeeping
答案 1 :(得分:0)
我认为它应该是minifyEnabled true
而不是minifyEnabled = true
至少在我的build.gradle文件中是这样的,并且混淆有效。