gpt4 book ai didi

java - 无法解析符号 'DaggerAppComponent'

转载 作者:行者123 更新时间:2023-12-02 05:35:18 36 4
gpt4 key购买 nike

我一直在添加 di folder 中的所有组件githubbrowsersample (java) 的并且似乎没有引起任何大惊小怪,直到创建 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 中的所有内容来解决这个问题,然后注意到我已将 GithubService 而不是 GithubViewFactory 的等价物放在 ViewModelModule 中。

现在可以正常编译了。

关于java - 无法解析符号 'DaggerAppComponent',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56172239/

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