1

我正在开发的应用程序在生产中崩溃,用户正在报告以下堆栈跟踪。问题是我自己无法重现它。

Caused by: toothpick.registries.NoFactoryFoundException: 
  at toothpick.registries.FactoryRegistryLocator.getFactoryUsingRegistries (FactoryRegistryLocator.java:49)
  at toothpick.configuration.ReflectionOffConfiguration.getFactory (ReflectionOffConfiguration.java:11)
  at toothpick.configuration.Configuration.getFactory (Configuration.java:113)
  at toothpick.registries.FactoryRegistryLocator.getFactory (FactoryRegistryLocator.java:38)
  at toothpick.ScopeImpl.lookupProvider (ScopeImpl.java:329)
  at toothpick.ScopeImpl.getInstance (ScopeImpl.java:58)
  at toothpick.ScopeImpl.getInstance (ScopeImpl.java:49)
  at my.package.name.activity.MainActivity$$MemberInjector.inject (MainActivity$$MemberInjector.java:13)
  at my.package.name.activity.MainActivity$$MemberInjector.inject (MainActivity$$MemberInjector.java:10)
  at toothpick.InjectorImpl.inject (InjectorImpl.java:25)
  at toothpick.Toothpick.inject (Toothpick.java:149)
  at my.package.name.BaseActivity.injectInScopes (BaseActivity.java:17)
  at my.package.name.activity.MainActivity.onCreate (MainActivity.java:120)
  at android.app.Activity.performCreate (Activity.java:6876)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1135)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3206)

对于不同的用户,它在不同的时间在不同的活动中崩溃。如下所示,缺失的工厂存在(至少对我而言)。

public final class MainActivity$$MemberInjector implements MemberInjector<MainActivity> {
  @Override
  public void inject(MainActivity target, Scope scope) {
    target.myLogger = scope.getInstance(MyLogger.class);
    ...
  }
}

失踪的工厂:

public final class MyLoggerImpl$$Factory implements Factory<MyLoggerImpl> {
  @Override
  public MyLoggerImpl createInstance(Scope scope) {
    scope = getTargetScope(scope);
    RestApi param1 = scope.getInstance(RestApi.class);
    Scope param2 = scope.getInstance(Scope.class);
    MyLoggerImpl myLoggerImpl = new MyLoggerImpl(param1, param2);
    return myLoggerImpl;
  }

  @Override
  public Scope getTargetScope(Scope scope) {
    return scope;
  }

  @Override
  public boolean hasScopeAnnotation() {
    return false;
  }

  @Override
  public boolean hasProvidesSingletonInScopeAnnotation() {
    return false;
  }
}

模块:

bind(MyLogger.class).to(MyLoggerImpl.class).singletonInScope();

当使用Toothpick反射或无反射配置时会发生这种情况。关于为什么我得到这个例外的任何想法?

4

1 回答 1

2

我想出了这个。我以错误的方式使用牙签,当应用程序在后台运行一段时间并且用户重新进入应用程序时,我的范围没有重新创建。

自我注意:当应用程序在后台时,Android 应用程序和活动可以被 Android 杀死。确保应用程序和牙签可以从中安全恢复。保持依赖注入模型简单。

于 2018-01-05T11:40:34.683 回答