在build.gradle中添加java
//加入retrolambda須要的plugin聲明 apply plugin: 'me.tatarka.retrolambda' //retrolambda的編譯路徑依賴 buildscript { dependencies { classpath 'me.tatarka:gradle-retrolambda:3.1.0' } } //讓IDE使用用Java8語法解析 android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } //編譯RxJava compile 'io.reactivex:rxjava:1.0.14' //編譯RxAndroid compile 'io.reactivex:rxandroid:1.0.1' //編譯Retrofit及其相關庫,包括Gson compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' compile 'com.google.code.gson:gson:2.4'
Retrolambda是借用Java8的語法特性,須要配置好Java8
安裝好Java8後在File > Project structure > SDK Location中配置Java8路徑 react