Proguard doesnt obfuscate Class name, only methods are obfuscated

我只是一个虾纸丫 提交于 2019-12-10 16:46:30

问题


I try using Proguard in android studio, but seems like Proguard is not obfuscating the class name, for example, my app structure, and the config:

and config

but when i try trigger the exception in the app:

the exception is listed in ADB console:

only the methods are obfuscated, the MainActivity.class is not


回答1:


This is an expected behaviour because the class is an activity!

All classes that are mentioned in AndroidManifest.xml have to keep their names (activities, services, providers, receivers, application, instrumentation). Otherwise the system won't be able to find them.

Gradle build automatically generates some rules for your ProGuard configuration to achieve this. It scans AndroidManifest.xml and adds rules for each class found there.

If you want to see all the rules that are used, add this line to your ProGuard rules:

-printconfiguration "build/outputs/mapping/configuration.txt"

It will create configuration.txt file containing all the rules.

There should be something like this:

# view AndroidManifest.xml #generated:50
-keep class com.github.browep.proguard.MainActivity {
    <init>(...);
}



回答2:


I was facing the same problems,

After updating my Android plugin for Gradle, Proguard stop obfuscating my utility and other class files.

After few searching, I found that Android studio gradle now uses newer version of Proguard.

And according to this stack-overflow answer, which stated that: proguard automatically add rules specific for android/google package.

Therefore, After few rule changes in my app, Proguard obfuscated the class names again.

Old proguard-rules.pro:

#support-v4
#@link https://stackoverflow.com/questions/18978706/obfuscate-android-support-v7-widget-gridlayout-issue
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }

#support-v7
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }
#https://stackoverflow.com/a/34895791/4754141
-keep class !android.support.v7.view.menu.**
-keep interface android.support.v7.* { *; }

#support design
#@link https://stackoverflow.com/a/31028536
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

#error : Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
#solution : @link https://stackoverflow.com/a/14463528
-dontnote com.google.vending.licensing.ILicensingService
-dontnote **ILicensingService

#updating to Gradle 2.14.1 caused error :         https://stackoverflow.com/q/17141832/4754141
-keepattributes EnclosingMethod

#render script
#@link https://stackoverflow.com/questions/22161832/renderscript-support-library-crashes-on-x86-devices
-keepclasseswithmembernames class * { native <methods>; }
-keep class android.support.v8.renderscript.** { *; }

New proguard-rules.pro:

#https://stackoverflow.com/a/41901653/4754141
#https://stackoverflow.com/a/23840049/4754141
-keep class android.support.** { *; }
-keep interface android.support.** { *; }


来源:https://stackoverflow.com/questions/36077739/proguard-doesnt-obfuscate-class-name-only-methods-are-obfuscated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!