我正在一个项目中使用多个库,例如 google play service、retrofit、gson、glide、twitter 和 facebook sdk。所以我想知道每个库在我的应用程序中占用的确切大小。请帮助我是否有任何可能的方法来分析 Android studio 中的大小。任何适合我的要求的工具建议或提示都会对我非常有帮助。我正在发布我正在使用的依赖项build.gradle
如下。
compile('com.twitter.sdk.android:twitter:1.9.0@aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.android.support:support-v4:23.2.0'
Note:我正在分析此报告,以便通过删除占用大量内存的库来减少应用程序的 apk 大小。
在过去的几天里,我完全被这个解决方案所困扰。我什至搜索了很多,但找不到优化的方法来计算项目中库的确切大小使用情况。
请帮忙。提前致谢。
不确定这是否是您正在寻找的东西,但这可能会有所帮助:
task depsize {
doLast {
final formatStr = "%,10.2f"
final conf = configurations.default
final size = conf.collect { it.length() / (1024 * 1024) }.sum()
final out = new StringBuffer()
out << 'Total dependencies size:'.padRight(45)
out << "${String.format(formatStr, size)} Mb\n\n"
conf.sort { -it.length() }
.each {
out << "${it.name}".padRight(45)
out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
}
println(out)
}
}
该任务打印出所有依赖项的总和,并以 kb 为单位打印它们,按大小 desc 排序。
更新版本,兼容Gradle 5+
tasks.register("depsize") {
def formatStr = "%,10.2f"
def size = configurations.default.collect { it.length() / (1024 * 1024) }.sum()
def out = new StringBuffer()
out << 'Total dependencies size:'.padRight(45)
out << "${String.format(formatStr, size)} Mb\n\n"
configurations
.default
.sort { -it.length() }
.each {
out << "${it.name}".padRight(45)
out << "${String.format(formatStr, (it.length() / 1024))} kb\n"
}
println(out)
}
更新#2:最新版本的任务代码可以在github要点 https://gist.github.com/medvedev/968119d7786966d9ed4442ae17aca279
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)