使用Jack时未生成Dagger 2组件 [英] Dagger 2 components not generated when using Jack
问题描述
当我在Android Studio 2.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中的错误导致阻止类路径起作用而引起的正确.它与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.
这是似乎避免了番石榴与杰克发生冲突的最高版本.
- Wait for the 2.3 release of the Android gradle plugin, which already has the fix for this.
- Downgrade Dagger to v2.2, in the meantime.
It's the highest version that seems to avoid the Guava conflict with Jack.
更新1/14/2017:
我遇到了Jack的其他问题,对它感到厌倦,以至于我改用retrolambda并踢了自己,原因是他们没有更早地这样做!现在,杰克似乎引起的问题比解决的问题还多.只需添加带有加号的行并删除带有减号的行,就可以返回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
文件中,以便在处理过程中进行解密.现在,我使用的是Dagger 2.8,我的干净版本只有12秒, GOOD RIDDANCE,杰克!
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屋!