生成APK时出现Android Dex错误
我在尝试构建APK时遇到以下错误。我读过几篇关于如何解决这个问题的帖子,但由于我没有开发那么长时间,我不确定我在做什么。所以,希望有人能帮忙生成APK时出现Android Dex错误,android,gradle,apk,dex,Android,Gradle,Apk,Dex,我在尝试构建APK时遇到以下错误。我读过几篇关于如何解决这个问题的帖子,但由于我没有开发那么长时间,我不确定我在做什么。所以,希望有人能帮忙 Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessExceptio
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
这是我的build.gradle(模块)
这是我的build.gradle项目
/ Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
如果有人能帮忙,我将不胜感激,同时也请记住我有点经验不足。使用它:
android{
defaultConfig {
multiDexEnabled true
}
}
也要使用它
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
您需要启用多索引,请将此行添加到defaultConfig:
multiDexEnabled true
这一行与您的依赖项相关:
compile 'com.android.support:multidex:1.0.1'
此外,在运行单元测试时,需要创建一个扩展应用程序的类并安装MultiDex:
public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
在模块级渐变中使用此块: dexOptions{ javaMaxHeapSize“4g” } 并在清单中将应用程序名称更改为.multidex。
希望您的代码现在可以正常工作您必须启用multidex,因为您的方法超过65536个,或者您可以简单地将play services库替换为所需的工具,如ad etcEnable,谢谢。你的意思是将defaultConfig{multiDexEnabled true}放在依赖项{compile'com.android.support:multidex:1.0.1'}中,就像这样依赖项{defaultConfig{multiDexEnabled true}编译文件树(dir:'libs',include:['*.jar'])androidTestCompile('com.android.support.test.espresso:espresso核心:2.2',{排除组:'com.android.support',模块:'support annotations'})编译'com.android.support:appcompat-v7:25.1.0'compile'com.google.android.gms:play services:10.0.1'testCompile'junit:junit:4.12'}谢谢。build.gradle(模块)文件中的defaultConfig在哪里。
public class YouApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}