在androidstudio下使用Rxjava编程需要引入第三方类库。
要使用lamda表达式需要jdk1.8,这个需要自己提前配置好。
因为lamda表达式的包和jdk1.8有点冲突。所以先要把lamda表达式的包下载下来。
直接上截图。
先改项目下的build.gradle
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' classpath 'me.tatarka:gradle-retrolambda:3.2.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }然后sync一下。结束后在改app下的build.gradle文件
apply plugin: 'com.android.application' apply plugin: 'me.tatarka.retrolambda' android { compileSdkVersion 26 buildToolsVersion "26.0.2" defaultConfig { applicationId "com.meiaomei.rxandroid" minSdkVersion 17 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'io.reactivex:rxjava:1.1.0' compile 'io.reactivex:rxandroid:1.1.0' compile 'com.squareup.okhttp3:okhttp:3.2.0' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' }
这样就不会报错。又可以用Rxjava又可以用Lamda表达式。
红色的部分就是需要复制过去的。sync一下就好了。