使用 Jack 时未生成 Dagger 2 组件 [英] Dagger 2 components not generated when using Jack

查看:28
本文介绍了使用 Jack 时未生成 Dagger 2 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 Android Studio 2.2 中启用 Jack 编译器时,Dagger 2 组件未生成.Dagger 2 可以与 Jack 一起使用吗?如果是这样,我将如何配置我的应用程序?

When I enable the Jack compiler in Android Studio 2.2 the Dagger 2 component is not generated. Can Dagger 2 be used with Jack? If so, how would I go about configuring my application?

从我的应用程序的build.gradle:

jackOptions {
     enabled true
   }

 compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

推荐答案

我花了 2 天时间才弄清楚这个问题.所以我回过头来在这里发布调查结果,以防它节省一些时间:

I sunk like 2 days into figuring this out. So I'm circling back to posting the findings here in case it saves someone time:

这是由 杰克中阻止类路径工作的错误引起的正确.它与 Jack 在进程内"运行(与 gradle 守护进程在同一个 JVM 中)有关.将 android.defaultConfig.jackOptions.jackInProcess 设置为 false 确实超出了前提条件"错误,但会导致其他问题(2 个 JVM 占用系统资源)&错误破坏其他构建(更糟)方式.

This is caused by a bug in Jack that prevents classpaths from working properly. It has to do with Jack running "in-process" (in the same JVM as the gradle daemon). Setting android.defaultConfig.jackOptions.jackInProcess to false does get beyond the "Preconditions" error but it causes other problems (2 JVMs that hog system resources) & bugs that break the build in other (worse) ways.

目前,最好的解决方案似乎是:

  • 等待 Android gradle 插件的 2.3 版发布,该插件已经对此进行了修复.
  • 同时将 Dagger 降级到 v2.2.
    似乎是避免了 Guava 与 Jack 冲突的最高版本.

2017 年 1 月 14 日更新:
我和 Jack 一起遇到了其他几个问题,我已经厌倦了,所以我转向了 retrolambda,并因为没有早点这样做而自责!现在,Jack 造成的问题似乎比它解决的问题还多.只需添加带加号的行并删除带减号的行,您就可以返回 Dagger 2.8,同时等待 Jack 开始行动!

update 1/14/2017:
I ran into several OTHER problems with Jack and got so tired of it that I switched to retrolambda and kicked myself for not doing this earlier! Right now, Jack simply seems to cause more problems than it solves. Just add the lines with a plus and delete the lines with a minus and you can return to Dagger 2.8 while waiting for Jack to get it's act together!

+plugins {
+    id "me.tatarka.retrolambda" version "3.4.0"
+}

 apply plugin: 'com.android.application'
+apply plugin: 'me.tatarka.retrolambda'

-        jackOptions {
-            enabled true
-        }

为了更快地构建retrolambda,请将org.gradle.jvmargs=-Xmx4608M 添加到您的gradle.properties 文件中,以便在进程中进行dexing.现在,我使用的是 Dagger 2.8,我的干净构建只有 12 秒,好问题,JACK!

For even faster retrolambda builds, add org.gradle.jvmargs=-Xmx4608M to your gradle.properties file so that dexing can happen in-process. Now, I'm on Dagger 2.8 and my clean builds are only 12 seconds, GOOD RIDDANCE, JACK!

这篇关于使用 Jack 时未生成 Dagger 2 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆