Android Studios RuntimeException:dex writer 线程中出现意外异常 [英] Android Studios RuntimeException: Unexpected exception in dex writer thread

查看:28
本文介绍了Android Studios RuntimeException:dex writer 线程中出现意外异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天一整天都在收到这个奇怪的错误——有人知道这里出了什么问题吗?

据我所知,我一直在正确使用 multidex 库(以下来自 app.gradle 文件):

defaultConfig {applicationId "com.example.simon"minSdk 版本 14目标SDK版本23版本代码 1版本名称1.0"/*启用多索引*/multiDexEnabled true}依赖{/* 启用多索引*/编译'com.android.support:multidex:1.0.1'}

我的顶级 gradle 文件非常基础:

buildscript {存储库{jcenter()}依赖{类路径 'com.android.tools.build:gradle:1.3.0'类路径 'com.google.gms:google-services:1.3.1'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{jcenter()}}

错误:

 执行任务:[:app:generateDebugSources,:app:generateDebugAndroidTestSources]按需配置的并行执行是一种孵化特征.:app:preBuild 最新:app:preDebugBuild 最新:app:checkDebugManifest:app:preReleaseBuild 最新:app:prepareComAndroidSupportAppcompatV72301库更新:app:prepareComAndroidSupportCardviewV72301库更新:app:prepareComAndroidSupportDesign2301Library 最新:app:prepareComAndroidSupportMultidex101Library 最新:app:prepareComAndroidSupportPaletteV72301库更新:app:prepareComAndroidSupportRecyclerviewV72301图书馆最新:app:prepareComAndroidSupportSupportV42301Library 最新:app:prepareComDigitsSdkAndroidDigits162Library 最新:app:prepareComFacebookAndroidFacebookAndroidSdk440Library 最新:app:prepareComFacebookConcealConceal101Library 最新:app:prepareComGithubCurioustechizenAndroidAgoLibrary130Library 最新:app:prepareComGoogleAndroidGmsPlayServicesAppinvite780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesBase780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesGcm780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesLocation780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesMaps780Library 最新:app:prepareComTheartofdevEdmodoAndroidImageCropper104Library 最新:app:prepareComTwitterSdkAndroidTweetComposer080Library 最新:app:prepareComTwitterSdkAndroidTweetUi131Library 最新:app:prepareComTwitterSdkAndroidTwitter161Library 最新:app:prepareComTwitterSdkAndroidTwitterCore141Library 最新:app:prepareIoFabricSdkAndroidFabric134Library 最新:app:prepareDebugDependencies:app:compileDebugAidl 最新:app:compileDebugRenderscript 最新:app:generateDebugBuildConfig 最新:app:generateDebugAssets 最新:app:mergeDebugAssets 最新:app:generateDebugResValues 最新:app:processDebugGoogleServices:app:generateDebugResources:app:mergeDebugResources 最新:app:processDebugManifest 最新:app:fabricGenerateResourcesDebug:app:processDebugResources:app:generateDebugSources:app:preDebugAndroidTestBuild 最新:app:prepareDebugAndroidTestDependencies:app:compileDebugAndroidTestAidl 最新:app:processDebugAndroidTestManifest 最新:app:compileDebugAndroidTestRenderscript 最新:app:generateDebugAndroidTestBuildConfig 最新:app:generateDebugAndroidTestAssets 最新:app:mergeDebugAndroidTestAssets 最新:app:generateDebugAndroidTestResValues 最新:app:generateDebugAndroidTestResources 最新:app:mergeDebugAndroidTestResources 最新:app:processDebugAndroidTestResources 最新:app:generateDebugAndroidTestSources 最新建造成功总时间:3.913 秒执行任务:[:app:assembleDebug]按需配置的并行执行是一种孵化特征.:app:preBuild 最新:app:preDebugBuild 最新:app:checkDebugManifest:app:preReleaseBuild 最新:app:prepareComAndroidSupportAppcompatV72301库更新:app:prepareComAndroidSupportCardviewV72301库更新:app:prepareComAndroidSupportDesign2301Library 最新:app:prepareComAndroidSupportMultidex101Library 最新:app:prepareComAndroidSupportPaletteV72301库更新:app:prepareComAndroidSupportRecyclerviewV72301图书馆最新:app:prepareComAndroidSupportSupportV42301Library 最新:app:prepareComDigitsSdkAndroidDigits162Library 最新:app:prepareComFacebookAndroidFacebookAndroidSdk440Library 最新:app:prepareComGithubCurioustechizenAndroidAgoLibrary130Library 最新:app:prepareComGoogleAndroidGmsPlayServicesAppinvite780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesBase780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesGcm780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesLocation780Library 最新:app:prepareComGoogleAndroidGmsPlayServicesMaps780Library 最新:app:prepareComTheartofdevEdmodoAndroidImageCropper104Library:app:prepareDebugDependencies:app:compileDebugAidl 最新:app:compileDebugRenderscript 最新:app:generateDebugBuildConfig 最新:app:generateDebugAssets 最新:app:mergeDebugAssets 最新:app:generateDebugResValues 最新:app:processDebugGoogleServices:app:generateDebugResources:app:mergeDebugResources 最新:app:processDebugManifest 最新:app:fabricGenerateResourcesDebug:app:processDebugResources:app:generateDebugSources:app:processDebugJavaRes 最新:app:compileDebugJavaWithJavac 最新:app:compileDebugNdk 最新:app:compileDebugSources 最新:app:collectDebugMultiDexComponents 最新:app:packageAllDebugClassesForMultiDex 最新:app:shrinkDebugMultiDexComponents 最新:app:createDebugMainDexClassList 最新:app:dexDebugExecuting任务:[:app:assembleDebug]按需配置的并行执行是一种孵化特征.:app:preBuild 最新:app:preDebugBuild 最新:app:checkDebugManifest:app:preReleaseBuild 最新:app:prepareComAndroidSupportAppcompatV72301库更新:app:prepareComAndroidSupportCardviewV72301库更新:app:prepareComAndroidSupportDesign2301Library 最新:app:prepareComAndroidSupportMultidex101Library 最新:app:prepareComAndroidSupportPaletteV72301库更新:app:prepareComAndroidSupportRecyclerviewV72301图书馆最新:app:prepareComAndroidSupportSupportV42301Library 最新:app:prepareComDigitsSdkAndroidDigits162Library 最新:app:prepareDebugDependencies:app:compileDebugAidl 最新:app:compileDebugRenderscript 最新:app:generateDebugBuildConfig 最新:app:generateDebugAssets 最新:app:mergeDebugAssets 最新:app:generateDebugResValues 最新:app:processDebugGoogleServices:app:generateDebugResources:app:mergeDebugResources 最新:app:processDebugManifest 最新:app:fabricGenerateResourcesDebug:app:processDebugResources:app:generateDebugSources:app:processDebugJavaRes 最新:app:compileDebugJavaWithJavac 最新:app:compileDebugNdk 最新:app:compileDebugSources 最新:app:collectDebugMultiDexComponents 最新:app:packageAllDebugClassesForMultiDex 最新:app:shrinkDebugMultiDexComponents 最新:app:createDebugMainDexClassList 最新:app:dexDebug AGPBI:{"kind":"simple","text":"意外的顶级例外:","sources":[{}]} AGPBI:{"kind":"simple","text":"java.lang.RuntimeException: 意外dex writer 线程中的异常","sources":[{}]} AGPBI:{"kind":"simple","text":"\tatcom.android.dx.command.dexer.Main.runMultiDex(Main.java:397)","sources":[{}]}AGPBI: {"kind":"simple","text":"\tatcom.android.dx.command.dexer.Main.run(Main.java:275)","sources":[{}]}AGPBI: {"kind":"simple","text":"\tatcom.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]}AGPBI: {"kind":"simple","text":"\tatcom.android.dx.command.Main.main(Main.java:106)","sources":[{}]}失败的FAILURE:构建失败,出现异常.* 出了什么问题:任务 ':app:dexDebug' 执行失败.com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command'C:\Program Files\Java\jdk1.7.0_76\bin\java.exe'' 完成非零退出值 2* 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪.使用 --info 或 --debug 选项运行以获得更多日志输出.构建失败总时间:1 分 5.426 秒

解决方案

google了一会儿,发现问题是没有足够的heap分配给dex writer.

我通过在我的应用程序 gradle.build 中放入以下内容来修复它:

android {dexOptions {增量真javaMaxHeapSize "4g"}}

这个选项还显着加快了我的 gradle 构建速度.

使用 Gradle (Android Studio) 进行超长构建>

I have been getting this strange error the whole of today - anyone know what is going wrong here?

As far as I know, I have been using the multidex library correctly (the below is from the app.gradle file):

defaultConfig {
    applicationId "com.example.simon"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    /*Enabling multidex*/
    multiDexEnabled true
}

dependencies {
    /*    Enabling multidex*/
    compile 'com.android.support:multidex:1.0.1'
}

My top level gradle file is very basic:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.google.gms:google-services:1.3.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Error:

    Executing tasks: [:app:generateDebugSources,
:app:generateDebugAndroidTestSources]

Parallel execution with configuration on demand is an incubating
feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2301Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportPaletteV72301Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:app:prepareComDigitsSdkAndroidDigits162Library UP-TO-DATE
:app:prepareComFacebookAndroidFacebookAndroidSdk440Library UP-TO-DATE
:app:prepareComFacebookConcealConceal101Library UP-TO-DATE
:app:prepareComGithubCurioustechizenAndroidAgoLibrary130Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps780Library UP-TO-DATE
:app:prepareComTheartofdevEdmodoAndroidImageCropper104Library UP-TO-DATE
:app:prepareComTwitterSdkAndroidTweetComposer080Library UP-TO-DATE
:app:prepareComTwitterSdkAndroidTweetUi131Library UP-TO-DATE
:app:prepareComTwitterSdkAndroidTwitter161Library UP-TO-DATE
:app:prepareComTwitterSdkAndroidTwitterCore141Library UP-TO-DATE
:app:prepareIoFabricSdkAndroidFabric134Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
:app:generateDebugResources
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:fabricGenerateResourcesDebug
:app:processDebugResources
:app:generateDebugSources
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest UP-TO-DATE
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources UP-TO-DATE
:app:processDebugAndroidTestResources UP-TO-DATE
:app:generateDebugAndroidTestSources UP-TO-DATE

BUILD SUCCESSFUL

Total time: 3.913 secs Executing tasks: [:app:assembleDebug]

Parallel execution with configuration on demand is an incubating
feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2301Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportPaletteV72301Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:app:prepareComDigitsSdkAndroidDigits162Library UP-TO-DATE
:app:prepareComFacebookAndroidFacebookAndroidSdk440Library UP-TO-DATE
:app:prepareComGithubCurioustechizenAndroidAgoLibrary130Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation780Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps780Library UP-TO-DATE
:app:prepareComTheartofdevEdmodoAndroidImageCropper104Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
:app:generateDebugResources
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:fabricGenerateResourcesDebug
:app:processDebugResources
:app:generateDebugSources
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:collectDebugMultiDexComponents UP-TO-DATE
:app:packageAllDebugClassesForMultiDex UP-TO-DATE
:app:shrinkDebugMultiDexComponents UP-TO-DATE
:app:createDebugMainDexClassList UP-TO-DATE
:app:dexDebugExecuting
tasks: [:app:assembleDebug]

Parallel execution with configuration on demand is an incubating
feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2301Library UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportPaletteV72301Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72301Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:app:prepareComDigitsSdkAndroidDigits162Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
:app:generateDebugResources
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:fabricGenerateResourcesDebug
:app:processDebugResources
:app:generateDebugSources
:app:processDebugJavaRes UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:collectDebugMultiDexComponents UP-TO-DATE
:app:packageAllDebugClassesForMultiDex UP-TO-DATE
:app:shrinkDebugMultiDexComponents UP-TO-DATE
:app:createDebugMainDexClassList UP-TO-DATE
:app:dexDebug AGPBI:
{"kind":"simple","text":"UNEXPECTED TOP-LEVEL
EXCEPTION:","sources":[{}]} AGPBI:
{"kind":"simple","text":"java.lang.RuntimeException: Unexpected
exception in dex writer thread","sources":[{}]} AGPBI:
{"kind":"simple","text":"\tat
com.android.dx.command.dexer.Main.runMultiDex(Main.java:397)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat
com.android.dx.command.dexer.Main.run(Main.java:275)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat
com.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat
com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
'C:\Program Files\Java\jdk1.7.0_76\bin\java.exe'' finished with
non-zero exit value 2

* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 5.426 secs

解决方案

After googling for a while, I found the problem was that not enough heap was allocated to the dex writer.

I fixed it by putting in the following in my app gradle.build:

android {
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}

This option also managed to speed up my gradle build significantly.

Extremely long build with Gradle (Android Studio)

这篇关于Android Studios RuntimeException:dex writer 线程中出现意外异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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