I have two modules in my project:
common
app
common depends on Koin, which is a Kotlin library for dependency injection:
dependencies {
implementation 'org.koin:koin-core:1.0.2'
}
Usage example:
class MyPresenter: KoinComponent {
...
}
app does not depend on the Koin library because I do not need to inject anything in the Android code, all the injections are in the common code (presenters, interceptors, etc).
But app depends on common:
dependencies {
implementation project(':common')
}
Usage example:
class MyFragment {
private val presenter = MyPresenter()
}
I can compile common, I can run unit tests in common, but when I try to compile app I get this error:
Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class xxx.common.presenter.MyPresenter, unresolved supertypes: org.koin.standalone.KoinComponent
When I run ./gradlew :app:dependencies
debugCompileClasspath
+--- project :common
debugRuntimeClasspath
+--- project :common
| +--- org.koin:koin-core:1.0.2
The dependency is in the runtime configuration, but is missing from the compile configuration.
Obviously I don't want to declare the Koin dependency in app so I have tried several things:
Change Koin dependency for api:
dependencies {
api 'org.koin:koin-core:1.0.2'
}
Not working - I get the exact same dependency tree as with implementation.
Change project dependency configuration:
dependencies {
implementation project(path: ':common', configuration: `compile`)
}
Not working - I wasn't sure of this one but I was hoping it would get the dependencies of common in compile configuration.
Change Koin dependency for compile:
dependencies {
compile 'org.koin:koin-core:1.0.2'
}
Working! The dependency appears in the debugCompileClasspath and I am able to run the app.
Now I am confused:
app does not use Koin directly, I though it would not need the dependency. Why does it? Is it because the static type of MyPresenter is KoinComponent?api was the same than the deprecated compile. It seems not.compile?api configuration is what you should use and should workapi is, how the consumable configuration apiElements is built or accessed or ...To debug that, I would recommend creating a simple project that reproduces the problem and that can be shared as there might be a bug behind that in the android or kotlin plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With