来自StackoverFlow的搬运工:
http://stackoverflow.com/questions/37975128/is-there-way-to-use-java-8-features-with-android-library-project/38360596#38360596
在library gradle中配置:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
apply plugin: 'com.android.library'
repositories {
mavenCentral()
}
// Java8 not fully supported in library projects yet, https://code.google.com/p/android/issues/detail?id=211386
// this is a temporary workaround to get at least lambdas compiling
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xbootclasspath/a:" + System.properties.get("java.home") + "/lib/rt.jar"
}
}
android {
compileSdkVersion 24
buildToolsVersion "24"
defaultConfig {
minSdkVersion 10
targetSdkVersion 24
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}