无法解析符号 'DaggerAppComponent'
Unable to resolve symbol 'DaggerAppComponent'
我已经在 githubbrowsersample (java) 的 di folder 中添加了所有组件,并且在创建 AppInjector 之前似乎没有引起什么大惊小怪,因为它没有想要生成 DaggerAppComponent,我知道在示例中它显示在 generatedJava 文件夹中,而不是为我显示,所以这就是为什么它不可解析,但我不确定如何解决它。
我已经尝试了通常的嫌疑人,无效的缓存,在 gradle 中尝试了不同的替代方案,看看 android.enableSeparateAnnotationProcessing=true 做了什么,添加了 -Pandroid.incrementalJavaCompile = false,从中找到了很多帖子许多其他人面临着类似的问题,但我根本无法弄清楚为什么我的代码没有正常运行。
Build.gradle(模块:应用):
implementation "com.google.dagger:dagger:$rootProject.dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger"
implementation "com.google.dagger:dagger-android:$rootProject.dagger"
implementation "com.google.dagger:dagger-android-support:$rootProject.dagger" // if you use the support libraries
annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.dagger"
我的构建错误,其中一些似乎只在 di 就位时才会发生:
Gradle may disable incremental compilation as the following annotation processors are not incremental: dagger-compiler-2.17.jar (com.google.dagger:dagger-compiler:2.17), dagger-android-processor-2.17.jar (com.google.dagger:dagger-android-processor:2.17), room-compiler-2.0.0.jar (androidx.room:room-compiler:2.0.0), lifecycle-compiler-2.0.0.jar (androidx.lifecycle:lifecycle-compiler:2.0.0), databinding-compiler-3.4.1.jar (androidx.databinding:databinding-compiler:3.4.1).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental.
D:\AndroidStudioProjects\smhApp\binding\FragmentDataBindingComponent.java:5: error: cannot find symbol
public class FragmentDataBindingComponent implements androidx.databinding.DataBindingComponent {
^
symbol: class DataBindingComponent
location: package androidx.databinding
D:\AndroidStudioProjects\smhApp\ui\u\category\CategoryFragment.java:32: error: cannot find symbol
androidx.databinding.DataBindingComponent dataBindingComponent = new FragmentDataBindingComponent(this);
^
symbol: class DataBindingComponent
location: package androidx.databinding
D:\AndroidStudioProjects\smhApp\ui\u\common\CategoryListAdapter.java:39: error: cannot find symbol
public CategoryListAdapter(DataBindingComponent dataBindingComponent) {
^
symbol: class DataBindingComponent
location: class CategoryListAdapter
D:\AndroidStudioProjects\smhApp\di\AppModule.java:35: error: com.smhapp.di.ViewModelModule has errors
@Module(includes = ViewModelModule.class)
^
D:\AndroidStudioProjects\smhApp\di\ViewModelModule.java:20: error: @Binds methods' parameter type must be assignable to the return type
abstract ViewModelProvider.Factory bindViewModelFactory(CrosscareService factory);
^
D:\AndroidStudioProjects\smhApp\di\AppComponent.java:29: error: com.smhapp.di.AppModule has errors
@Component(modules = {
^
D:\AndroidStudioProjects\smhApp\ui\u\category\CategoryFragment.java:25: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public class CategoryFragment extends Fragment implements Injectable {
^
7 errors
> Task :app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
必须至少花了一个小时来寻找解决方案。
感谢您抽出时间。
代表我复制和粘贴很糟糕。我通过慢慢地重新引入 AppModule.java 中的所有内容来解决这个问题,然后注意到我在 ViewModelModule 中放置了 GithubService 的等价物而不是 GithubViewFactory。
现在可以正常编译了。
我已经在 githubbrowsersample (java) 的 di folder 中添加了所有组件,并且在创建 AppInjector 之前似乎没有引起什么大惊小怪,因为它没有想要生成 DaggerAppComponent,我知道在示例中它显示在 generatedJava 文件夹中,而不是为我显示,所以这就是为什么它不可解析,但我不确定如何解决它。
我已经尝试了通常的嫌疑人,无效的缓存,在 gradle 中尝试了不同的替代方案,看看 android.enableSeparateAnnotationProcessing=true 做了什么,添加了 -Pandroid.incrementalJavaCompile = false,从中找到了很多帖子许多其他人面临着类似的问题,但我根本无法弄清楚为什么我的代码没有正常运行。
Build.gradle(模块:应用):
implementation "com.google.dagger:dagger:$rootProject.dagger"
annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger"
implementation "com.google.dagger:dagger-android:$rootProject.dagger"
implementation "com.google.dagger:dagger-android-support:$rootProject.dagger" // if you use the support libraries
annotationProcessor "com.google.dagger:dagger-android-processor:$rootProject.dagger"
我的构建错误,其中一些似乎只在 di 就位时才会发生:
Gradle may disable incremental compilation as the following annotation processors are not incremental: dagger-compiler-2.17.jar (com.google.dagger:dagger-compiler:2.17), dagger-android-processor-2.17.jar (com.google.dagger:dagger-android-processor:2.17), room-compiler-2.0.0.jar (androidx.room:room-compiler:2.0.0), lifecycle-compiler-2.0.0.jar (androidx.lifecycle:lifecycle-compiler:2.0.0), databinding-compiler-3.4.1.jar (androidx.databinding:databinding-compiler:3.4.1).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental.
D:\AndroidStudioProjects\smhApp\binding\FragmentDataBindingComponent.java:5: error: cannot find symbol
public class FragmentDataBindingComponent implements androidx.databinding.DataBindingComponent {
^
symbol: class DataBindingComponent
location: package androidx.databinding
D:\AndroidStudioProjects\smhApp\ui\u\category\CategoryFragment.java:32: error: cannot find symbol
androidx.databinding.DataBindingComponent dataBindingComponent = new FragmentDataBindingComponent(this);
^
symbol: class DataBindingComponent
location: package androidx.databinding
D:\AndroidStudioProjects\smhApp\ui\u\common\CategoryListAdapter.java:39: error: cannot find symbol
public CategoryListAdapter(DataBindingComponent dataBindingComponent) {
^
symbol: class DataBindingComponent
location: class CategoryListAdapter
D:\AndroidStudioProjects\smhApp\di\AppModule.java:35: error: com.smhapp.di.ViewModelModule has errors
@Module(includes = ViewModelModule.class)
^
D:\AndroidStudioProjects\smhApp\di\ViewModelModule.java:20: error: @Binds methods' parameter type must be assignable to the return type
abstract ViewModelProvider.Factory bindViewModelFactory(CrosscareService factory);
^
D:\AndroidStudioProjects\smhApp\di\AppComponent.java:29: error: com.smhapp.di.AppModule has errors
@Component(modules = {
^
D:\AndroidStudioProjects\smhApp\ui\u\category\CategoryFragment.java:25: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this class because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code.
public class CategoryFragment extends Fragment implements Injectable {
^
7 errors
> Task :app:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
必须至少花了一个小时来寻找解决方案。
感谢您抽出时间。
代表我复制和粘贴很糟糕。我通过慢慢地重新引入 AppModule.java 中的所有内容来解决这个问题,然后注意到我在 ViewModelModule 中放置了 GithubService 的等价物而不是 GithubViewFactory。
现在可以正常编译了。