dagger2 error: cannot find symbol class DaggerAppComponent

Error message: Cannot find symbol class DaggerAppComponent

Application class:

public class App extends MultiDexApplication implements HasActivityInjector {
    
    

	@Inject
	DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;

	@Override
	public void onCreate() {
    
    
		super.onCreate();
        Realm.init(this);
        DaggerAppComponent
				.builder()
				.application(this)
				.build()
				.inject(this);
	}

	@Override
	public AndroidInjector<Activity> activityInjector() {
    
    
		return dispatchingAndroidInjector;
	}

}

Application components:

@Singleton
@Component(modules = {
    
    
		AndroidSupportInjectionModule.class,
		ToolsModule.class,
		RepositoriesModule.class,
		BuildersModule.class })
public interface AppComponent {
    
    

	@Component.Builder
	interface Builder {
    
    
		@BindsInstance
		Builder application(App app);
		AppComponent build();
	}
	void inject(App app);
}

Dependencies used:

implementation 'com.google.dagger:dagger:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'

solution:

From the error message, it is because dagger2 cannot automatically generate dagger + component.
After checking the code and dependencies, there was no problem, so I asked my colleague to run the project on his computer and found that the colleague could run it. . . . It turned out to be the reason of the environment. My AS is the latest version 2021.1.1 and the JDK specified by default is 11. Just change the AS default JDK to JKD8: File→Project Structure (Mac computers can use ⌘;shortcut keys)→Gradle Settings→Gradle JKD select 1.8.
insert image description here

Guess you like

Origin blog.csdn.net/Jackson_Wen/article/details/123094944