MetroX Android¶
Core Android support for Metro. This artifact specifically focuses on integration with AppComponentFactory, which requires API 28+. As a result, this artifact requires min SDK 28 since it’s useless on older versions.
Usage¶
For simple cases, all you need to do is
-
Depend on this artifact
dependencies { implementation("dev.zacsweers.metro:metrox-android:x.y.z") }
2. Make yourAppGraph(or equivalent) implementMetroAppComponentProviders.
@DependencyGraph(AppScope::class) interface AppGraph : MetroAppComponentProviders
3. Make yourApplicationsubclass implementMetroApplicationand implementappComponentProviders.
class MyApp : Application(), MetroApplication { private val appGraph by lazy { createGraph<AppGraph>() } override val appComponentProviders: MetroAppComponentProviders get() = appGraph }
Advanced¶
If you have your own custom AppComponentFactory, you will need to exclude the MetroX implementation in your AndroidManifest.xml via tools:replace attribute.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
...
android:appComponentFactory="your.custom.AppComponentFactory"
tools:replace="android:appComponentFactory"
>
</application>
</manifest>
Then you can replicate what MetroAppComponentFactory does or subclass it in your custom factory.