android - 在 Eclipse 中使用 ProGuard(没有私钥)

标签 android proguard

我一直在尝试在我的测试 Android 应用程序中查看 ProGuard。我是否需要注册为 Android 开发者并拥有 key ?我知道应用程序需要在 Release模式下构建。我读了these在 Android 网站上多次说明,其中讨论了 ProGuard 的作用,但没有讨论如何在 Android 中正确实现混淆。找到另一个 blog它展示了如何使用 Ant 而不是 Eclipse。

最佳答案

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

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

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

# ProGuard
proguard.config=proguard.cfg

然后,你必须写下你的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 *;
}

当你在 Debug模式下编译时,没有混淆。要混淆您的代码,您必须:

1- 确保您的 list 文件将 Debug模式设置为 false:

<application android:icon="@drawable/icon" 
             android:label="@string/app_name"
             android:debuggable="false">

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

一旦完成混淆,你会发现一个proguard项目根目录中的目录。它将包含允许您检查混淆代码的文件,查看混淆的内容和未混淆的内容等。Proguard 的文档将在这方面帮助您,这非常简单。

关于android - 在 Eclipse 中使用 ProGuard(没有私钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6792145/

相关文章:

android - 加载 Google map 时的 ProgressBar

android - 没有在 Eclipse 中显示 Android 和 AVD 管理器

android - 如何使用 BluetoothHeadset API 获取蓝牙连接的设备

java - while 无法循环

android - ProGuard - org.codehaus.jackson.map.JsonMappingException : No suitable constructor found for type

android - 如何在我的 Android 库 (AAR) 中包含 proguard 配置

java - ProGuard Android - JDBC 错误 - NullPointerException

Android - ImageView - 多屏幕支持 - 将高度/宽度设置为 dp 或 match_parent/wrap_content?

java - 如何使用 maven- assembly-plugin 从 dependencySet 中删除 META-INF ?

android - 有没有让 Proguard 与 Cocos2d-x 一起工作的例子?和 twitter4j