1 在app中的build.gradle 中添加
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//rxJava添加下面兩行
compile 'io.reactivex:rxjava:1.1.5'
compile 'io.reactivex:rxandroid:1.2.0'
}
2 在app的build gradle中添加java 1.8
android {
compileSdkVersion 26
defaultConfig {
applicationId "demo.fence.com.myapplication"
minSdkVersion 15
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'
}
}
//rxJava 添加下面一句
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
3 在 項目的build.gradle 中 添加
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
//rxjava 添加下面一行
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
PS : 網上還有人說 要在app 中的build.gradle 添加一個插件
apply plugin: 'me.tatarka.retrolambda'
我也測試過 會報一個warning 提示去掉這句話
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM38CXlZHbvN3cpR2Lc1TPB10QGtWUCpEMJ9CXsxWam9CXwADNvwVZ6l2c052bm9CXUJDT1wkNhVzLcRnbvZ2LcJTRq1UMVJzY1Z0VlZXUYpVd1kmYr50MZV3YyI2cKJDT29GRjBjUIF2LcRHelR3LcJzLctmch1mclRXY39DNyQTM0UDMzEDNyIDM4EDMy8CX0Vmbu4GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)
查了一下原因 studio3.0 已經支援java8了
是以 到第3步結束 rxjava 依賴添加完畢