我希望在android apklib文件中混淆非公共方法等,以便我可以与其他人分发apklib文件,而不会损害共享我的所有源代码,因为apklib包含源代码。
我采用的方法是通过启用pom.xml中的proguard.cfg来混淆库项目中的非公共方法
这是我的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
(默认生成源)@ libraryprojects-lib1-[信息]
ANDROID-904-002:找到的辅助文件:计数= 0 [信息] ANDROID-904-002:
找到的辅助文件:计数= 0 [信息]
C:\ GSDevelopment \ tools \ android-sdk \ platform-tools \ aapt.exe [包,
-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
(默认资源)@ libraryprojects-lib1 --- [INFO]使用'UTF-8'
编码以复制过滤的资源。 [INFO]正在复制1个资源[INFO]
跳过不存在的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
(默认编译)@ libraryprojects-lib1 --- [信息]编译2源
文件到
C:\ GSDevelopment \ expworkspace \ Samples \ libraryprojects \ libraryprojects-lib1 \ target \ classes
[INFO] [INFO] --- android-maven-plugin:3.3.2:proguard
(默认保护程序)@ libraryprojects-lib1 --- [信息]
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 。罐',
-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]注意:有185个重复的类定义。 [信息]
java.io.IOException:输出jar为空。您是否指定了
适当的“ -keep”选项? [INFO]位于
proguard.shrink.Shrinker.execute(Shrinker.java:159)[INFO]在
proguard.ProGuard.shrink(ProGuard.java:275)在[INFO]
proguard.ProGuard.execute(ProGuard.java:101)在[INFO]
proguard.ProGuard.main(ProGuard.java:492)
我有两个带有两个私有方法的java文件。谁能指出我可能出了什么问题?提前致谢。
最佳答案
不知道您是否仍然需要答案,但是无论如何我都会给出答案,因为我遇到了类似的问题,偶然发现了您的问题...
关键是引用Proguard手册:“为了确定必须保留哪些代码以及可以丢弃或混淆哪些代码,您必须为代码指定一个或多个入口点。这些入口点通常是类。主要方法,小程序,midlet,活动等。”
因此,您的代码似乎没有任何公共条目。必须有一个公共条目,否则任何东西都不能使用您的库或OS(例如Android)如何调用您的代码。
您需要确定库中的入口点是什么,然后需要确保正确使用了“ -keep”命令。例如,从Proguard的库示例中,这就是它们保留公共类的方式:
-keep public class * {
public protected *;
}
关于android - 使用Android Maven插件运行Proguard混淆apklib时遇到困难,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12355667/