有没有办法在Android库项目中使用Java 8功能? [英] Is there way to use Java 8 features with Android library project?
问题描述
我按照 Android Java 8功能手册进行操作。它适用于Android应用程序项目。但是当我尝试将它与Android库项目一起使用时,我得到了
I followed the Android Java 8 Features manual. It works well for Android application project. But when I try to use it with Android library project I get
Error:Library projects cannot enable Jack. Jack is enabled in default config.
部分解决方案:
我用 Gradle Retrolambda插件。
推荐答案
我有同样的问题并尝试了不同的方法。它现在适用于我而不使用retrolambda(在运行时产生一些奇怪的错误)。杰克也因你提到的原因而不活跃。
google.com上有一个关于此主题的有趣错误帖子: https:// code.google.com/p/android/issues/detail?id=211386
I had the same issue and tried different approaches. It now works for me without using retrolambda (which produced some weird error during runtime). Also Jack is not active for the same reason you already mentioned. There is an interesting bug post at google.com about this topic: https://code.google.com/p/android/issues/detail?id=211386
这是我的build.gradle脚本,我使用了来自的解决方法在编译期间修复未找到MethodType异常的bug帖子。
Here is my build.gradle script, I used the workaround from the bug post to fix the "MethodType not found" exception during compilation.
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
}
}
这篇关于有没有办法在Android库项目中使用Java 8功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!