使用annotationProcessor而不是Android apt的Android Studio 3.0预览版(金丝雀2)的Dagger 2
好的,长话短说-我决定给使用annotationProcessor而不是Android apt的Android Studio 3.0预览版(金丝雀2)的Dagger 2,android,dagger-2,android-studio-3.0,annotation-processor,android-apt,Android,Dagger 2,Android Studio 3.0,Annotation Processor,Android Apt,好的,长话短说-我决定给安卓Studio 3.0预览版(金丝雀2)一个机会,但我不能用annotationProcessor而不是安卓apt让它与Dagger 2一起工作 我得到的错误消息很容易理解: "A long time ago in a galaxy far, far away...." 我读过这些文件(我想没有什么特别的): 并将build.gradle文件更改为: Error:(59, 24) error: cannot find symbol variable DaggerApp
安卓Studio 3.0预览版(金丝雀2)
一个机会,但我不能用annotationProcessor
而不是安卓apt
让它与Dagger 2
一起工作
我得到的错误消息很容易理解:
"A long time ago in a galaxy far, far away...."
我读过这些文件(我想没有什么特别的):
并将build.gradle
文件更改为:
Error:(59, 24) error: cannot find symbol variable DaggerAppComponent
其中daggervision='2.11'
此外,我还确保在Android Studio中选中了相应的选项(默认情况下未选中):
不幸的是,这没有帮助
格拉德尔:
File -> Other Settings -> Default Settings ->
Build, Execution, Deployment -> Compiler -> Annotation Processors ->
Enable annotation processors -> IS CHECKED
Gradle的Android插件:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
如何使用annotationProcessor
而不是android apt
编辑#1
我添加了这些“应该是额外的”依赖项“以防”
现在我得到一个关于冲突作用域的错误。。。哦
implementation "com.google.dagger:dagger:$rootProject.ext.daggerVersion"
implementation "com.google.dagger:dagger-android:$rootProject.ext.daggerVersion"
implementation "com.google.dagger:dagger-android-support:$rootProject.ext.daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.ext.daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.ext.daggerVersion"
compileOnly 'javax.annotation:jsr250-api:1.0'
我确实将Dagger从2.6.1
升级到了2.11
,所以现在我在发行说明中寻找一些“突破性的变化”:
编辑#2
好消息是第一个“突破性的变化”是在2.9中引入的,我的猜测是这是由于“新的验证”。坏消息是,这个问题很可能已经存在了很久
查看(子)组件的结构
和作用域依赖关系
编辑#3
目前,该问题与此相关:
考虑以下示例:
SomeSubComponent has conflicting scopes:
AppComponent also has @Singleton
这在匕首2.9+
中不再可能。组件
必须使用与子组件
不同的范围
。像这样:
@Singleton
@Component(modules = {
AppModule.class
})
public interface AppComponent {
SomeComponent plus(SomeModule someModule);
}
@Module
public class AppModule {
@Provides
@Singleton
public Integer provideInteger() {
return 1;
}
}
@Singleton
@Subcomponent(modules = {
SomeModule.class
})
public interface SomeComponent {
void inject(MainActivity activity);
}
@Module
public class SomeModule {
@Provides
@Singleton
public String provideText(Integer number) {
return number.toString();
}
}
不要做一个“聪明人”,坚持医生说的话:
@Scope
public @interface ApplicationScope {
}
@Module
public class AppModule {
@Provides
@ApplicationScope
public Integer provideInteger() {
return -1;
}
}
@ApplicationScope
@Component(modules = {
AppModule.class
})
public interface AppComponent {
SomeComponent plus(SomeModule someModule);
}
迁移到Dagger 2.9+
时,为组件和子组件使用不同的(自定义)范围
请参阅问题的描述以获得更详细的解释
另外,我认为2.9
的发行说明可以更明确地说明这一变化,不是吗/
我想这是错误,因为匕首没有正确安装。这是你唯一的错误吗<代码>错误:(59,24)错误:找不到符号变量DaggerAppComponent
是,我得到的唯一一个。基本上,:app:compilerRoddebugJavaWithJavaC失败了
。您是否创建了任何dagger依赖类?像组件和所有东西一样?我们正在谈论一个成功的项目,它广泛地使用Dagger2进行我甚至不记得多长时间了™ ;)
@Singleton
@Component(modules = {
AppModule.class
})
public interface AppComponent {
SomeComponent plus(SomeModule someModule);
}
@Module
public class AppModule {
@Provides
@Singleton
public Integer provideInteger() {
return 1;
}
}
@Singleton
@Subcomponent(modules = {
SomeModule.class
})
public interface SomeComponent {
void inject(MainActivity activity);
}
@Module
public class SomeModule {
@Provides
@Singleton
public String provideText(Integer number) {
return number.toString();
}
}
@Scope
public @interface ApplicationScope {
}
@Module
public class AppModule {
@Provides
@ApplicationScope
public Integer provideInteger() {
return -1;
}
}
@ApplicationScope
@Component(modules = {
AppModule.class
})
public interface AppComponent {
SomeComponent plus(SomeModule someModule);
}
implementation "com.google.dagger:dagger:2.11"
annotationProcessor "com.google.dagger:dagger-compiler:2.11"