当前位置: 首页 > 知识库问答 >
问题:

Android Studio 1.0无法在dexDebug或dexRelease上构建

蓬祺
2023-03-14

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

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

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 Studio0.9.2和版本0.14的gradle插件构建工作良好。

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

// 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文件:

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

这一问题的原因是什么?如何解决?

共有1个答案

仇炜
2023-03-14

似乎Android Studio内存不足,请尝试在androidstudio.app/contents/bin/Studio.vmoptions中增加内存大小

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

根据Android Studio中的答案建议-如何增加分配的堆大小

此外,您可能要添加

dexOptions {
    javaMaxHeapSize "4g"
}

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

 类似资料:
  • 我正在尝试安装JNetPcap,并按照此处给出的说明进行操作。在步骤12,我无法运行ant命令,我看到了错误 因为我能够从eclipse或命令行运行Java类,所以我不认为这是的问题。 echo$路径显示 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/b

  • 请告诉我如何解决这个问题。我更新了Xamarin表单dll。 我得到以下错误: 错误错误:找不到符号专用本机void n\u onInflate(android.support.v7.widget.ViewStubCompat p0,android.view.view p1);符号:class ViewStubCompat位置:package android。支持v7.widget obj\Deb

  • 我试图在乌班图12.06上安装opencv(3.1.0)。此错误是什么意思?是否第二次观察到开放 CV 模块?我该如何修复它? 环境变量设置 cmake/opencvModule.cmake处出现CMake错误:268(消息):< br >再次观察到目录/home/user/bin/opencv/modules中有OpenCV模块。< br >调用堆栈(最近的调用优先):< br > module

  • 问题内容: 很长时间以来,我一直在从事与离子相关的项目。 最近,我更新了android studio及其软件包,由于以下问题,我现在无法在android上进行构建: com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / google / android / gms / iid

  • 几天前我更新了我的Google SDK,现在我无法构建google-play-services_lib。发布“ant版本”后,我得到以下stacktrac: 构建失败/home/abc/Java/android sdk/tools/ant/BUILD。xml:649:执行此行时发生以下错误: /home/ABC/Java/Android-SDK/tools/ant/build . XML:694: