天天看点

Android rxjava 中Observable 转型 “incompatible types: Object cannot be converted to ……

问题:

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"