gpt4 book ai didi

android - 很难使用 android maven 插件运行 Proguard 来混淆 apklib

转载 作者:行者123 更新时间:2023-11-29 21:59:23 27 4
gpt4 key购买 nike

我希望混淆 android apklib 文件中的非公共(public)方法等,以便我可以与其他人分发 apklib 文件,而不会影响共享我的所有源代码,因为 apklib 包含源代码。

我采用的方法是通过在 pom.xml 中启用 proguard.cfg 来混淆库项目中的非公共(public)方法

这是我的 proguard.cfg 的样子

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

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

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

这是我在安装 Maven 时遇到的错误

[INFO] --- android-maven-plugin:3.3.2:generate-sources (default-generate-sources) @ libraryprojects-lib1 --- [INFO] ANDROID-904-002: Found aidl files: Count = 0 [INFO] ANDROID-904-002: Found aidl files: Count = 0 [INFO] C:\GSDevelopment\tools\android-sdk\platform-tools\aapt.exe [package, -m, -J, C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\generated-sources\r, -M, C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\AndroidManifest.xml, -S, C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\res, --auto-add-overlay, -A, C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\assets, -I, C:\GSDevelopment\tools\android-sdk\platforms\android-14\android.jar] [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ libraryprojects-lib1 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 1 resource [INFO] skip non existing resourceDirectory C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\generated-sources\extracted-dependencies\src\main\resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ libraryprojects-lib1 --- [INFO] Compiling 2 source files to C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\classes [INFO] [INFO] --- android-maven-plugin:3.3.2:proguard (default-proguard) @ libraryprojects-lib1 --- [INFO] C:\GSDevelopment\tools\java\jdk1.6.0_33\jre\bin\java [-Xmx512M, -jar, C:\GSDevelopment\tools\android-sdk\tools\proguard\lib\proguard.jar, @proguard.cfg, -injars, 'C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\classes', -libraryjars, 'C:\GSDevelopment\tools\java\jdk1.6.0_33\jre\lib\rt.jar', -libraryjars, 'C:\GSDevelopment\tools\java\jdk1.6.0_33\jre\lib\jsse.jar', -libraryjars, 'C:\GSDevelopment\tools\java\jdk1.6.0_33\jre\lib\jce.jar', -libraryjars, c:.m2GSD\repository\com\google\android\android\4.0.1.2\android-4.0.1.2.jar(!org/xml/,!org/w3c/,!java/,!javax/), -libraryjars, 'c:.m2GSD\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar', -libraryjars, 'c:.m2GSD\repository\org\apache\httpcomponents\httpclient\4.0.1\httpclient-4.0.1.jar', -libraryjars, 'c:.m2GSD\repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar', -libraryjars, 'c:.m2GSD\repository\commons-codec\commons-codec\1.3\commons-codec-1.3.jar', -libraryjars, 'c:.m2GSD\repository\org\khronos\opengl-api\gl1.1-android-2.1_r1\opengl-api-gl1.1-android-2.1_r1.jar', -libraryjars, 'c:.m2GSD\repository\xerces\xmlParserAPIs\2.6.2\xmlParserAPIs-2.6.2.jar', -libraryjars, 'c:.m2GSD\repository\xpp3\xpp3\1.1.4c\xpp3-1.1.4c.jar', -libraryjars, 'c:.m2GSD\repository\org\json\json\20080701\json-20080701.jar', -outjars, 'C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\proguard-obfuscated.jar', -dump, 'C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\proguard\dump.txt', -printseeds, 'C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\proguard\seeds.txt', -printusage, 'C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\proguard\usage.txt', -printmapping, 'C:\GSDevelopment\expworkspace\Samples\libraryprojects\libraryprojects-lib1\target\proguard\mapping.txt'] [INFO] Note: there were 185 duplicate class definitions. [INFO] java.io.IOException: The output jar is empty. Did you specify the proper '-keep' options? [INFO] at proguard.shrink.Shrinker.execute(Shrinker.java:159) [INFO] at proguard.ProGuard.shrink(ProGuard.java:275) [INFO] at proguard.ProGuard.execute(ProGuard.java:101) [INFO] at proguard.ProGuard.main(ProGuard.java:492)

我有两个带有两个私有(private)方法的 java 文件。谁能指出我可能出了什么问题?提前致谢。

最佳答案

不确定您是否还需要答案,但我还是会给出答案,因为我遇到了类似的问题并且偶然发现了您的问题...

关键在于,引用 Proguard 手册:“为了确定必须保留哪些代码以及可以丢弃或混淆哪些代码,您必须为代码指定一个或多个入口点。这些入口点通常是具有主要方法、applet、midlet、 Activity 等的类。”

因此,看起来您的代码中没有任何公开条目。必须有一个公共(public)条目,否则任何东西如何使用您的库或操作系统(如 Android)如何调用您的代码。

您需要确定库的入口点是什么,然后需要确保正确使用“-keep”命令。例如,从库的 Proguard 示例中,这是它们保留公共(public)类的方式:

-keep public class * {
public protected *;
}

关于android - 很难使用 android maven 插件运行 Proguard 来混淆 apklib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12355667/

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