Android項(xiàng)目中Bug總結(jié),持續(xù)更新...

一.在4.0左右的手機(jī)上運(yùn)行,Application初始化,比如imageLoader,sharSDK啥的初始化那報(bào)錯(cuò)
java.lang.NoClassDefFoundError: com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener
(這是imageloader報(bào)的錯(cuò))
解決方案:
在Application中添加這個(gè)方法

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

這是Gradle分包:
android{
defaultConfig{
multiDexEnable true
}
}
dependencies{
compile 'com.android.support:multidex:1.0.0'
}

二.
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/exoplayer/SampleSource.class

這種是依賴重復(fù)(導(dǎo)jar包重復(fù)),想想在沒出錯(cuò)之前依賴過什么,如果不知道就得一個(gè)一個(gè)注釋掉依賴進(jìn)行查找.

三.Error:A problem was found with the configuration of task ':app:packageRelease'.
解析包出錯(cuò)
解決方案:
打包選擇v1

四. java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/internal/http/HttpEngine
集成retrofit,集成okhttp日志攔截報(bào)的錯(cuò),所以還得集成okhttp

注意 版本號(hào)得一致

image.png

五.在Retrofit中加入rxjava

image.png

同步?jīng)]有錯(cuò)誤,運(yùn)行報(bào)錯(cuò) Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties

{VU9U0~_`2YF{3U2}S%}4I0.png

解決方案:
加上packagingOptions節(jié)點(diǎn)

image.png

六.Unable to create call adapter for io.reactivex.Observable<java.lang.Boolean>

image.png

得加上 2,導(dǎo)的包是 io.reactivex

七:com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
解決方案:
POST請(qǐng)求json數(shù)據(jù)之前還有一些其他非json輸出'

Gson gson = new GsonBuilder().setLenient().create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();

八: clean沒問題,運(yùn)行報(bào)錯(cuò)Error:Execution failed for task 'transformClassesWithExtractJarsForXXXXDebug'.

error
解決方案:
Android2.0中加入了instant run,所以在setting-->Build,Execution,Deployment-->instant run--> 取消對(duì)勾,不選中

最后:看bug小Tips:
如果在在項(xiàng)目中遇到莫名奇妙的bug,看又看不懂,百度也沒有的,比如類似如這種bug

image.png

可以嘗試下面這種方法:

image.png

會(huì)看到非常詳細(xì)的日志,也許會(huì)有一點(diǎn)幫助.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容