Dagger2 2.13 AndroidInjector StackOverflowError

时间:2018-07-23 08:19:15

标签: android dagger-2 dagger

我正在Dagger Github site上实现示例,我得到了

Cause: java.lang.StackOverflowError
    at com.sun.tools.javac.model.AnnotationProxyMaker.generateAnnotation(AnnotationProxyMaker.java:87)
    at com.sun.tools.javac.model.AnnotationProxyMaker.generateAnnotation(AnnotationProxyMaker.java:79)
    at com.sun.tools.javac.code.AnnoConstruct.getAnnotation(AnnoConstruct.java:179)
    at dagger.internal.codegen.MapKeys.unwrapValue(MapKeys.java:84)
    at dagger.internal.codegen.MapKeys.mapKeyType(MapKeys.java:93)
    at dagger.internal.codegen.Key$Factory.bindingMethodKeyType(Key.java:463)
    at dagger.internal.codegen.Key$Factory.forBindingMethod(Key.java:420)
    at dagger.internal.codegen.Key$Factory.forBindsMethod(Key.java:384)

这是我从示例中复制的代码

@Component(modules = {ApplicationModule.class, AndroidSupportInjectionModule.class})
@Singleton
public interface ApplicationComponent extends AndroidInjector<MyApplication> {

}

@Module(subcomponents = {YourActivitySubcomponent.class})
public abstract class ApplicationModule {

}

@Subcomponent(modules = {YourActivityModule.class})
public interface YourActivitySubcomponent extends AndroidInjector<MainActivity> {
    @Subcomponent.Builder
    public abstract class Builder extends AndroidInjector.Builder<MainActivity> {
    }
}

@Module(subcomponents = {YourActivitySubcomponent.class})
public abstract class YourActivityModule {
    @Binds
    @IntoMap
    @ActivityKey(MainActivity.class)
    abstract AndroidInjector.Factory<? extends MainActivity>
    bindYourActivityInjectorFactory(YourActivitySubcomponent.Builder builder);
}

public class MyApplication extends Application implements HasActivityInjector {

    @Inject
    DispatchingAndroidInjector<Activity> dispatchingActivityInjector;


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


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

public class MainActivity extends DaggerAppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

为什么会出现此错误?

0 个答案:

没有答案