Android Studio 1.0 在 dexDebug 或 dexRelease 构建失败 [英] Android Studio 1.0 failing build at dexDebug or dexRelease

查看:23
本文介绍了Android Studio 1.0 在 dexDebug 或 dexRelease 构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近从 Android Studio 0.9.2 升级到 1.0(包括 Gradle 插件的 1.0.0 版),但我在构建项目时遇到了问题.

I recently upgraded from Android Studio 0.9.2 to 1.0 (including version 1.0.0 of the Gradle plugin) and I'm having an issue with building my project.

每当我构建时,我都会在 dexDebug 或 dexRelease 步骤中收到以下异常:

Whenever I build I get the following exception at the dexDebug or dexRelease step:

UNEXPECTED TOP-LEVEL ERROR:
    java.lang.OutOfMemoryError: GC overhead limit exceeded
        at java.util.HashMap.createEntry(HashMap.java:897)
        at java.util.HashMap.addEntry(HashMap.java:884)
        at java.util.HashMap.put(HashMap.java:505)
        at com.android.dx.rop.type.Type.putIntern(Type.java:857)
        at com.android.dx.rop.type.Type.intern(Type.java:365)
        at com.android.dx.rop.type.Type.internClassName(Type.java:415)
        at com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:289)
        at com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:299)
        at com.android.dx.cf.cst.ConstantPoolParser.parse(ConstantPoolParser.java:150)
        at com.android.dx.cf.cst.ConstantPoolParser.parseIfNecessary(ConstantPoolParser.java:124)
        at com.android.dx.cf.cst.ConstantPoolParser.getPool(ConstantPoolParser.java:115)
        at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:482)
        at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
        at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
        at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
        at com.android.dx.command.dexer.Main.processClass(Main.java:704)
        at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
        at com.android.dx.command.dexer.Main.access$300(Main.java:82)
        at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
        at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
        at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
        at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
        at com.android.dx.command.dexer.Main.processOne(Main.java:632)
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
        at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332)
        at com.android.dx.command.dexer.Main.run(Main.java:243)
        at com.android.dx.command.dexer.Main.main(Main.java:214)
        at com.android.dx.command.Main.main(Main.java:106)

我尝试将 Android Studio 的堆大小增加到 -Xmx4096m 但无济于事.在 Android Studio 0.9.2 和 0.14 版本的 gradle 插件构建中运行良好.

I tried increasing the heap size of Android Studio to -Xmx4096m but to no avail. In Android Studio 0.9.2 with version 0.14 of the gradle plugin building worked fine.

这是我项目的 build.gradle 文件:

This is the build.gradle file of my project:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
    }
}

这是我的模块的 build.gradle 文件:

And this is the build.gradle file of my module:

apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.android.support:multidex:1.+'
    compile 'com.google.android.gms:play-services:6.5.+'
    compile 'org.jsoup:jsoup:1.8.+'
    compile 'commons-io:commons-io:2.4'
    compile 'org.apache.commons:commons-lang3:3.3.2'
    compile 'com.rometools:rome:1.5.0'
    compile 'com.google.apis:google-api-services-blogger:v3-rev44-1.19.0'
    compile 'com.google.http-client:google-http-client-gson:1.19.0'
    compile 'org.apache.commons:commons-collections4:4.0'
    compile 'com.parse.bolts:bolts-android:1.1.2'
    compile files('libs/android-query.0.26.8.jar')
    compile files('libs/Parse-1.7.1.jar')
}

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"
    defaultConfig {
        // Enabling multidex support.
        multiDexEnabled true
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 1040009
        versionName "1.4"

    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-dcrapp.txt'
            shrinkResources true
        }

        debug {
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-dcrapp.txt'
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }


        //Bugfix for Gradle build bug
        packagingOptions {
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

task copyMappingFiles(type: Copy)

copyMappingFiles {
    from 'build\\outputs\\mapping\\release'
    into 'mappings\\'+android.defaultConfig.versionCode
    include('mapping.txt')
}

assembleRelease.finalizedBy copyProguardFiles

此问题的原因可能是什么,如何解决?

What could be the cause of this issue and how can it be solved?

推荐答案

看起来Android Studio内存不足,尝试在AndroidStudio.app/Contents/bin/studio.vmoptions中增加内存大小

Looks like Android Studio ran out of memory, try increasing the memory size in AndroidStudio.app/Contents/bin/studio.vmoptions

-Xms256m
-Xmx1024m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=96m
-XX:+UseCompressedOops

根据 Android Studio - How to increase Allocated堆大小

另外你可能想添加

dexOptions {
    javaMaxHeapSize "4g"
}

根据 Android 到您的模块 build.gradleStudio Google JAR 文件导致 GC 开销限制超出错误

这篇关于Android Studio 1.0 在 dexDebug 或 dexRelease 构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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