我使用以下命令创建了一个安卓库项目的.aar文件(包含资源和可绘制内容
./gradlew assemble我已经通过将minify ==设置为true来启用模糊处理
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文件进行混淆?
诚挚的问候
发布于 2019-08-15 03:40:35
使用Proguard对我来说就像是一种魅力!
前卫用于收缩、混淆和优化代码。对于你的库来说,要移除未使用的代码,并使逆向工程变得稍微困难,Proguard是必要的。库的防护规则与普通应用程序不同。正如您所知道的,Proguard使用无意义的名称来重命名类、变量和方法。您希望保持开发人员将调用的那些方法和类的名称不变。您将需要测试和验证生成的AAR文件中的混淆代码。
Library Module build.gradle of your of your library
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.pro 的proguard-rules.pro内
# 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多亏了....参考文献
发布于 2015-08-11 22:22:28
Proguard删除未使用的类。库是独立的产品,有一些特定的入口点,不应该被混淆。因此,您需要添加规则来保持此入口点。规则看起来像这样:
-keep class packagename {public *;}发布于 2015-04-30 17:40:49
两个建议:
https://stackoverflow.com/questions/29365161
复制相似问题