Obfuscating a module/library

元气小坏坏 提交于 2019-12-12 18:25:25

问题


I have a library that will be consumed by apps. This module has interfaces and helper classes.

How can I obfuscate the whole module but still allow access to all those interfaces and helper classes?

I tried this:

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

Then I found myself having to do --keep on all my classes in proguard. Is there something I can add to pro guard so that I can keep all those interfaces/helper-classes and still have it as obfuscated?


回答1:


If you want to keep only the public API of your library from being obfuscated, you need to specify this public API. There are various approaches for libraries:

  1. Have separate package for public API and actual implementations, e.g. com.example.library contains the public API, whereas com.example.library.internal contains the actual implementations that are hidden.

  2. Make the actual implementations package private

The ProGuard rules would then look like this:

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

This will keep only public classes together with their public or protected methods / fields in the com.example.library package.



来源:https://stackoverflow.com/questions/38041396/obfuscating-a-module-library

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