作者:awetyjdgtjkt_933 | 来源:互联网 | 2023-02-13 14:35
正如标题所说,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