如何使用androidOptions for android库项目

nay*_*hoj 5 android java-8 android-studio-2.1

我在android studio中有一个应用程序代码,我想将它转换为库项目,以便我可以在其他应用程序中将其用作库.
库项目的build.gradle如下

apply plugin: 'com.android.library'
apply plugin: 'com.google.gms.google-services'
android {
    compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
    //applicationId "com.example"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"

    jackOptions {
        enabled true
    }
    multiDexEnabled true
}
dexOptions {

    javaMaxHeapSize "4g"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

 }
 }

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'
})
testCompile 'junit:junit:4.12'

/* support libraries*/
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:support-annotations:23.1.0'

/* google play services libraries*/
compile 'com.google.android.gms:play-services-location:9.0.0'

}
Run Code Online (Sandbox Code Playgroud)

我使用android studio 2.2.1和jdk 1.8,
jdk 1.8需要jackOptions

它说:
错误:图书馆项目无法启用杰克.Jack在默认配置中启用.如果我禁用jackOptions然后我的库不工作,因为jdk 1.8它说jackOptions是必要的,并得到以下错误.

app:generateDebugSources 
app:mockableAndroidJar
app:prepareDebugUnitTestDependencies 
app:generateDebugAndroidTestSources
myapplication:generateDebugSources
myapplication:generateDebugAndroidTestSources
myapplication:mockableAndroidJar
myapplication:prepareDebugUnitTestDependencies
Run Code Online (Sandbox Code Playgroud)

LE *_*oît 0

感谢Olivier M.,您在这里有一个可行的解决方法:Is there way to use Java 8 features with Android Library Project?

导入部分是:

// 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"
    }
}
Run Code Online (Sandbox Code Playgroud)