android - 如何启用 Jack Compiler 支持?

标签 android android-studio intellij-idea gradle

我一直在为 Jack 编译器烦恼。我使用 Intellij IDEA 进行 Androidd 应用程序开发。

我已经阅读了这些文档:

documentation for jack compiler

how to use java 8 features

这是我的 build.gradle 配置:

android {
...
defaultConfig {
    ...
    jackOptions {
        enabled true
    }
    ...
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
...
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile ('io.socket:socket.io-client:0.8.1') {
    // excluding org.json which is provided by Android
    exclude group: 'org.json', module: 'json'
}
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'io.reactivex:rxjava:1.2.0'
compile 'io.reactivex:rxandroid:1.2.1'
}

但我仍然得到这个错误:

Error:Gradle: Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

Gradle 构建错误:

Error:(12, 0) Gradle DSL method not found: 'jackOptions()'
Possible causes:<ul><li>The project 'App' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

不知道如何解决这个问题。

最佳答案

    defaultConfig {

         ...

       jackOptions {
           enabled true
       }

       // inside defaultConfig
       compileOptions { 
           sourceCompatibility JavaVersion.VERSION_1_8
           targetCompatibility JavaVersion.VERSION_1_8
       }
    }

关于android - 如何启用 Jack Compiler 支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978201/

相关文章:

android - OnTouchEvent 不适用于 subview

java - 在同一模块中使用时,IntelliJ 找不到生成的源

android - 在 Android SQLite 中从哪里获取数据库错误信息(例如,由于违反 not null 而导致插入失败)

android - 完成 Android 设置?

java listview改变内容

android - "Could not find property on task set",但任务出现在 "gradlew -q tasks --all"的输出中

Android studio gradle 自定义任务与 shell 脚本在构建时不起作用

android - 程序类型已经存在 : android. support.v4.app.INotificationSideChannel$Stub$Proxy

intellij-idea - 我如何告诉 IntelliJ IdeaVim 重新获取 .ideavimrc

java - 在 IntelliJ IDEA 中使用 Python 脚本作为外部工具