我正在一个项目中工作,我正在使用多个图书馆,如google play service,retrofit,gson,glide,twitter和facebook sdk。所以我想知道每个库的确切大小在我的应用程序中占用。请帮助我是否有任何可能的方法来分析Android工作室的大小。任何针对我的要求的工具建议或提示对我都非常有帮助。我发布了我在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'
注意:我正在分析此报告,以便通过删除占用大量内存的库来减少应用程序的apk大小。
过去几天我完全坚持这个解决方案。我甚至搜索了很多,我无法找到优化的方法来计算项目中库的确切大小用法。
请帮忙。提前谢谢。
答案 0 :(得分:5)
不确定这是你正在寻找的东西,但这可能会有所帮助:
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排序。
答案 1 :(得分:4)
最简单的方法是使用名为http://www.methodscount.com/的网站,您只需粘贴编译语句,即可获得有关它的所有大小详细信息。
示例,如果我将 com.github.paolorotolo:appintro:4.1.0 粘贴到其中,那么我得到这个结果:
它不适用于少数几个库,但对于大多数情况,它确实是Job。
答案 2 :(得分:3)
task (depsize) << {
def size = 0;
configurations._debugApk.collect { it.length() / (1024 * 1024) }.each { size += it }
println "Total dependencies size: ${Math.round(size * 100) / 100} Mb"
configurations
._debugApk
.sort { -it.length() }
.each { println "${it.name} : ${Math.round(it.length() / (1024) * 100) / 100} kb" }
}
尝试将此项放入您的app模块gradle.build中,然后您可以直接通过gradle运行。如果你想看到所有可能的配置添加:
configurations
.findAll()
.each { println "${it.name}" }