Android ProGuard如何隐藏/混淆导出库的源代码 [英] Android ProGuard how to hide/obfuscate source code of exported library

查看:133
本文介绍了Android ProGuard如何隐藏/混淆导出库的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android库,我想隐藏/混淆该库的源代码实现.

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) );

所以我只需要在库项目中保留入口点Activity的名称,就这些.

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

当我使用默认的ProGuard设置时:

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.

谢谢

推荐答案

由于没有典型的库,因此不应包含典型的库示例.

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

首先,您需要启用Proguard执行,更改此行:

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

可能也需要

 -allowaccessmodification

顺便说一句. ProGuard不会混淆代码本身,而只会混淆类/方法名称.

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

这篇关于Android ProGuard如何隐藏/混淆导出库的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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