问题描述
它看起来像我用65K的限制DEX调情,
如果我写了一些新的方法,我有一个DEX的错误,如果我删除一些旧的东西,它消失了。
It looks like I'm flirting with the dex limit of 65K,if I write some new methods I have a dex error, if I remove some older things, it's gone.
有没有一种方法来检查你正在使用的Android Studio中?
Is there a way to check how many methods you are using at the moment in Android Studio?
推荐答案
我能找到一个脆弱的方式做到这一点,这也许是比没有办法要好。复制并粘贴以下到您的模块的的build.gradle 的文件,替换 ANDROID_HOME
与您的Android SDK安装的路径和<$ C的底$ C> BUILD_TOOLS_VERSION 在你的机器人
块 buildToolsVersion
规范指定的同一版本
I can find a fragile way to do it, which is maybe better than no way at all. Copy and paste the following to the bottom of your module's build.gradle file, replacing ANDROID_HOME
with the path of your Android SDK installation and BUILD_TOOLS_VERSION
with the same version specified in the buildToolsVersion
spec of your android
block:
buildscript {
dependencies {
classpath files("/Users/sbarta/sdk/build-tools/21.0.2/lib/dx.jar")
}
}
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
variant.assemble.doLast {
// Show the dex count after the assemble task is finished
showDexCount(
[filename: output.outputFile],
)
}
}
}
def showDexCount(Map... files) {
def maxReferences = (int) Math.pow(2, 16);
def buffer = 5000 // that's for safety, because you can't burn maxReferences
println "\n\n***********************************************************************************"
println "* DEX COUNTS *"
println "***********************************************************************************"
files.each {
def dex = new com.android.dex.Dex(it.filename)
def count = dex.tableOfContents.methodIds.size
if ((maxReferences - count - buffer) >= 0)
println String.format('* %1$5d (there are still %2$5d references to burn...) *',
count, maxReferences - count - buffer)
else
println String.format('* %1$5d !!!WARNING!!! Too many references, please decrease by %2$4d! *',
count, -(maxReferences - count - buffer))
}
println "***********************************************************************************\n"
}
这加载了DEX code本身来评价DEX文件和统计方法的数量;它增加了其工作的结束组装
任务生成脚本,所以你会看到它在命令行构建,或者如果你真正从Android Studio中运行(其中它会在摇篮控制台显示出来)。
This loads up the dex code itself to evaluate the dex files and count the number of methods; it adds its work to the end of the assemble
task in the build script, so you'll see it in command line builds or if you actually run it from Android Studio (where it will show up in the Gradle console).
我试图使它更具弹性,并使用需要你辛苦code中的路径,但使用环境变量在Android Studio生成时的ANDROID_HOME环境变量,而不是有问题(它在命令行工作虽然)。同样,我试图把它的构建工具的版本,从拉在它被引用的构建脚本的其他地方,我也试着定义一个全局常量,但不能使执行工作的范围和顺序。如果有人可以在此改善,请评论或编辑答案。
I tried to make it more resilient and use the ANDROID_HOME environment variable instead of requiring you to hardcode the path, but using environment variables when building from Android Studio is problematic (it works from the command line though). Similarly, I tried to have it pull in the build tools version from the other place in the build script where it's being referenced, and I also tried defining a global constant, but couldn't make the scoping and order of execution work. If someone can improve on this, please comment or edit the answer.
这是由卡洛斯·Sobrinho写的东西适应;我找不到一个可以通过Web访问参照原文。
This is adapted from something written by Carlos Sobrinho; I can't find a Web-accessible reference to the original.
这篇关于检查你有多少方法在Android的工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!