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

柔情痞子 提交于 2019-12-01 05:34:03

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/39167966/android-proguard-how-to-hide-obfuscate-source-code-of-exported-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!