gpt4 book ai didi

android - 如何使用 proguard 混淆 android 库(.aar)?

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:44 24 4
gpt4 key购买 nike

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

最佳答案

在您的 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 中提到的依赖项的所有混淆规则。您应该为您的 POJO 类、带有注释的接口(interface)以及您需要保护其免受混淆清理或混淆的任何其他类添加保留规则。如果你收缩资源,你应该在你的资源中添加一个 keep.xml 文件在 res(例如 res/raw)下。在此文件中,您指定要保留的可绘制对象或布局。您在使用反射通过 getResources().getIdentifier(..) 调用资源时 checkin 代码,如果是这样,您可以像这样添加可绘制对象。

<?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 文件夹下。

关于android - 如何使用 proguard 混淆 android 库(.aar)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44236208/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com