统计 apk 方法数和代码行数小工具
来源:互联网 发布:java迷宫收集金币 编辑:程序博客网 时间:2024/05/06 06:11
转载请注明出处:
http://blog.csdn.net/BruceHurrican/article/details/62419115
商业 app, 随着业务不停的迭代后,app 体积会由最初的几 M 增加到几十至上百 M,过大的安装包,不利于用户下载安装,那么 apk 瘦身就会被提上日程。
本篇文章不会详细介绍怎样瘦身,这里我向大家推荐的两款工具意在于帮助开发人员直观看到apk 中方法数量,代码行数。
tool 1:
statistic 插件,安装方法 AS Preferences-Plugins-Browse repositories 搜索 statistic 安装完毕后重启 AS,
打开自己的工程后,在最下方的功能栏中会出现新的一栏 “statistic” ,点击”Refresh”按钮后在 “Java”一项中就可以看到当前工程的代码行数,以我写的 demo 为例
java 代码共计12822行,以 App.java 文件来说,总共35行,源码行数为4,注释行数为27,注释比为77%,空白行为4行,占比11%。
我知道国内有的公司在代码上会有硬性规定,比如为了保证代码的质量规定代码的注释率必须要达到多少。相信不少人都碰到过1个 java 文件上千行代码,一句注释都没有,接手者维护时,心中也是万千羊驼在奔跑吧。有了上面的工具,就可以直观地了解到,你的代码是不是让别人很容易看的懂的代码。
tool 2:
classyshark google 出品,用来统计 apk,jar 包中的方法数。这款工具有两个版本, 一个是 GUI的,跨平台,另一个是android 版的。不过 android 版本的 apk 没有 GUI的好用。
从饼图中可以直观的看到当前 apk 中各方法数占比。
tool 3:
dex-method-counts, 通过命令行的方式统计 apk 中的方法数
默认的按包名分类统计方法数。
注意:
dex-method-count获取到的方法数和 classyshark 获取的方法数是不一样的,前者获取的方法数是 apk 中所有的方法数,classyshark 获取的方法数是开发者自己定义的方法数和引用的第三方库中的方法数,不包括 android.jar中的方法。
根据官方文档
Figure 4 depicts a medium-size app approaching the 64k DEX limit. Each package, class, and method includes counts listed in the Defined Method and Referenced Method columns. The Referenced Methods column counts all methods that are referenced by the DEX file. This typically includes methods defined in your code, dependency libraries, and methods defined in standard Java and Android packages that the code uses—these are the methods counted toward the 64k method limit in each DEX file. The Defined Methods column counts only the methods that are defined in one of your DEX files, so this number is a subset of Referenced Methods. Note that when you package a dependency in your APK, the methods defined in the dependency add to both method counts. Also note that minification and/or Proguard shrinking can also considerably change the contents of a DEX file after source code is compiled.
大致意思是,dex 中的方法数包括 开发者定义的和方法和引用方法,即 define methods 和 reference methods,classyshark 统计到的方法数即为 define methods,dex-method-count统计的方法数为 reference methods。64K的限制是针对 reference methods 的。
这两个数值和 AS 2.2+版本后增加的功能 Analyze APK中获取的值是一致的。
传送门
classyshark
dex-method-count
Analyze APK 官方说明
- 统计 apk 方法数和代码行数小工具
- [小工具]代码统计小工具编写
- 【小工具】通过命令行获得代码行数
- 代码量统计小工具V1.0
- 原创小工具:PHP有效代码行数计算器
- Xcode---代码行数统计方法
- 代码美化/统计/工程清理小工具CodeHelper
- 利用java小工具-----统计项目代码量
- Python小工具——统计文件夹下源代码的行数
- Android统计APK方法数
- Android APK 反编译小工具
- 代码小工具
- 小工具初始代码
- 【工具】统计jar包和apk中的java方法数
- 统计Android apk和jar的方法数
- 统计jar包和apk中的java方法数
- 统计apk文件和jar包中的方法数
- 统计单词个数小工具
- LK thread_detach处理
- vi颜色设置
- union-find算法(java实现)
- 画圆
- 我的Android日记(2)
- 统计 apk 方法数和代码行数小工具
- Linux下openGL编程
- 找到很好的一篇关于二叉树三种遍历的博客
- HTML5基础加强css样式篇(css过渡属性简写,cubic-bezier过度曲线函数使用)(二十)
- FishC笔记—27 讲 集合:在我的世界里,你就是唯一!
- lk thread_resume
- org.springframework.data.domain.PageRequest
- 深入理解Android之Gradle
- 全国建筑楼块矢量数据参数详解