0

i have written android library. but when i integrate aar into client app. i can actually see private/internal/public methods of "public" classes. what i expect is: it should show only "public" methods of "public" classes.

i am using R8, for release build i have following settings in library gradle file.

 buildTypes {
        release {           
            minifyEnabled true
            proguardFiles 'proguard-rules.pro'
        }
    }

proguard-rules.pro file contents:

-keep class com.comp.sdk.UserManager {
    public *;
 }

here UserManager is 'object' in kotlin.

after building aar file. distributing to client app. client app can still see private/public/internal methods for UserManager object.

my question is how can i write r8 rules for showing only public methods/variables of User object in kotlin?

Matrix
  • 7,477
  • 14
  • 66
  • 97
  • What exactly do you mean by "hide"? If the methods are there - then they can be "seen". By using access modifiers you can restrict access, but I assume you already know that. If your concern is the visibility of internal logic's method names - then the most you can do is obfuscate the names. – Alex Lipov Nov 12 '22 at 10:47
  • how can i obfuscate names with R8 ? – Matrix Nov 12 '22 at 10:53
  • I believe that the methods are indeed obfuscated with your configuration (please confirm that), but it's the kept metadata is the one that allows decompiler to retrieve the original method names. If that's the case, see a similar [question here](https://stackoverflow.com/q/46219853/1233652). – Alex Lipov Nov 12 '22 at 12:02
  • no methods are not obfuscated. thats why i am thinking something is missing. – Matrix Nov 12 '22 at 12:05
  • like how proguard changes method names to random a,b,c. i don't see those kind of changes in R8. plus R8 has additionally changed access modifiers of methods. – Matrix Nov 12 '22 at 12:06
  • in mapping i can only see methods renamed to methodname_release. – Matrix Nov 12 '22 at 12:07
  • There might be additional proguard rules which affect your effective configuration; check the `build\outputs\mapping\{flavor}\configuration.txt`, which contains the rules from all the possible sources. – Alex Lipov Nov 12 '22 at 12:50
  • @AlexLipov, i figured out, it was ' debuggable true' in release config which was stopping it from proguard. but now how can i make aar with proguard works on both device + emulator? – Matrix Nov 12 '22 at 17:33

0 Answers0