gpt4 book ai didi

android - Dagger2 不生成 "Dagger_"文件

转载 作者:IT老高 更新时间:2023-10-28 23:02:56 25 4
gpt4 key购买 nike

我使用 dagger 2 已经有一段时间了,但是今天尝试编译得到了这个错误:

Error:(13, 31) error: cannot find symbol class Dagger_GlobalComponent

Error:(38, 21) error: cannot find symbol variable Dagger_GlobalComponent

代码如下:

public class MyAppApplication extends Application {

private static GlobalComponent component;

@Override
public void onCreate() {
super.onCreate();

component = Dagger_GlobalComponent.builder()
.busModule(new BusModule())
.syncModule(new SyncModule())
.serviceModule(new ServiceModule())
.contextModule(new ContextModule(this))
.persistenceModule(new PersistenceModule(this))
.build();
}}

和 gradle 依赖关系:

...
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
...

有什么解决办法吗?已尝试:清理、重建、更改依赖版本,同时删除 Gradle 缓存并重新安装 Android Studio。

如果这个示例项目也有同样的错误:

https://github.com/gk5885/dagger-android-sample

https://github.com/mgrzechocinski/dagger2-example

最佳答案

我试图按照 tutsplus here 上的 Dagger2 教程进行操作并在尝试使用下划线语法 (Dagger_ClassnameComponent) 时遇到了同样的问题。

正如其他人所说,新的 Dagger API 不使用下划线语法,而只是使用语法 DaggerClassnameComponent。但是,在我的简单应用程序中尝试使用新语法时,找不到 DaggerClassnameComponent 类。我相信它应该位于 app/build/generated/source/apt/debug/packagename/component 文件夹中。

起初,我没有在上述文件夹下生成任何文件。但是,我的解决方案是清理并构建项目,然后我可以按预期使用 Component 类。

关于android - Dagger2 不生成 "Dagger_"文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29512080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com