Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProGuard how to hide/obfuscate source code of exported library

I'm developing Android library and I want to hide/obfuscate the source code implementation of the library.

The way the user project app will use the library is:

startActivity( new Intent(context, LibraryActivityName.class) );

So I need to keep just the name of entry point Activity inside the library project, That's all.

When I used the default ProGuard settings:

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

as well as the suggested example for library - Nothing happened, and by clicking on the Activity name inside the user app (when he imports it) - One can see the source code.

Thanks,

like image 360
michael Avatar asked Feb 06 '23 06:02

michael


1 Answers

As you do not have a typical library, you should not include the typical library example.

First of all, you need to enable Proguard execution, change this line:

 minifyEnabled true

Second, you do not want to keep all public classes, but only the activity:

 -keep class LibraryActivityName { public protected <methods>; }

The remaining classes can be fully obfuscated if I understand your question correctly, so there should be no need for further configuration, unless you use reflection somewhere.

It would also be good if you repackage the obfuscated classes into an internal package or something using

 -repackageclasses my.library.package.internal

which might also required

 -allowaccessmodification

btw. ProGuard will not obfuscate the code itself, only the class / method names.

like image 53
T. Neidhart Avatar answered Feb 13 '23 06:02

T. Neidhart