我在我的android项目中收到此错误:
Unable to execute dex: method ID not in [0, 0xffff]: 65536
Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
从我的所有研究来看,这是由于我的android项目中有太多方法 - 限制为64k。但是我运行脚本来计算当前项目中有多少,并且它提出了56k方法。 Here是我正在运行的脚本。
我项目的唯一补充是我已经将Parse从1.4更新到1.7。
在更新解析后构建和编译项目,但是当我尝试添加任何新代码时,会出现此错误。
我第一次遇到此错误时使用的是Android Studio 0.8.9。我已经恢复到Android Studio 0.8.6并且它仍在发生。
答案 0 :(得分:5)
我使用此代码解决了这个问题,我的问题是Google Play服务推动我的应用程序超过限制。这会删除您应用不需要的Google Play服务。将它放在gradle构建文件的底部
def toCamelCase(String string) {
String result = ""
string.findAll("[^\\W]+") { String word ->
result += word.capitalize()
}
return result
}
afterEvaluate { project ->
Configuration runtimeConfiguration = project.configurations.getByName('compile')
ResolutionResult resolution = runtimeConfiguration.incoming.resolutionResult
// Forces resolve of configuration
ModuleVersionIdentifier module = resolution.getAllComponents().find { it.moduleVersion.name.equals("play-services") }.moduleVersion
String prepareTaskName = "prepare${toCamelCase("${module.group} ${module.name} ${module.version}")}Library"
File playServiceRootFolder = project.tasks.find { it.name.equals(prepareTaskName) }.explodedDir
Task stripPlayServices = project.tasks.create(name: 'stripPlayServices', group: "Strip") {
inputs.files new File(playServiceRootFolder, "classes.jar")
outputs.dir playServiceRootFolder
description 'Strip useless packages from Google Play Services library to avoid reaching dex limit'
doLast {
copy {
from(file(new File(playServiceRootFolder, "classes.jar")))
into(file(playServiceRootFolder))
rename { fileName ->
fileName = "classes_orig.jar"
}
}
tasks.create(name: "stripPlayServices" + module.version, type: Jar) {
destinationDir = playServiceRootFolder
archiveName = "classes.jar"
from(zipTree(new File(playServiceRootFolder, "classes_orig.jar"))) {
exclude "com/google/ads/**"
exclude "com/google/android/gms/analytics/**"
exclude "com/google/android/gms/games/**"
exclude "com/google/android/gms/plus/**"
exclude "com/google/android/gms/drive/**"
exclude "com/google/android/gms/ads/**"
}
}.execute()
delete file(new File(playServiceRootFolder, "classes_orig.jar"))
}
}
project.tasks.findAll { it.name.startsWith('prepare') && it.name.endsWith('Dependencies') }.each { Task task ->
task.dependsOn stripPlayServices
}
}
答案 1 :(得分:2)
您现在只能导入您使用的Google Play服务。这节省了很多方法。
如果您只使用GCM,那么您只需要 com.google.android.gms:玩服务-GCM:7.5.0
答案 2 :(得分:0)
你在使用混淆吗? Proguard可以删除未使用的方法,因此您将符合限制。 此外,您可以将项目拆分为模块。 65k限制是每个dex文件,模块是单独的dex文件。
您还可以将Proguard配置为内联短方法 - 但应删除大量简短方法。
有关详细信息,请参阅http://fuzzproductions.com/news/the-mythical-android-method-limit-solved和How to solve the issue with Dalvik compiler limitation on 64K methods?。
答案 3 :(得分:0)
您可能需要查看新的MultiDex支持库。
http://blog.osom.info/2014/10/multi-dex-to-rescue-from-infamous-65536.html
答案 4 :(得分:0)
当您更新谷歌播放服务时问题会上升所以不是添加整个播放服务安卓工作室提供了一种方法来为项目添加特定的api Reference它会减少你的方法