use*_*079 8 obfuscation android proguard android-studio
我已经创建了一个Android库项目的.aar文件(包含资源和drawable)
./gradlew assemble
Run Code Online (Sandbox Code Playgroud)
我通过设置minify == true启用了混淆
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用minify enabled = true运行提到的gradle命令时,我得到了 java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options?
这个错误指向什么以及如何模糊库.aar文件?
最好的祝福
使用 Proguard 对我来说就像一个魅力!
Proguard 用于缩小、混淆、优化代码。Proguard 对于您的库删除未使用的代码并使逆向工程变得不那么困难是必要的。库的 Proguard 规则与普通应用程序不同。如您所知,Proguard 使用无意义的名称重命名类、变量和方法。您希望保留开发人员将调用的那些方法和类的名称。您需要测试和验证生成的 AAR 文件中的混淆代码。
库模块 的build.gradle库的
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'
}
}
Run Code Online (Sandbox Code Playgroud)
在你图书馆的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
Run Code Online (Sandbox Code Playgroud)
感谢 .... 参考
两个建议:
| 归档时间: |
|
| 查看次数: |
5089 次 |
| 最近记录: |