問題:
Android rxjava 中Observable 轉型 “incompatible types: Object cannot be converted to ……
關于Observable轉型的問題估計應該不少人遇見了吧,我之前也遇見了。
原因:
項目中使用Observable的轉型問題是由java version引起的,需要Android Studio支援Java version 8 ,網上解決方案有很多,比如這篇部落格
我最開始也是通過這樣的方式解決的,我用的
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
成功自動轉型,但是3.7.0不成功。
最近更新的Android Studio 那麼問題就來了。
同樣的處理方式,結果并不能自動轉型,當然能否自動轉型是跟你的gradle版本也有關系的。我的gradle版本是3.0.1,在做同樣配置時AndroidStudio對我有如下提示:
Warning:One of the plugins you are using supports Java 8 language features. To try the support built into the Android plugin, remove the following from your build.gradle:
apply plugin: 'me.tatarka.retrolambda'
從警告上看,希望我移除這個插件,于是我到官網上檢視了一下資訊:
If Android Studio detects that your project is using Jack, Retrolambda, or DexGuard, the IDE uses Java 8 support provided by those tools instead.
.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
apply plugin: 'me.tatarka.retrolambda'
classpath 'me.tatarka:gradle-retrolambda:3.6.0'
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io"