Android ProGuard使用要点!

1.基本的的使用可以很容易百度到,

 但是当你使用了android-support-v4或者android-support-v7或者android-support-v11包之后,你发现导出的时候,

警告相当得多,这个时候,就算百度,Google都不太好使了,因为他们都是回答了一部分,没有很好的解决你的问题:

 其实要解决你的问题的方法就在你的android-sdk路径的proguard中的文档中:

特别是Examples示例中:

示例中有专门针对android的说明:

  以下是第一点:

If you're using additional Google APIs, you'll have to specify those as well, for instance:

如果你使用了Google API,你还需要添加如下声明 

-libraryjars /usr/local/android-sdk/add-ons/google_apis-7_r01/libs/maps.jar

If you're using the Android Compatibility library, you should add the following line, to let ProGuard know it's ok that the library references some classes that are not available in all versions of the API:

如果你使用了android-support包,你需要使用以下声明设置,让ProGuard知道库中的一些类并不是在所有版本的API中可用:

-dontwarn android.support.**

 

如果你还有其它问题,那还是参见proguard文档吧..

2.使用ProGuard删除日志输出语句,

 Thanks to:statckoverflow

  (1)http://stackoverflow.com/questions/4435773/android-proguard-removing-all-log-statements-and-merging-packages

 (2)http://stackoverflow.com/questions/7086920/removing-logging-with-proguard-doesnt-remove-the-strings-being-logged

在开发android的时候,经常要使用Log.d()语句,但是发布的时候,如果一行一行的注释还是有点麻烦的.

这个时候可以使用如下的指令让proguard帮助我们删除他:

-assumenosideeffects class android.util.Log{ public static *** d(...); public static *** i(...); }

  

转载于:https://my.oschina.net/banxi/blog/55622

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ProGuard is a tool used in Android development to optimize and obfuscate the compiled code. It helps reduce the size of the APK file and makes it harder for reverse engineers to understand and modify the code. ProGuard performs several tasks to achieve this, including: 1. Shrinking: It analyzes the code and removes unused classes, fields, and methods, thereby reducing the size of the application. 2. Optimization: ProGuard applies various optimizations, such as inlining methods, removing dead code, and simplifying constant expressions, to improve the app's performance. 3. Obfuscation: It renames classes, fields, and methods with short, meaningless names, making it difficult for others to understand the code. To enable ProGuard in an Android project, you need to add the following lines to your project's `build.gradle` file: ```groovy android { // ... buildTypes { release { // ... minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } } ``` Here, `minifyEnabled true` enables code shrinking and obfuscation, while `proguardFiles` specifies the ProGuard configuration files. The `getDefaultProguardFile('proguard-android-optimize.txt')` line includes a default set of rules provided by the Android SDK, and you can customize these rules in your own `proguard-rules.pro` file. It's important to note that ProGuard can sometimes cause issues if it mistakenly removes code that is actually used, or if it conflicts with certain libraries or reflection-based code. In such cases, you may need to tweak the ProGuard configuration to exclude specific classes or methods. Overall, ProGuard is a useful tool for optimizing and securing your Android app.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值