在多模块项目上以“一件"的方式运行Proguard. [英] Run Proguard on multi-module project as "one piece"

查看:321
本文介绍了在多模块项目上以“一件"的方式运行Proguard.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TLDR:如何将proguard映射传递给javac以针对混淆的库进行编译?

TLDR: How to pass proguard mapping to javac to compile against obfuscated library ?

那很长,但是我不知道如何使它更短:

That's long, but I don't see how to make it shorter:

背景: 我有以下产品设置:

Background: I have the following product setup:

Android Studio项目 -图书馆模块 -(子)模块核心 -(子)模块A -(子)模块B -(子)模块C -示例应用程序模块 -...其他模块

Android Studio project - Library module - (sub)module Core - (sub)module A - (sub)module B - (sub)module C - Sample App module - ... Other modules

Core中的每个库子模块A,B,C都引用类,但是A,B,C之间是相互独立的.从概念上讲,它与Play服务相似,在Play Services中,用户只能拥有代码和所需的子模块. 每个库子模块都有外部API,但也有许多内部类 目标是能够将Core,A,B,C分配为独立的aar-s.

Each of library submodules A, B, C reference classes in Core, but A, B, C independent among themselves. Conceptually similar to Play Services where user can only have code and required sub-module. Each of the library submodules has external APIs but also many internal classes The goal is to be able to distribute Core, A, B, C as independent aar-s.

目标: 将所有子模块混淆在一起,只公开公共API,但以混淆/优化的形式分别打包和分发它们.

Goal: obfuscate all sub-modules together leaving only public APIs exposed but package and distribute them separately in obfuscated/optimized form.

问题: 我看不到如何在简单的gradle配置中使用它.这里需要自定义构建系统,除非有任何已知的解决方案?

Issue: I do not see how to use it with straightforward gradle configuration. Custom build system is needed here, Unless there is a any known solution?

这里需要的是:

  • Java将所有子模块一起编译
  • 对他们进行混淆处理
  • 分别运行其余所有构建过程

每个模块的正常构建过程如下: -编译->包括所有内容.混淆->包

Where is normal build process is for each module is: - Compile -> do everything incl. obfuscation -> package

直接编译在Core之后的第一个子模块编译时失败.如果只能将Proguard mapping.txt作为Java编译器的输入进行传递...但是我找不到这样的选项.有什么想法吗?

Straight forward setup fails at the compilation of the first submodule after Core. If it only would be possible to pass Proguard mapping.txt as an input to Java compiler... But I could not find such an option. Any ideas?

谢谢!

推荐答案

问题:我看不到如何在简单的Gradle中使用它 配置.这里需要自定义构建系统,除非有 任何已知的解决方案?

Issue: I do not see how to use it with straightforward gradle configuration. Custom build system is needed here, Unless there is a any known solution?

因此,您正在寻找自定义构建系统",因为您不知道该如何做.但是,如果这可以通过gradle解决,您想使用它,对吗?

So, you're looking for a "custom build system" since you don't know how to do it in gradle. But if this could be solved in gradle, you'd like to use it, right?

要使用gradle保护库,您有2种选择:

To proguarding libraries with gradle, you have 2 options:

  • 为每个库单独运行Proguard :在每个模块中,设置minifyEnabled true,然后使用proguardFiles函数设置您的 proguard.txt 文件.
  • 仅在您的应用程序模块中运行Proguard :在每个模块中,设置minifyEnabled false,然后使用consumerProguardFiles函数从每个库中传递 proguard.txt 文件到主模块.
  • Run Proguard for each library independently: In each module, set minifyEnabled true, and use proguardFiles function to set your proguard.txt file.
  • Run Proguard just in your app module: In each module, set minifyEnabled false, and use consumerProguardFiles function to pass the proguard.txt file from each library to the main module.

在这里通过代码示例进行了详细说明,因此我将不重复答案: https://stackoverflow.com/a/42758629/1516973

Here is explained in detail with code examples, so I'm not going to replicate the answer: https://stackoverflow.com/a/42758629/1516973

这篇关于在多模块项目上以“一件"的方式运行Proguard.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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