牙签不注入依赖关系

我正在尝试用于依赖注入的牙签库,它比其他的更容易使用和测试。

但是,当我运行代码时,我正面临着一个问题,牙签没有注入任何东西。 我现在只是使用它,这是有点难以弄清楚。

我正在使用Kotlin,Android Studio 2.3.3和Gradle 2.3.3,这里是我的代码:

的build.gradle

//KOTLIN_VERSION=1.1.4 //TOOTHPICK_VERSION=1.0.8 compile "com.github.stephanenicolas.toothpick:toothpick-runtime:$TOOTHPICK_VERSION" compile "com.github.stephanenicolas.toothpick:smoothie:$TOOTHPICK_VERSION" kapt "com.github.stephanenicolas.toothpick:toothpick-compiler:$TOOTHPICK_VERSION" class AppModule : Module { constructor(application: Application) { bind(QuestionRepository::class.java).toInstance(QuestionRepository(application)) } } class MyApp : Application() { override fun onCreate() { super.onCreate() setupInjector() } fun setupInjector() { val appScope = Toothpick.openScope(this) appScope.installModules(SmoothieApplicationModule(this), AppModule(this)) if (BuildConfig.DEBUG) { Toothpick.setConfiguration(Configuration.forDevelopment()); } } } class MainViewModule : Module { constructor() { bind(MainPresenter::class.java).to(MainPresenter::class.java) } } class QuestionRepository @Inject constructor(application: Application) { val assetManager: AssetManager = application.assets //a couple of functions } class MainActivity : AppCompatActivity(), MainView, NavigationView.OnNavigationItemSelectedListener { @Inject lateinit var presenter: MainPresenter lateinit private var activityScope: Scope val binding: ActivityMainBinding by lazy { DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main) } override fun onCreate(savedInstanceState: Bundle?) { setUpInject() super.onCreate(savedInstanceState) setUpView() } override fun onDestroy() { Toothpick.closeScope(activityScope) super.onDestroy() } fun setUpInject() { activityScope = Toothpick.openScopes(application, this) activityScope.installModules(MainViewModule()) Toothpick.inject(this, activityScope) //println(activityScope.toString()) presenter.onAttachView(this) } fun setUpView() { // } //Omit implemented method of OnNavigationItemSelectedListener } class MainPresenter @Inject constructor() {} 

错误信息:

 kotlin.UninitializedPropertyAccessException: lateinit property presenter has not been initialized 

它在MainActivity中打印activityScope时显示:

  Providers: [com.ispark.app.MainPresenter,toothpick.Scope] 

当我检查KotlinWeather示例时,代码没有在活动中安装任何模块,但仍然注入依赖关系。 我不知道它是如何工作的。 无论如何,我对牙签还是比较陌生的,我错过了什么?

感谢您的帮助。

EDIT1:

在build.gradle中,我用annotationProcessor替换kapt“com.github.stephanenicolas.toothpick:toothpick-compiler:$ TOOTHPICK_VERSION”,但是仍然是一样的。

AndroidBinding库有没有可能的问题?

EDIT2:

activityScope日志不适用于activityScope,但它是从牙签日志。 activityScope是activityScope:com.ispark.app.MainActivity@2a0e3388:303497268