gpt4 book ai didi

java - MultiDexApplication 未实现 HasActivityInjector

转载 作者:行者123 更新时间:2023-12-02 08:07:36 24 4
gpt4 key购买 nike

我使用 https://medium.com/@iammert/new-android-injector-with-dagger-2-part-1-8baa60152abe 的 Dagger 2 新 Android 注入(inject)器

在 MultiDex 支持应用程序运行之前。我已向 app/build.gradle 和 AndroidManifest.xml 添加了 multidex 支持。在 MultiDex 支持之后,我在设备上安装时出现错误 logcat

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eusecom.samfantozzi/com.eusecom.samfantozzi.Detail2Activity}: java.lang.RuntimeException: android.support.multidex.MultiDexApplication does not implement dagger.android.HasActivityInjector at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349) at android.app.ActivityThread.access$700(ActivityThread.java:159) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.RuntimeException: android.support.multidex.MultiDexApplication does not implement dagger.android.HasActivityInjector at dagger.android.AndroidInjection.inject(AndroidInjection.java:48) at com.eusecom.samfantozzi.Detail2Activity.onCreate(Detail2Activity.java:19) at android.app.Activity.performCreate(Activity.java:5372) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)  at android.app.ActivityThread.access$700(ActivityThread.java:159)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:137)  at android.app.ActivityThread.main(ActivityThread.java:5419)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:525)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)  at dalvik.system.NativeStart.main(Native Method) 

我的应用程序.java

public class SamfantozziApp extends MultiDexApplication implements HasActivityInjector {

@Inject
DispatchingAndroidInjector<Activity> activityDispatchingAndroidInjector;

public RxBus _rxBus;

@NonNull
private DatabaseReference mDatabaseReference;

@Override
public void onCreate() {
super.onCreate();

if (LeakCanary.isInAnalyzerProcess(this)) {
// This process is dedicated to LeakCanary for heap analysis.
// You should not init your app in this process.
return;
}
LeakCanary.install(this);

mDatabaseReference = FirebaseDatabase.getInstance().getReference();

DaggerAppComponent
.builder()
.application(this)
.build()
.inject(this);

}

@Override
public DispatchingAndroidInjector<Activity> activityInjector() {
return activityDispatchingAndroidInjector;
}




@NonNull
public ISchedulerProvider getSchedulerProvider() {
return SchedulerProvider.getInstance();
}

@NonNull
public DatabaseReference getDatabaseFirebaseReference() {
return mDatabaseReference;
}


public RxBus getRxBusSingleton() {
if (_rxBus == null) {
_rxBus = new RxBus();
}
return _rxBus;
}

private final DemoComponent dgaeacomponent = createDgAeaComponent();

protected DemoComponent createDgAeaComponent() {
return DaggerDemoComponent.builder()
.applicationModule(new ApplicationModule(this))
.build();
}

public DemoComponent dgaeacomponent() {
return dgaeacomponent;
}

}

带有 Dagger 2 的新 Android 注入(inject)器不支持 MultiDex ?

最佳答案

您是否已将当前应用程序声明为 AndroidManifest.xml 中应用程序标记中的 android:name ?

就您而言,您必须使用扩展 multiDexApplication 的应用程序。

关于java - MultiDexApplication 未实现 HasActivityInjector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46530161/

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