我一直在githubbrowsersample(java)的di folder中添加所有组件,并且在创建AppInjector之前似乎并没有引起大惊小怪,因为它不想生成DaggerAppComponent,我在示例中知道它显示在generateJava文件夹中,而不是对我而言,所以这就是为什么它不可解析但我不确定如何解决它的原因。
我已经尝试了常见的可疑对象,无效的缓存,在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.
必须花费至少一个小时来寻找解决方案。
感谢您的时间。
答案 0 :(得分:0)
以我的名义不好地进行复制和粘贴。我通过慢慢地在AppModule.java中重新引入所有内容来解决了这个问题,然后指出我将GithubService的股份而不是ViewModelModule的GithubViewFactory投入了。
现在可以编译了。