如何混淆在Eclipse中使用Proguard的一个Android库(.jar文件) [英] How to obfuscate an Android library (.jar file) using Proguard in Eclipse

查看:347
本文介绍了如何混淆在Eclipse中使用Proguard的一个Android库(.jar文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到有关如何混淆在Eclipse中使用ProGuard的Andr​​oid应用程序(的.apk文件)很多帖子。另请参阅<一href="http://developer.android.com/guide/developing/tools/proguard.html">http://developer.android.com/guide/developing/tools/proguard.html:

I have seen many posts about how to obfuscate an Android application (.apk file) using ProGuard in Eclipse. Also see http://developer.android.com/guide/developing/tools/proguard.html:

当您生成应用程序在释放模式,或者通过运行ant版本或通过使用导出向导在Eclipse中,构建系统会自动检查,看看是否proguard.config属性设置。如果是,ProGuard的自动包装万事成之前处理应用程序的字节code 一个的apk文件

"When you build your application in release mode, either by running ant release or by using the Export Wizard in Eclipse, the build system automatically checks to see if the proguard.config property is set. If it is, ProGuard automatically processes the application's bytecode before packaging everything into an .apk file."

但是,如果出口的Andr​​oid项目中使用Eclipse导出向导.jar文件,下面所描述的步骤(创建文件proguard.cfg,配置proguard.config属性文件default.properties到proguard.cfg的,使用导出向导等)似乎不工作 - 我看不出有任何模糊处理的类名,等在生成jar文件。我也有我的proguard.cfg文件中的下列设置,但我不认为在我的项目目录或在ProGuard的目录中的任何输出文件(甚至不创建该目录)。

But in case of exporting an Android project in a .jar file using Eclipse Export Wizard, following the described steps (of creating a file proguard.cfg, configuring proguard.config property to proguard.cfg in the file default.properties, using Export Wizard etc.) does not seem to work - I see no obfuscation of class names, etc. in the resulting jar file. I also have the following settings in my proguard.cfg file, but I don't see any output files in my project directory or in the proguard directory (that directory is not even created).

-dump class_files.txt 
-printseeds seeds.txt 
-printusage unused.txt 
-printmapping mapping.txt

我甚至创建了一个文件project.properties在我的下面一行项目目录,但是这似乎并没有吸引ProGuard的付诸行动:

I have even created a file project.properties in my project directory with the following line but that did not seem to entice ProGuard into action:

proguard.config=proguard.cfg

有没有在这个项目中定义的活动。我使用的是Android 2.3.1和Eclipse伽利略3.5.2在Windows上。相同的结果与Android 3.0。似乎是模糊处理的步骤,必须以某种方式在Eclipse导出向导明确地插话。我将AP preciate任何帮助或洞察力。谢谢。

There are no activities defined in this project. I am using Android 2.3.1 and Eclipse Galileo 3.5.2 on Windows. Same results with Android 3.0. Seems like the obfuscation step has to be somehow interjected explicitly in the Eclipse Export Wizard. I will appreciate any help or insight. Thanks.

推荐答案

作为建议的意见,上述问题的答案之一(但我没有注意到在第一,因为它被埋葬之间的补充意见一)

as suggested in the comments to one of the answers above (but which i didn't notice at first because it was buried amongst one of the "additional comments") …

我们只需运行progruard在命令行(见下图的第一块)在图书馆蚀外,在下面我们我们proguard.cfg文件中的第二块的参数(绝对< STRONG>不要使用 -dont preverify ,或使用你的项目作为一个Android库项目将无法正常因混淆从project.jar StackMapTable问题)。

we simply run progruard on the command line (see the first block below) on the library outside of eclipse with the parameters in the second block below in our our proguard.cfg file (and definitely do not use -dontpreverify, or projects that use your project as an android library won't be able to properly be obfuscated due to StackMapTable problems from your project.jar).

命令行:

$ java -jar $ANDROID_SDK/tools/proguard/lib/proguard.jar \
  -libraryjars $ANDROID_SDK/platforms/android-18/android.jar @proguard.cfg
  -outjars /tmp/project.jar -verbose

proguard.cfg:

proguard.cfg:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontwarn our.company.project.R*
-injars bin/project.jar
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep class org.apache.3rdparty.stuff.**
-keep public class our.company.project.ProjectAPI
-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

-keepclassmembers public class our.company.project.ProjectAPI {
    public static <fields>;
}

-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 *;
}

这可能不是所有的参数和-keep项目是绝对必要的(除了没有使用 -dont preverify 为previously提到),但大多数这些道理给我因为这需要在那里,如果你有一个Activity类扩展中要导出的库项目。

it's possible not all of the parameters and -keep items are strictly necessary (other than not using -dontpreverify as previously mentioned), but most of these make sense to me as items that need to be there if you have an Activity class extension in the library you are exporting.

这篇关于如何混淆在Eclipse中使用Proguard的一个Android库(.jar文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆