dagger2 GC overhead limit exceeded

血红的双手。 提交于 2020-01-05 04:04:10

问题


I'm following the Dagger2 sample of TODO app but encounted with OutOfMemoryError: GC overhead limit exceeded. Along with it are 600+ warning likes:

warning: Ignoring InnerClasses attribute for an anonymous inner class (org.eclipse.osgi.internal.baseadaptor.BaseStorage$StateSaver$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is *not* an inner class.

Here's my code: dagger2 cannot find symbol ,where I got my previous problem solved with help of gk5885. Thanks to you again :-).

Just after I add SharedPreferences sharedPreferences() to NetComponent and rebuild, the program compiles for 9 minutes and end up throwing that error. But the time to compile the previous version of my app without Dagger2 is seconds, on account of which I'm pretty sure Dagger2 caused this error. But I don't know why and how to solve this problem.

And my vm size: -Xms256m -Xmx1280m. I think it's more than enough.

Any help is appreciated.

Edit: In fact before I rebuild, I got duplicate file copied in apk error. And I solved it by add this in gradle:

packagingOptions {
        exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
        exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
    } 

Maybe I should show my dependencies:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'me.yokeyword:indexablestickylistview:0.6.1'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:recyclerview-v7:23.4.0'
    compile 'in.srain.cube:ultra-ptr:1.0.11'
    compile files('libs/ormlite-android-4.49-SNAPSHOT.jar')
    compile files('libs/ormlite-core-4.49-SNAPSHOT.jar')
    compile 'com.jakewharton:butterknife:8.1.0'
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
    compile 'com.google.dagger:dagger:2.2' // dagger2
    compile 'com.google.dagger:dagger-compiler:2.2' // dagger2
    compile project(':ToggleButtonLib')
    compile project(':IMKit')
}


Sorry for so many descriptions....


回答1:


You should change

compile 'com.google.dagger:dagger-compiler:2.2' // dagger2 

to

apt 'com.google.dagger:dagger-compiler:2.2' // dagger2

Because you're currently including the entire dagger2 compiler into your project, and that includes Guava and all kinds of things.




回答2:


In my case killing gradle, then cleaning the project fixed the issue.

Perform ./gradlew --stop followed by ./gradlew clean.



来源:https://stackoverflow.com/questions/37981293/dagger2-gc-overhead-limit-exceeded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!