【问题标题】:How to use jackOptions for android library project如何将 jackOptions 用于 android 库项目
【发布时间】:2016-10-18 11:45:20
【问题描述】:

我在 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

【问题讨论】:

    标签: android java-8 android-studio-2.1


    【解决方案1】:

    设置中有重复条目。只需从 build.gradle 中删除以下行:

    jackOptions {
            enabled true
    }
    

    【讨论】:

      【解决方案2】:

      感谢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"
          }
      }
      

      【讨论】:

      • 在模块或项目中。 ?
      猜你喜欢
      • 2014-10-01
      • 2012-01-05
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-11
      相关资源
      最近更新 更多