if (BuildConfig.Theme == "red") {
RedTheme { ... }
}else {
GreenTheme { ... }
}This is under src/red
// AppTheme.kt
@Composable
fun AppTheme(content: @Composable () -> Unit) {
RedTheme(content)
}This is under src/green
// AppTheme.kt
@Composable
fun AppTheme(content: @Composable () -> Unit) {
GreenTheme(content)
}First, you need to define the dependency in build.gradle.kts
"cameraImplementation"(project(":image-source-camera")
"fileSystemImplementation"(project(":image-source-fs")In the image-source-api module
interface ImageSource {
...
}In the image-source-camera module
class CameraImageSource : ImageSource {...}in the image-source-fs module
class FileSystemImageSource : ImageSource {...}In the app module, source set src/camera
@Module
@InstallIn(AppScope.class)
abstract class CameraImageSourceModule {
abstract fun bindCameraImageSource(source: CameraImageSource): ImageSource
}In the app module, source set src/filesystem
@Module
@InstallIn(AppScope.class)
abstract class CameraImageSourceModule {
abstract fun bindCameraImageSource(source: FileSystemImageSource): ImageSource
}The usage in other modules. We don't need to declare anything related to flavor since it's all configured via the host (application module)
class ImagePicker @Inject constructor(
private val imageSource: ImageSource
) {
...
}Since we're using hilt (same goes with Anvil) we don't exactly need to define the Dagger module in the custom source set.
We can easily define the module in each image source module (image-source-camera and image-source-fs's src/main)