環境
私のプロジェクトには 2 つのモジュールがあります。
- Java/Kotlin モジュール
common - Android/Kotlin モジュール
app
common依存性注入のための Kotlin ライブラリである Koin に依存します。
dependencies {
implementation 'org.koin:koin-core:1.0.2'
}
使用例:
class MyPresenter: KoinComponent {
...
}
appAndroid コードに何も注入する必要がないため、Koin ライブラリに依存しません。すべての注入は共通コード (プレゼンター、インターセプターなど) 内にあります。
しかし、app依存しcommonます:
dependencies {
implementation project(':common')
}
使用例:
class MyFragment {
private val presenter = MyPresenter()
}
問題
をコンパイルできcommon、単体テストを実行できますcommonが、コンパイルしようとすると次のappエラーが発生します。
次のクラスのスーパータイプは解決できません。クラスパスに必要な依存関係があることを確認してください: class xxx.common.presenter.MyPresenter、未解決のスーパータイプ: org.koin.standalone.KoinComponent
私が走るとき./gradlew :app:dependencies
debugCompileClasspath
+--- project :common
debugRuntimeClasspath
+--- project :common
| +--- org.koin:koin-core:1.0.2
依存関係はruntime構成内にありますが、構成から欠落していcompileます。
私がこれまでに試したこと:
明らかに、Koin の依存関係を宣言したくないappので、いくつかのことを試しました。
の Koin 依存関係を変更api:
dependencies {
api 'org.koin:koin-core:1.0.2'
}
動作しません- とまったく同じ依存関係ツリーが得られimplementationます。
プロジェクトの依存関係の構成を変更します。
dependencies {
implementation project(path: ':common', configuration: `compile`)
}
機能していませんcommon- これについてはよくわかりませんでしたが、構成で依存関係が得られることを望んでいましたcompile。
の Koin 依存関係を変更compile:
dependencies {
compile 'org.koin:koin-core:1.0.2'
}
働く!依存関係が に表示され、debugCompileClasspathを実行できますapp。
質問
今私は混乱しています:
- Koin
appは直接使用しないので、依存関係は必要ないと思います。なぜですか?の静的型が でMyPresenterあるからKoinComponentですか? apideprecated と同じだと思いましたcompile。そうではないようです。- deprecated を使用する以外に別の方法はあり
compileますか?