无法解析符号'DaggerAppComponent'

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (355)

我一直在githubbrowsersample(java)的di文件夹中添加所有组件,并且在创建AppInjector之前似乎没有引起任何麻烦,因为它不想生成DaggerAppComponent,我在示例中知道它的显示在generatedJava文件夹中,而不是我,所以这就是为什么它不可解析但我不知道如何解决它。

我已经尝试了通常的嫌疑人,无效缓存,在gradle中尝试不同的替代方案,看看android.enableSeparateAnnotationProcessing = true做了什么,添加-Pandroid.incrementalJavaCompile = false,发现很多其他人面临类似问题的帖子,但我根本无法弄清楚为什么我的代码不是打球。

Build.gradle(模块:app):

 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中放了GiveubService而不是GithubViewFactory。

现在编译好了。

扫码关注云+社区

领取腾讯云代金券