Error java.lang.OutOfMemoryError: GC overhead limit exceeded

后端 未结 20 2794
攒了一身酷
攒了一身酷 2020-11-21 05:23

I get this error message as I execute my JUnit tests:

java.lang.OutOfMemoryError: GC overhead limit exceeded

I know what an OutOfMemo

20条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 05:28

    I'm working in Android Studio and encountered this error when trying to generate a signed APK for release. I was able to build and test a debug APK with no problem, but as soon as I wanted to build a release APK, the build process would run for minutes on end and then finally terminate with the "Error java.lang.OutOfMemoryError: GC overhead limit exceeded". I increased the heap sizes for both the VM and the Android DEX compiler, but the problem persisted. Finally, after many hours and mugs of coffee it turned out that the problem was in my app-level 'build.gradle' file - I had the 'minifyEnabled' parameter for the release build type set to 'false', consequently running Proguard stuffs on code that hasn't been through the code-shrinking' process (see https://developer.android.com/studio/build/shrink-code.html). I changed the 'minifyEnabled' parameter to 'true' and the release build executed like a dream :)

    In short, I had to change my app-level 'build.gradle' file from: //...

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.sign_config_release
        }
        debug {
            debuggable true
            signingConfig signingConfigs.sign_config_debug
        }
    }
    
    //...
    

    to

        //...
    
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.sign_config_release
        }
        debug {
            debuggable true
            signingConfig signingConfigs.sign_config_debug
        }
    }
    
    //...
    

提交回复
热议问题