why proguard is only obfuscating the class which is not extending anything

前端 未结 2 494
后悔当初
后悔当初 2021-01-17 06:30

i am trying to obfuscate my android application with proguard. But the problem is when i decompiled the apk it only shows the changed variable names but class names are sam

相关标签:
2条回答
  • 2021-01-17 07:02

    I don't know what exactly problem in your case but i had solved my problem by below proguard rules and their are various rules which help you to protect your application

    -dontskipnonpubliclibraryclassmembers
    -dontshrink
    -dontoptimize
    -printmapping build/libs/output/obfuscation.map
    -keepattributes
    -adaptclassstrings
    -dontnote
    -dontwarn
    
    # Keep Android classes
    -keep class ** extends android.** {
        <fields>;
        <methods>;
    }
    
    # Keep serializable classes & fields
    -keep class ** extends java.io.Serializable {
        <fields>;
    }
    
    # Keep - Applications. Keep all application classes, along with their 'main'
    # methods.
    -keepclasseswithmembers public class * {
        public static void main(java.lang.String[]);
    }
    
    # Also keep - Enumerations. Keep the special static methods that are required in
    # enumeration classes.
    -keepclassmembers enum  * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    
    
    -assumenosideeffects class android.util.Log {
        public static *** d(...);
        public static *** e(...);
        public static *** w(...);
    }
    

    For More Information you can visit Proguard official site

    0 讨论(0)
  • 2021-01-17 07:03

    Use this RULES

    It will change obfuscating the class as well as your instance

    -ignorewarnings
    
    -keep class * {
        public private default *;
    }
    

    Note: Don't forget to check your all functionalities after applying changes in proguard-ruls.pro file

    There are may be some class will not work after applied changes in proguard-ruls.pro file in this case you have to use -keep to avoid this issue

    -keep Specifies classes and class members (fields and methods) to be preserved as entry points to your code. For example, in order to keep an application, you can specify the main class along with its main method.

    and you can apply this rules also

    ignorewarnings
    
    -dontpreverify
    -repackageclasses ''
    -allowaccessmodification
    -optimizations !code/simplification/arithmetic
    -keepattributes *Annotation*
    
    
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet);
    }
    
    -keepclasseswithmembers class * {
        public <init>(android.content.Context, android.util.AttributeSet, int);
    }
    
    -keepclassmembers class * implements android.os.Parcelable {
        static android.os.Parcelable$Creator CREATOR;
    }
    
    -keepclassmembers class **.R$* {
        public static <fields>;
    }
    
    -keep class android.support.v7.widget.SearchView { *; }
    
    -assumenosideeffects class android.util.Log {
        public static *** d(...);
        public static *** e(...);
        public static *** w(...);
    }
    

    for more about proguard-rules you can refer official proguard DOC

    0 讨论(0)
提交回复
热议问题