如何在Android库项目中使用jackOptions

5

我有一个在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'

}

我正在使用Android Studio 2.2.1和JDK 1.8,
JDK 1.8需要jackOptions。
错误消息如下:
错误:库项目不能启用Jack。 Jack在默认配置中已启用。 如果我禁用jackOptions,则我的库无法正常工作,因为由于JDK 1.8,它说jackOptions是必需的,并出现以下错误。
app:generateDebugSources 
app:mockableAndroidJar
app:prepareDebugUnitTestDependencies 
app:generateDebugAndroidTestSources
myapplication:generateDebugSources
myapplication:generateDebugAndroidTestSources
myapplication:mockableAndroidJar
myapplication:prepareDebugUnitTestDependencies
2个回答

1
在设置中出现了重复的条目。只需从您的build.gradle文件中删除以下行:
jackOptions {
        enabled true
}

0
感谢Olivier M.,您在这里有一个可行的解决方法:有没有办法在Android库项目中使用Java 8功能?
重要的部分是:
// 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"
    }
}

在模块或项目内部。 - J.K

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接