首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >混淆.aar文件

混淆.aar文件
EN

Stack Overflow用户
提问于 2015-03-31 17:28:24
回答 4查看 9.1K关注 0票数 13

我使用以下命令创建了一个安卓库项目的.aar文件(包含资源和可绘制内容

代码语言:javascript
复制
./gradlew assemble

我已经通过将minify ==设置为true来启用模糊处理

代码语言:javascript
复制
buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

但是,当我在minify enabled = true的情况下运行前面提到的gradle命令时,我得到java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?

这个错误指向什么?我如何对库.aar文件进行混淆?

诚挚的问候

EN

回答 4

Stack Overflow用户

发布于 2019-08-15 03:40:35

使用Proguard对我来说就像是一种魅力!

前卫用于收缩、混淆和优化代码。对于你的库来说,要移除未使用的代码,并使逆向工程变得稍微困难,Proguard是必要的。库的防护规则与普通应用程序不同。正如您所知道的,Proguard使用无意义的名称来重命名类、变量和方法。您希望保持开发人员将调用的那些方法和类的名称不变。您将需要测试和验证生成的AAR文件中的混淆代码。

Library Module build.gradle of your of your library

代码语言:javascript
复制
buildTypes {
    release {
        // Enables code shrinking, obfuscation, and optimization for only
        // your project's release build type.
        minifyEnabled true


        // Includes the default ProGuard rules files that are packaged with
        // the Android Gradle plugin. To learn more, go to the section about
        // R8 configuration files.
        proguardFiles getDefaultProguardFile(
                'proguard-android-optimize.txt'),
                'proguard-rules.pro'

       }
}

在您的库proguard-rules.proproguard-rules.pro

代码语言:javascript
复制
# Save the obfuscation mapping to a file, so we can de-obfuscate any stack
# traces later on. Keep a fixed source file attribute and all line number
# tables to get line numbers in the stack traces.
# You can comment this out if you're not interested in stack traces.

-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,EnclosingMethod

# Preserve all annotations.

-keepattributes *Annotation*

# Preserve all public classes, and their public and protected fields and
# methods.

-keep public class * {
    public protected *;
}

# Preserve all .class method names.

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

# Preserve all native method names and the names of their classes.

-keepclasseswithmembernames class * {
    native <methods>;
}

# Preserve the special static methods that are required in all enumeration
# classes.

-keepclassmembers class * extends java.lang.Enum {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
# You can comment this out if your library doesn't use serialization.
# If your code contains serializable classes that have to be backward
# compatible, please refer to the manual.

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# The library may contain more items that need to be preserved;
# typically classes that are dynamically created using Class.forName:

# -keep public class mypackage.MyClass
# -keep public interface mypackage.MyInterface
# -keep public class * implements mypackage.MyInterface

多亏了....参考文献

https://dev.to/mohitrajput987/develop--publish-your-own-sdk-in-android---part-2getting-started-with-sdk-development-3159

票数 7
EN

Stack Overflow用户

发布于 2015-08-11 22:22:28

Proguard删除未使用的类。库是独立的产品,有一些特定的入口点,不应该被混淆。因此,您需要添加规则来保持此入口点。规则看起来像这样:

代码语言:javascript
复制
-keep class packagename {public *;}
票数 4
EN

Stack Overflow用户

发布于 2015-04-30 17:40:49

两个建议:

  1. 请确保此文件存在于库模块中: proguard-rules.pro.
  2. Please尝试运行“./ :mylib:assembleRelease”,并将"mylib“替换为您的库模块名称。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29365161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档