1、今天在升級了AS2.0后,運行iyuba項目竟然爆出了1500多個錯誤!(內(nèi)心崩潰的)
?拉到最后一行,錯誤提示:
Android Studio XXX causing GC overhead limit exceeded error
StackOverflow解決:
?I think there's a separate way to raise the heap limit of the dexing operation. Add this to your android closure in your build.gradle file:
dexOptions {
javaMaxHeapSize "4g"
}
?再次執(zhí)行,還是報錯,不過這次只報一個錯誤了:
Android Studio Error:Execution failed for task ':iyuba:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process finished with non-zero exit value 2
?總的分析來說,應(yīng)該是項目中的總文件數(shù)超過了65K的限制了。下面采用插件化機制multidex,首先在iyuba和lib的build.gradle文件的dependencies中添加:
compile 'com.android.support:multidex:1.0.0'
并在iyuba的build.gradle文件中添加:
defaultConfig{
multiDexEnabled true
}
?注意不要在lib的build.gradle文件添加!
?這時執(zhí)行還是有錯誤:
Android Studio duplicate entry: android/support/multidex/MultiDex$V19.class
?項目Clean了一遍之后這個錯誤就消失了,又出現(xiàn)了新的錯誤:
Gradle Duplicate Entry: java.util.zip.ZipException :duplicate entry: android/support/annotation/IntegerRes.class
?因為這里有support包的問題,懷疑是本地的support包或者其他有兩個module使用的jar包中的方法引起的沖突,因為使用了Multidex的原因。然后將Project中的所有Module一一排查,只用一次的jar包可以直接引用本地的,其他可能多次引用的jar包一律使用在線的。如此折騰完一番,問題比較明確了。然后發(fā)現(xiàn)有support-v4包的沖突,actionbarSherlock、SlidingMenu統(tǒng)統(tǒng)注掉,基本問題少了很多,只剩下最后一個坑,AS的應(yīng)用運行按鈕旁邊的應(yīng)用名字上一直顯示個紅叉,說是找不到Default Activity,自己手動指定一下就可以了。至此,程序基本上可以運行了,再次淚流滿面!
?最后一個小點,如果想讓應(yīng)用中的ActionBar和Title不顯示,在styles.xml文件中,Application中調(diào)用的Theme中設(shè)置:
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>即可。
?愉快而又充滿了坑的一天!