How to Obfuscated Jar or AAR files

2019-08-01 01:03发布

问题:

Can someone help me about, obfuscated or give me example to do this?

I created an .aar file and .jar file and put the class of getter and setter that will give value if they access on it.

but the thing in need to put the hidden values that someone will not see what is the value on it.

     package com.example.test;
     public class MyClass  extends  privateClass{
            String testing;
            public MyClass() {
              this.testing = getStringExample();
            }
            public String getTesting() {
                return testing;
            }
            public void setTesting(String testing) {
                this.testing = testing;
            }
     }

and this class must be hide/obfuscated to the other developers if i give my library

    package com.example.test;

    public class privateClass {
        String getStringExample()
        {
             return "TEST RESULT";
        }
    }

Note: I tried to put proguard too, and check the library but still they can see my private class, , i tried to use interface and extends the class but still the same,

here is my proguard example:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontwarn ccom.example.test.R*
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class
-keepclassmembers class com.example.test.** { *; }
-keep class com.example.eyefixdata.** {
    void set*(***);
    void set*(int, ***);
    boolean is*();
    boolean is*(int);
    *** get*();
    *** get*(int);
}

Please save my day. hope you help me. Thanks in advance.

回答1:

You can move your private classes/interfaces to other packages, e.g. put your privateClass to an internal package package com.example.your.library.internal; to distinguish with your public classes/interfaces.


package com.example.your.library.internal;

public class privateClass {
    String getStringExample()
    {
        return "TEST RESULT";
    }
}

And add below line to your proguard configuration

-keep public class com.example.your.library.* { public *; }

Note that you should use single wild char * to NOT obfuscate the internal packages.