【问题标题】:How to obfuscate android library(.aar) using proguard?如何使用 proguard 混淆 android 库(.aar)?
【发布时间】:2017-10-29 09:24:29
【问题描述】:

我想使用 proguard 混淆 .aar 库以用于分发目的,我在互联网上尝试了许多解决方案,但到目前为止没有任何效果,只有一些代码被混淆。谁能帮我解决这个问题?

【问题讨论】:

标签: android obfuscation android-library android-proguard aar


【解决方案1】:

在你的 build.gradle 中,在 defaultConfig 下添加 consumerProguardFiles :

 android {
        compileSdkVersion Integer.parseInt("${COMPILE_SDK}")
        buildToolsVersion "${BUILD_TOOLS_VERSION}"

        defaultConfig {
            targetSdkVersion Integer.parseInt("${TARGET_SDK}")
            minSdkVersion Integer.parseInt("${MIN_SDK}")
            consumerProguardFiles 'consumer-proguard-rules.pro'
        }
    }

您在库项目的根文件夹下添加一个名为 consumer-proguard-rules.pro 的文件。该文件应包含库项目的 build.gradle 中提到的所有依赖项的 proguard 规则。您应该为您的 POJO 类、带注释的接口以及任何其他需要保护免受 proguard 清理或混淆的类添加保留规则。 如果你收缩资源,你应该在资源下的 res 下添加一个 keep.xml 文件(例如 res/raw)。在此文件中,您指定要保留的可绘制对象或布局。你签入你的代码,使用反射调用 getResources().getIdentifier(..) 资源,如果是这样,你可以像这样添加你的可绘制对象。

<?xml version="1.0" encoding="utf-8"?>
<resources
    xmlns:tools="http://schemas.android.com/tools"
    tools:shrinkMode="safe"
    tools:keep="@layout/layout1, @drawable/icon1,@drawable/icon2,@drawable/img_*"/>

你可以用*告诉proguard把所有以img_开头的drawable保存在drawable文件夹下。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 2013-02-22
    • 1970-01-01
    • 2011-12-26
    相关资源
    最近更新 更多