作者編寫的一個(gè)高效的多媒體支持操作開源庫,可多方面的簡單配置操作拍照、相冊、錄制、錄音等功能。
周六整整一天就被這個(gè)奇葩問題困擾了,整整一天悶悶不樂心情煩躁,中午沒有照常吃飯沒有給狗洗澡晚上就點(diǎn)了個(gè)外賣也不跑步遛狗。最后第二天周日終于解決,瞬間突然覺得自己萌萌噠~~~~
首先先讓我們看看開頭的一個(gè)問題
如果只想關(guān)注答案的,直接看結(jié)尾,但是因?yàn)閷?dǎo)致這個(gè)問題的有很多種,所以建議還是全程看
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
那么前面最熱門的答案都是:
添加這些配置即可
defaultConfig {
jackOptions {
enabled true
}
}
dexOptions {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
或者這個(gè)配置
classpath 'com.android.tools.build:gradle:3.0.0'
and
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
...
//jackOptions { // DEPRECATED
//enabled true
//}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
運(yùn)行,報(bào)錯(cuò)
Cannot get property 'destinationDir' on null object
又google了一番
如果使用enabled true開啟了1.8
注:AS2.1以上時(shí),app的build.gradle里不要加
apply plugin: 'me.tatarka.retrolambda'
好吧好吧,我刪掉~
終于可以運(yùn)行,誰知道……
運(yùn)行到某個(gè)地方,又報(bào)錯(cuò)
IncompatibleClassChangeError …
was expected to be of type direct but instead was found to be of type virtual
于是又google
I see you are building for android, so maybe issue is as follows: build set minSdkVersion 21 - android 5 lollipop AND targetCompatibility for java 8 - which is supported (very limited though) starting from sdk 24, thus causing your build problems. You can address this issue three ways:
1) build for minSdkVersion 24, targeting solid [0.4%](https://developer.android.com/about/dashboards/index.html) of devices
2) get rid of java 8 features and set source/target compatibility to java 7
3) use java 8 features and build using [retrolambda](https://github.com/orfjackal/retrolambda) (with some limitations, present on lib readme)
大致意思還是java8和兼容java7的問題!
那我就納悶了,我把我以前的項(xiàng)目跟這個(gè)項(xiàng)目重新對比,用排除法將配置一個(gè)一個(gè)的修改復(fù)原,終于找到一個(gè)問題……
總結(jié)
是下面這個(gè)包引起的!??!
compile 'org.jetbrains:annotations:15.0'
還是回到這個(gè)熱門答案
https://stackoverflow.com/questions/37020413/android-dex-cannot-parse-version-52-byte-code
有一個(gè)稍微冷門答案提及到
If you use org.jetbrains:annotation:15 and retrolambda plugin then remove line compile org.jetbrains:annotations:15.0 from your build.gradle and the error will disappear. It works for me.
大致意思是如果你使用org.jetbrains:annotation:15包和retrolambda插件,那么刪掉org.jetbrains:annotation:15包就可以了............應(yīng)該是沖突造成原因了
有時(shí)候就是莫名其妙的問題耽擱事件,我的整整一天假期就這么沒了。祝大家周末愉快