【发布时间】:2016-07-05 20:03:11
【问题描述】:
每当我按项目构建并准备在我的设备上启动时,我都会不断收到此错误:
错误:.dex 文件中的方法引用数不能超过 64K。 通过https://developer.android.com/tools/building/multidex.html了解如何解决此问题
另外,我得到这个错误:
错误:任务 ':app:transformClassesWithDexForDebug' 执行失败。 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:com.android.ide.common.process.ProcessException:org.gradle.process。 internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' 以非零退出值 2 结束
它说 gradle build 失败并出现两个错误
所以我有一些问题:
- 什么是 dex 文件
- 我没有直接使用它们,为什么会出现上述错误?
- dex 文件中有什么?
- 这些文件对 .APK 文件的大小有什么影响吗?
在我停止使用 proguard 进行调试构建后,这些错误又开始出现,因为 StackTrace 没有显示,并且在我激活 proguard 之前我遇到了错误。
我之前遇到过这个错误,我删除了 dex 文件夹并解决了它,但现在它突然变得不够了。
我的 gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.myproject"
minSdkVersion 15
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.google.android.gms:play-services:9.2.0'
compile 'com.google.android.gms:play-services-ads:9.2.0'
}
【问题讨论】:
-
您应该永远使用完整的
play-services依赖项。仅使用select Play services APIs you need。包括整个东西是 64k 方法限制的 45k+。
标签: java android gradle dalvik dex