热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Dagger2没有生成Dagger*类

如何解决《Dagger2没有生成Dagger*类》经验,为你挑选了1个好方法。

正如标题所说,Dagger2没有为我的Android项目生成Dagger*前缀类.我查看了我能找到的所有其他类似帖子,但没有任何帮助.我正在尝试将它添加到现有项目中,并且我遇到了一些初始问题,使其能够很好地处理数据绑定,但我似乎已经对其进行了排序,即数据绑定没有编译错误,并且它为它生成代码.我还下载了几个工作正常的示例项目.

我的顶级graddle文件有

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

而我的构建级别有

apply plugin: 'com.neenbedankt.android-apt'

....
final DAGGER_VERSION = '2.8'
....

    compile 'javax.inject:javax.inject:1'
    compile 'javax.annotation:javax.annotation-api:1.2'

    apt "com.google.dagger:dagger:$DAGGER_VERSION"
    compile "com.google.dagger:dagger:$DAGGER_VERSION"
}

组件文件非常简单

@Singleton
@Component(modules = {
        AndroidModule.class
})

public interface ApplicationComponent {
    void inject(MainActivity activity);
}

AndroidModule文件包含

@Module
public class AndroidModule {
    private final Context application;

    public AndroidModule(Application application) {
        this.application = application;
    }
}

和Application类有

import com.rockwellcollins.fsl.dagger.DaggerApplicationComponent;
...

public class FslApplication extends Application {

    private static ApplicationComponent component;

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

        compOnent= DaggerApplicationComponent.builder()
                .androidModule(new AndroidModule(this))
                .build();
    }

    public static void inject(MainActivity target) {
        component.inject(target);
    }

    public ApplicationComponent getComponent() {
        return component;
    }
}

我得到的输出是

Information:Gradle tasks [clean, :android-sliding-layer-lib:Library:generateDebugSources, :android-sliding-layer-lib:Library:mockableAndroidJar, :android-sliding-layer-lib:Library:prepareDebugUnitTestDependencies, :android-sliding-layer-lib:Library:generateDebugAndroidTestSources, :android-sliding-layer-lib:Library:compileDebugSources, :android-sliding-layer-lib:Library:compileDebugUnitTestSources, :android-sliding-layer-lib:Library:compileDebugAndroidTestSources, :mobile:generateDebugSources, :mobile:mockableAndroidJar, :mobile:prepareDebugUnitTestDependencies, :mobile:generateDebugAndroidTestSources, :mobile:compileDebugSources, :mobile:compileDebugUnitTestSources, :mobile:compileDebugAndroidTestSources, :wear:generateDebugSources, :wear:generateDebugAndroidTestSources, :wear:mockableAndroidJar, :wear:prepareDebugUnitTestDependencies, :wear:compileDebugSources, :wear:compileDebugAndroidTestSources, :wear:compileDebugUnitTestSources]

Warning:WARNING: Dependency org.json:json:20131018 is ignored for debug as     it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.json:json:20131018 is ignored for release as it may be conflicting with the internal version provided by Android.
Warning:View field aircraftList collides with a variable or import
Warning:View field groundList collides with a variable or import

C:\Git\android\mobile\src\main\java\com\rockwellcollins\fsl\FslApplication.java
Error:(7, 38) error: cannot find symbol class DaggerApplicationComponent
Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: 
Compilation failed; see the compiler error output for details.
Information:BUILD FAILED

正如我所说,Dagger的东西根本没有代码生成.如果有人能指出问题是什么,我将非常感激.



1> ootinii..:

你的依赖应该是

apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"

您缺少工件ID的-compiler部分.

此链接还包含一些有用的信息. https://github.com/google/dagger#android-gradle


推荐阅读
author-avatar
awetyjdgtjkt_933
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有