2

I use New Android Injector with Dagger 2 by https://medium.com/@iammert/new-android-injector-with-dagger-2-part-1-8baa60152abe

Before MultiDex support App has worked. I have added multidex support to app/build.gradle and AndroidManifest.xml. After MultiDex support i have got error logcat by instaling on device

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) 

My 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;
    }

}

New Android Injector with Dagger 2 does not support MultiDex ?

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
eurosecom
  • 2,932
  • 4
  • 24
  • 38

1 Answers1

12

Have ou declared your current Application as the android:name in application tag in AndroidManifest.xml?

In your case, you must use the one that extends multiDexApplication.

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • I replaced `application` name to `android.support.multidex.MultiDexApplication` as said in https://stackoverflow.com/questions/46304196/unable-to-get-provider-android-arch-lifecycle-lifecycleruntimetrojanprovider-ja and got this error. – CoolMind Feb 16 '18 at 18:24
  • 1
    `android:name` is very important for some reason. Who knows why :) – Daniel Wilson Aug 24 '18 at 13:20