混淆模块/库 [英] Obfuscating a module/library

查看:100
本文介绍了混淆模块/库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个供应用程序使用的库.该模块具有接口和帮助程序类.

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?

我尝试过:

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

然后,我发现自己必须在proguard的所有课程中都做--keep.有什么我可以添加到proguard中的东西,以便可以保留所有这些接口/帮助程序类,并且仍然使它们模糊不清吗?

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?

推荐答案

如果仅希望避免混淆图书馆的公共API,则需要指定此公共API.图书馆有多种方法:

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. 具有用于公共API和实际实现的单独程序包,例如com.example.library包含公共API,而com.example.library.internal包含隐藏的实际实现.

  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.

将实际的实现包设为私有

Make the actual implementations package private

然后,ProGuard规则将如下所示:

The ProGuard rules would then look like this:

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

这将仅将公共类及其公共或受保护的方法/字段保留在com.example.library包中.

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

这篇关于混淆模块/库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆