4

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,

michael
  • 3,835
  • 14
  • 53
  • 90

1 Answers1

8

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.

T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
  • Thanks, So how can I totally obfuscate the code rather than only names? – michael Aug 26 '16 at 16:52
  • 1
    I am not aware of any free or open-source solution that can obfuscate code with reasonable quality. You may take a look at DexGuard (https://www.guardsquare.com/dexguard), the commercial variant of ProGuard that offers also code obfuscation and class encryption. – T. Neidhart Aug 26 '16 at 18:31
  • Thanks, which means that the best practice is just make the libs activities perform basic ui and move the algorithmic parts to backend (server)? And then you don't care about exposing how you code ui? – michael Aug 26 '16 at 18:47
  • 1
    That would certainly be a better approach indeed. – T. Neidhart Aug 26 '16 at 19:11