导出签名、混淆的 Android 应用程序时如何在 Eclipse 中设置 ProGuard?

发布于 2024-09-24 01:27:50 字数 107 浏览 6 评论 0原文

我正在发布一个在 Eclipse 中开发的 Android 应用程序,正如标题中所述,我想将 Proguard 混淆集成到构建中,专门用于导出签名的应用程序。

有人没有走过蚂蚁之路吗?

I'm publishing an Android application developed in Eclipse and, as stated in the title, I would like to integrate Proguard obfuscation into the build, specifically for exporting a signed app.

Anyone had any luck without going down the ant path?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

兮子 2024-10-01 01:27:50

我还想在不使用 Ant 或命令行方法的情况下完成此操作。以下是有效的(仅在 Eclipse + Windows 上):

  • (您需要下载 Proguard。脚本期望在此处找到它:C:\android-sdk_r04-windows\proguard\lib\proguard.jar)。

  • 创建 Windows 批处理文件,“C:\android-sdk_r04-windows\obfusc.bat”:


    DEL /S /Q obfuscated
    MKDIR obfuscated

    java -jar C:\android-sdk_r04-windows\proguard\lib\proguard.jar @android.pro

    DEL /S /Q bin\com\
    DEL /S /Q bin\org\

    ROBOCOPY obfuscated\com bin\com /S
  • < p>在 Eclipse 中,打开 Android 项目的属性页面,选择“Builders”窗格并添加一个类型为“Program”的新构建器。在主选项卡的“位置”字段中输入上一步中脚本的绝对路径。在“工作目录”字段中输入变量${build_project}。在“Build options”选项卡中,选择“Run builder”下的“After a clean”。

  • 确保此构建工具位于最后一个,就在 Android 软件包生成器之前。

  • 在 Android 项目的根文件夹中创建一个 proguard 配置文件。我稍微定制了这些并将它们包含在修订控制中,但这取决于您。我使用的文件名为“android.pro”,如脚本中所命名,与开发博客中的配置类似,但包含带有 injar、outjar 和 libraryjar 语句的标头,例如:


    -injars      bin(!.svn/**)
    -outjars     obfuscated
    -libraryjars C:\android-sdk_r04-windows\android-sdk-windows\platforms\android-1.6\android.jar
    -libraryjars C:\GoogleAnalyticsAndroid_0.7\libGoogleAnalytics.jar

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

    -printmapping proguard.map
    -keepattributes SourceFile,LineNumberTable

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

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

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

    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
  • :生成器大部分时间都关闭。当需要测试或导出混淆的 APK 时,将其打开,然后从 Eclipse 执行“Project > Clean”,包括该项目及其依赖的任何库项目。

我想就是这样。

I also wanted to do this without using Ant or the command line approach. Here is what worked (on Eclipse + Windows only):

  • (You need to download Proguard. The script expects to find it here: C:\android-sdk_r04-windows\proguard\lib\proguard.jar).

  • Create a Windows batch file, "C:\android-sdk_r04-windows\obfusc.bat":


    DEL /S /Q obfuscated
    MKDIR obfuscated

    java -jar C:\android-sdk_r04-windows\proguard\lib\proguard.jar @android.pro

    DEL /S /Q bin\com\
    DEL /S /Q bin\org\

    ROBOCOPY obfuscated\com bin\com /S
  • In Eclipse, bring up the properties page of your Android project, select the "Builders" pane and add a new builder of type "Program." In the "Location" field of the main tab put the absolute path of the script in the previous step. In the "Working directory" field put the variable ${build_project}. In the "Build options" tab select "After a clean" under "Run builder."

  • Make sure this build tool comes next to last, just before the Android package builder.

  • Create a proguard config file in the root folder of the Android project. I customize these slightly and include them in revision control, but that's up to you. The file I use is called "android.pro," as named in the script, and is similar to the config in the dev blog but includes a header with injar, outjar, and libraryjar statements, for example:


    -injars      bin(!.svn/**)
    -outjars     obfuscated
    -libraryjars C:\android-sdk_r04-windows\android-sdk-windows\platforms\android-1.6\android.jar
    -libraryjars C:\GoogleAnalyticsAndroid_0.7\libGoogleAnalytics.jar

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

    -printmapping proguard.map
    -keepattributes SourceFile,LineNumberTable

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

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

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

    -keepclassmembers enum * {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
  • You will want to keep this Builder turned off most of the time. When it is time to test or export an obfuscated APK, turn it on and then do a "Project > Clean" from Eclipse, including the project and any library projects it depends on.

I think that's about it.

喵星人汪星人 2024-10-01 01:27:50

好的,这是关于该主题的最相关和最新的帖子:

http://android-developers.blogspot.com/2010/09/proguard-android-and-licensing-server.html

它确实使用了 Ant,但所有困难的部分都为你完成了,只要你按照说明操作,它就会起作用。注意:不要跳过更新,这仅适用于 SDK r7+,并且运行 eclipse 的更新也不是一个坏主意,对于 AVD 更新也是如此。

并且,对于任何添加外部 jar 的人,请设置 ProGuards procfg.txt 并添加:

-libraryjars {path}{file_name}.jar

Ok, this is the most relevant and recent post on the topic:

http://android-developers.blogspot.com/2010/09/proguard-android-and-licensing-server.html

It dose use Ant, but all the hard parts are done for you, and as long as you follow the instruction, it works. A note: don't skip the update this only work with SDK r7+, and it's not a bad idea to run eclipse's update, for the AVD update too.

And, for anyone adding external jars, setup ProGuards procfg.txt and add:

-libraryjars {path}{file_name}.jar

不美如何 2024-10-01 01:27:50

如果您使用的是 eclipse,只需取消注释 project.properties

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

If you are using eclipse just uncomment the project.properties line

# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文