MultiDexApplication未实现HasActivityInjector

时间:2017-10-02 16:58:26

标签: java android dagger-2

我使用新的Android Injector和https://medium.com/@iammert/new-android-injector-with-dagger-2-part-1-8baa60152abe

的Dagger 2

在MultiDex支持之前,App已经发挥作用。 我已经为app / build.gradle和AndroidManifest.xml添加了multidex支持。 在MultiDex支持之后,我通过安装在设备上获得了错误logcat

  

致命的例外:主要                                                      java.lang.RuntimeException:无法启动活动ComponentInfo {com.eusecom.samfantozzi / com.eusecom.samfantozzi.Detail2Activity}:java.lang.RuntimeException:android.support.multidex.MultiDexApplication未实现dagger.android.HasActivityInjector                                                          在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)                                                          在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)                                                          在android.app.ActivityThread.access $ 700(ActivityThread.java:159)                                                          在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)                                                          在android.os.Handler.dispatchMessage(Handler.java:99)                                                          在android.os.Looper.loop(Looper.java:137)                                                          在android.app.ActivityThread.main(ActivityThread.java:5419)                                                          at java.lang.reflect.Method.invokeNative(Native Method)                                                          在java.lang.reflect.Method.invoke(Method.java:525)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1187)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)                                                          at dalvik.system.NativeStart.main(Native Method)                                                       引起:java.lang.RuntimeException:android.support.multidex.MultiDexApplication没有实现dagger.android.HasActivityInjector                                                          在dagger.android.AndroidInjection.inject(AndroidInjection.java:48)                                                          在com.eusecom.samfantozzi.Detail2Activity.onCreate(Detail2Activity.java:19)                                                          在android.app.Activity.performCreate(Activity.java:5372)                                                          在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)                                                          在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)                                                          在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)                                                          在android.app.ActivityThread.access $ 700(ActivityThread.java:159)                                                          在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1316)                                                          在android.os.Handler.dispatchMessage(Handler.java:99)                                                          在android.os.Looper.loop(Looper.java:137)                                                          在android.app.ActivityThread.main(ActivityThread.java:5419)                                                          at java.lang.reflect.Method.invokeNative(Native Method)                                                          在java.lang.reflect.Method.invoke(Method.java:525)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1187)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)                                                          在dalvik.system.NativeStart.main(本地方法)

我的App.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注入器不支持MultiDex?

1 个答案:

答案 0 :(得分:10)

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

在您的情况下,您必须使用扩展multiDexApplication的那个。