[英]Android: Application class not recognized in Dagger2 Component
It seems like I cant find the MyApplication
class from my ApplicationComponent: 看来我无法从我的ApplicationComponent中找到
MyApplication
类:
And this error output: 并且此错误输出:
error: cannot find symbol class MyApplication
错误:找不到符号类MyApplication
Here is all the related classes: 这是所有相关的类:
ApplicationComponent: ApplicationComponent:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
StartModule.class,
AndroidInjectionModule.class,
BindModule.class,
AndroidSupportInjectionModule.class})
public interface ApplicationComponent {
void inject(MyApplication myApplication);
@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication); //CANT FIND MYAPPLICATION
ApplicationComponent build();
}
@ApplicationContext
Context getApplicationContext();
SharedPreferences getSharedPreferences();
KeyStoreServiceInterface getKeyStoreService();
SharedPreferencesHelper getSharedPreferencesHelper();
StartViewModelFactory getStartViewModelFactory();
}
MyApplication class: MyApplication类:
public class MyApplication extends MultiDexApplication implements HasActivityInjector {
private ApplicationComponent applicationComponent;
@Inject
DispatchingAndroidInjector<Activity> dispatchingActivityInjector;
@Override
public void onCreate() {
super.onCreate();
applicationComponent = DaggerApplicationComponent.builder()
.applicationContextModule(new ApplicationContextModule(this))
.build();
DaggerApplicationComponent
.builder()
.build()
.inject(this); //ERROR HERE. Complains that there is no inject method, offers creation of one in ApplicationComponent, but already exists one.
}
@Override
public AndroidInjector<Activity> activityInjector() {
return dispatchingActivityInjector;
}
public ApplicationComponent getApplicationComponent() {
return applicationComponent;
}
}
And here is my manifest: 这是我的清单:
<application
android:name="MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="whateverString">
<activity android:name="start.StartActivity" ></activity>
</application>
Why does it not recognize the class? 为什么不识别班级?
Apparently looks like a package name issue as component is unable to import it or use it so 显然是软件包名称问题,因为组件无法导入或使用它
Move the Application class under the root package name (that you entered while creating app) 将Application类移动到根包名称(您在创建应用程序时输入的名称)下
Use .MyApplication
to register you application class 使用
.MyApplication
注册您的应用程序类
android:name=".MyApplication"
or may also add any additional package name with application name 或者也可以在应用程序名称中添加任何其他软件包名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.