proguard

大牛耗时一年:深入探索 Android 包体积优化,共三万字建议收藏上

跟風遠走 提交于 2020-04-04 00:04:05
由于文章特别长,建议先收藏再阅读。 在 Android 性能优化的知识体系当中,包体积优化一直被排在优先级比较低的位置,从而导致很多开发同学对自身应用的大小并不重视。在项目发展的历程中,一般可划分为如下三个阶段: 初创期 => 成长期 => 成熟期 通常来说,当应用处于成长期的中后阶段时,才会考虑去做系统的包体积优化,因此,只有在这个阶段及之后,包体积优化带来的收益才是可观的。 那么,包体积优化能够给我们带来哪些 收益 呢?如何全面对应用的包体积进行 系统分析 及 针对性优化呢?在这篇文章中,我们将一起进行深入地分析与探索。 1、瘦身优化及 Apk 分析方案介绍 1、瘦身优势 我们首先来介绍下,为什么我们需要做 APK 的瘦身优化? 主要有 三个方面 的原因: (1)下载转化率 APK 瘦身优化在实际的项目中优先级是比较低的,因为做了之后它的好处不是那么明显,尤其是那些还没有到 稳定期 的项目,我们都知道,App 的发展历程是从 项目初期 => 成长期 => 稳定期,对于处于 发展初期与成长期 的项目而言,可能会做 启动优化、卡顿优化,但是一般不会做 瘦身优化,瘦身优化 最主要的好处是对应用 下载转化率 的影响,它是 App 业务运营的重要指标之一,在项目精细化运营的阶段是非常重要的。 因为如果你的 App 与其它同类型的 App 相比 Apk 体积要更小的话,那么你的 App

Android混淆打包

夙愿已清 提交于 2020-04-03 05:48:27
在这之前,看了下proguard官网介绍,并搜了下相关资料。 ProGuard简介 ProGuard是一个SourceForge上非常知名的开源项目。官网网址是:http://proguard.sourceforge.net/。 Java的字节码一般是非常容易反编译的。为了很好的保护Java源代码,我们往往会对编译好的class文件进行混淆处理。ProGuard的主要作用就是混淆。当然它还能对字节码进行缩减体积、优化等,但那些对于我们来说都算是次要的功能。 引用ProGuard官方的一段话来介绍就是: ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for

Progruard and R8 being deprecated - Android Studio 3.6

霸气de小男生 提交于 2020-03-21 12:00:55
问题 I'm getting deprecated warnings in regards to Proguard as well as R8 after upgrading my Android Studio to 3.6. Does that mean we shouldn't use obfuscation in our projects or is there another equivalent option we should consider while building in release mode? The option 'android.enableR8' is deprecated and should not be used anymore. It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8. Affected Modules: etc 回答1: Does that mean we

Progruard and R8 being deprecated - Android Studio 3.6

瘦欲@ 提交于 2020-03-21 12:00:34
问题 I'm getting deprecated warnings in regards to Proguard as well as R8 after upgrading my Android Studio to 3.6. Does that mean we shouldn't use obfuscation in our projects or is there another equivalent option we should consider while building in release mode? The option 'android.enableR8' is deprecated and should not be used anymore. It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8. Affected Modules: etc 回答1: Does that mean we

How to minify a Flutter app with Proguard?

元气小坏坏 提交于 2020-03-18 05:45:06
问题 I already made a Flutter app. The release apk is about 14MB. I searched methods to minify this and found this ons: https://flutter.io/android-release/#enabling-proguard But my question is, how can I get to know all my used additional libraries for step 1? Are there any commands to know them or is it just all the dependencies that I added to the pubspec.yaml ? How do I need to implement them in this file /android/app/proguard-rules.pro ? 回答1: First, we will enable shrinking and obfuscation in

Lint found fatal errors while assembling a release target. 问题的解决方案

旧巷老猫 提交于 2020-03-17 16:11:35
此问题发生在编译为 release 版本时,出现错误提示如下: Lint found fatal errors while assembling a release target. To proceed, either fix the issues identified by lint, or modify your build script as follows: ... android { lintOptions { checkReleaseBuilds false // Or, if you prefer, you can continue to check for errors in release builds, // but continue the build even when errors are found: abortOnError false } } ... 信他你就输了! 如果你真的去 build.gradle(app) 的 android{...} 中按照上述提示添加后,重新编译还遇到这个提示,请尝试按照以下方法解决: android { buildTypes { release { //在这里添加: lintOptions { checkReleaseBuilds false abortOnError false } minifyEnabled

Android ProGuard实例教程

Deadly 提交于 2020-03-09 04:30:35
ProGuard 工具通过移除不用的代码,用语义上混淆的名字来重命名类、字段和方法等手段来压缩、优化和混淆你的代码。结果是更小的.apk文件,并且更难于被反编译。由于ProGuard能够让你的程序难于被反编译,因此,当你的程序使用了一些机密的信息的时,使用它就显得更加重要。 ProGuard 已经集成到Android的编译环境中,因此,用不着手动来触发它。ProGuard只在release模式下编译应用程序才会运行,所以,在debug模式下编译,你就不必处理混淆的代码。是否运行ProGuard是完全可选的,但强烈推荐使用。 启用ProGuard 当你创建Android工程时,proguard.cfg文件会在工程的根目录自动创建。这个文件定义了ProGuard如何优化和混淆代码,因此,理解如何定制它是非常重要的。默认的配置文件只是覆盖了一些通用的情况,所以,基本上你需要编辑它来满足你的需求。参考后面的“配置ProGuard”章节来了解如何定制ProGuard的相关信息。 启用ProGuard让它跟随Ant或Eclipse编译时一起运行,你需要在<project_root>/default.properties文件中设置proguard.config属性。路径可以是绝对路径或是工程根目录的相对路径。 如果你把proguard.cfg文件放在默认的位置(工程的根目录)

Obfuscating Android app with CORBA

僤鯓⒐⒋嵵緔 提交于 2020-02-29 05:43:09
问题 It so fell out that I use jacorb.jar and CORBA interfaces in my android app. And when I try obfuscate code using Proguard I get a lot of warnings like this one: [proguard] Warning: org.jacorb.orb.standardInterceptors.SASComponentInterceptor: can't find referenced class org.ietf.jgss.Oid And as the result: [proguard] Warning: there were 1223 unresolved references to classes or interfaces. [proguard] You may need to specify additional library jars (using '-libraryjars'), [proguard] or perhaps

android 混淆配置

╄→尐↘猪︶ㄣ 提交于 2020-02-28 06:34:34
proguard 原理 Java代码编译成二进制class 文件,这个class 文件也可以反编译成源代码 ,除了注释外,原来的code 基本都可以看到。为了防止重要code 被泄露,我们往往需要混淆(Obfuscation code , 也就是把方法,字段,包和类这些java 元素的名称改成无意义的名称,这样代码结构没有变化,还可以运行,但是想弄懂代码的架构却很难。 proguard 就是这样的混淆工具,它可以分析一组class 的结构,根据用户的配置,然后把这些class 文件的可以混淆java 元素名混淆掉。在分析class 的同时,他还有其他两个功能,删除无效代码(Shrinking 收缩),和代码进行优化 (Optimization Options)。 缺省情况下,proguard 会混淆所有代码,但是下面几种情况是不能改变java 元素的名称,否则就会这样就会导致程序出错。 一, 我们用到反射的地方。 二, 我们代码依赖于系统的接口,比如被系统代码调用的回调方法,这种情况最复杂。 三, 是我们的java 元素名称是在配置文件中配置好的。 所以使用proguard时,我们需要有个配置文件告诉proguard 那些java 元素是不能混淆的。 proguard 配置 最常用的配置选项 -dontwarn 缺省proguard 会检查每一个引用是否正确

如何在构建Android应用程序的发布版本之前删除所有调试日志记录调用?

随声附和 提交于 2020-02-26 11:26:03
根据谷歌的说法, 在将 我的Android应用程序发布到Google Play之前,我必须“ 停用对源代码中任何Log方法的调用 ”。 摘录自 出版物清单的 第3部分: 在构建应用程序以进行发布之前,请确保停用日志记录并禁用调试选项。 您可以通过删除源文件中对Log方法的调用来停用日志记录。 我的开源项目很大,每次发布时手动执行都很痛苦。 此外,删除日志行可能很棘手,例如: if(condition) Log.d(LOG_TAG, "Something"); data.load(); data.show(); 如果我对日志行进行注释,则条件适用于下一行,并且可能不会调用load()。 这种情况是否足够罕见,我可以决定它不应该存在? 那么,是否有更好的源代码级方法呢? 或者可能有一些聪明的ProGuard语法可以有效但安全地删除所有日志行? #1楼 ProGuard将在您的发布版本上为您完成,现在来自android.com的好消息: http://developer.android.com/tools/help/proguard.html ProGuard工具通过删除未使用的代码并使用语义模糊的名称重命名类,字段和方法来缩小,优化和混淆代码。 结果是较小的.apk文件,更难以进行逆向工程。 由于ProGuard使您的应用程序更难以进行逆向工程,因此当您的应用程序使用对安全性敏感的功能