Android Studio 2.1.2中使用Gradle dexoption的OutofMemory错误异常

时间:2016-08-04 12:44:50

标签: android android-studio

我的应用程序中存在outofmemory异常错误。我在app的build.gradle中添加了这个dexoptions代码,如下所示,但它不会起作用。

 apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
        useLibrary  'org.apache.http.legacy'


        defaultConfig {
            applicationId "Package name"
            minSdkVersion 16
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"

            multiDexEnabled true

        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        sourceSets {
            main.java.srcDirs += 'src/main/facebooka'
        }

        dexOptions {
            incremental = true;
            preDexLibraries = false
            javaMaxHeapSize "2g" // 2g should be also OK
        }
       /* dexOptions
                {
                    incremental true
                    javaMaxHeapSize "2048M"
                    preDexLibraries = false
                }*/
    }

    dependencies {
        compile project(':library1')
        compile project(':facebooka')

        compile 'com.android.support:support-v4:23.1.1'
        compile 'com.android.support:appcompat-v7:23.1.1'
        compile files('libs/YouTubeAndroidPlayerApi.jar')
        compile 'com.android.support:design:23.1.1'

        compile 'com.google.android.gms:play-services:8.4.0'


        compile 'com.android.support:multidex:1.0.1'
        compile 'com.devfigas:marshmallow-permission:0.0.9'

    }

在Android studio版本2.1.1中,此代码可以正常工作,但是当我在版本2.1.2中尝试相同的代码时

dexOptions {
            incremental = true;
            preDexLibraries = false
            javaMaxHeapSize "2g" // 2g should be also OK
        }

1 个答案:

答案 0 :(得分:0)

尝试在应用程序的清单中添加此行:

<application
     android:largeHeap="true" >
</application>