使用ProGuard和Eclipse(没有私钥)

str*_*der 2 android proguard

我一直试图通过我的测试Android应用程序看到ProGuard.我是否需要注册为Android开发人员并拥有执行此操作的密钥?我知道app需要在发布模式下构建.我在Android网站上多次阅读这些说明,其中讨论了ProGuard的功能,但没有说明如何在Android中正确实现它的混淆.找到另一个博客,展示如何使用Ant,但不是使用Eclipse.

Shl*_*blu 12

不,您不需要注册为Android开发人员来尝试Proguard混淆.您只需安装Proguard并为您的应用正确配置.

几个月以来,Android SDK附带了Proguard直接集成的发行版.打开您的<android-home>\tools目录,检查是否找到了一个名为的目录proguard.如果不是这样,最好是升级您的SDK.

使用集成版Android SDK,使用Proguard非常简单:您只需在default.properties项目文件中声明以下内容:

# ProGuard
proguard.config=proguard.cfg
Run Code Online (Sandbox Code Playgroud)

然后,proguard.cfg如果它还不存在,你必须写下你的.Android SDK为您创建的任何新项目编写此文件,因为它集成了Proguard,但如果您的项目是使用以前版本的SDK创建的,则此文件将不存在.以下文件适用于大多数Android项目:

-printmapping proguard.map
-renamesourcefileattribute ProGuard
-keepattributes SourceFile,LineNumberTable

-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 com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

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

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

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

-keep class * implements android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}
Run Code Online (Sandbox Code Playgroud)

在调试模式下编译时,没有混淆.要混淆代码,您必须:

1-确保清单文件将调试模式设置为false:

<application android:icon="@drawable/icon" 
             android:label="@string/app_name"
             android:debuggable="false">
Run Code Online (Sandbox Code Playgroud)

2-使用Eclipse的"文件/导出"菜单导出APK(假设您使用的是Eclipse,但是谁不使用Eclipse?:-)).只使用"运行"功能就不会有混淆,因为这实际上是在调试.

完成模糊处理后,您将proguard在项目的根目录中找到一个目录.它将包含允许您检查混淆代码的文件,查看混淆的内容和未混淆的内容等.Proguard的文档将帮助您,这非常简单.