Android 64k 方法限制错误 56k 方法 [英] Android 64k method limit error on 56k methods

查看:20
本文介绍了Android 64k 方法限制错误 56k 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 android 项目中收到此错误:

I'm receiving this error in my android project:

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 方法.这里是我正在运行的脚本.

From all my research it's due to having too many methods in my android project - limit is 64k. However I have run scripts to count how many is currently in the project and it is coming up with 56k methods. Here is the script I am running.

我的项目唯一的补充是我将 Parse 从 1.4 更新到 1.7.

The only addition to my project is that I have updated Parse from 1.4 to 1.7.

更新解析后构建和编译的项目,但是当我尝试添加任何新代码时出现此错误.

The project built and compiled after updating parse, but when I try to add any new code this error appears.

当我第一次遇到这个错误时,我使用的是 Android Studio 0.8.9.我已经恢复到 Android Studio 0.8.6 并且它仍在发生.

I was using Android Studio 0.8.9 when I first encountered this error. I have reverted back to Android Studio 0.8.6 and it is still occurring.

推荐答案

我用这段代码解决了这个问题,我的问题是 google play 服务将我的应用推到了限制之上.这将删除您的应用不需要的 google play 服务.把它放在你的 gradle 构建文件的底部

I resolved this issue with this code, my problem is that google play services push my app over the limit. This removes the google play services that you app does not need. Put it at the bottom of your gradle build file

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
}
}

这篇关于Android 64k 方法限制错误 56k 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆