之前的項目從eclipse遷移過來的,編譯運行可以跑起來,但只要佈局文件中有layout設置background引用了資源,或者ImageView設置了src標籤引用了圖片,比如:
<ImageView android:id="@+id/splash_grain" android:src="@drawable/loading_page_bg" android:layout_width="match_parent" android:layout_height="match_parent" />
就會導致Activity啓動時閃退,報xml異常,如下所示:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.lxy.splash.NewGuideActivity}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class
<unknown>
但是相同的圖片,移動到mipmap目錄下就不會閃退,是我的圖片資源有問題嗎?eclipse下運行是沒有問題的,我試着在gradle中配置:
aaptOptions.cruncherEnabled false aaptOptions.useNewCruncher false
也沒用,如果把所有的圖片都移動到mipmap目錄下就要改很多地方,因爲引用的地方都要從@drawable改爲@mipmap,總覺得這不是一個好辦法,沒道理不能用drawable資源,我新建一個項目,把相同的圖片放在drawable目錄下也沒問題,是因爲我的compileSdkVersion 19和buildToolsVersion "19.1.0"版本太低嗎?
能試的辦法都試過了,求救各位大神有遇到過類似的問題是怎麼解決的?