Question
Missing classes detected while running R8
I have a multi module project setup like this:
app module
presentation module (Android module)
domain module (Kotlin module)
data module (Android module)
The dependency graph
presentation -> domain <- data
And app has dependency in all modules.
The code is the following:
domain module:
interface RemoteVenuesDataSource {
suspend fun getVenues(): Result<List<Venue>, DataError.Network>
}
class GetVenuesUseCase(
private val remoteVenuesDataSource: RemoteVenuesDataSource,
) {
suspend operator fun invoke() = remoteVenuesDataSource.getVenues()
}
data module:
@Provides
@Singleton
fun provideHttpClient(): HttpClient {
return HttpClientFactory().build()
}
@Provides
@Singleton
fun provideRemoteVenuesDataSource(
httpClient: HttpClient,
): RemoteVenuesDataSource {
return KtorVenuesRemoteDataSource(
httpClient = httpClient
)
}
presentation module:
class GetVenuesUseCase(
private val remoteVenuesDataSource: RemoteVenuesDataSource,
) {
suspend operator fun invoke() = remoteVenuesDataSource.getVenues()
}
@Provides
@ViewModelScoped
fun provideGetVenuesUseCase(
remoteVenuesDataSource: RemoteVenuesDataSource,
): GetVenuesUseCase {
return GetVenuesUseCase(
remoteVenuesDataSource
)
}
and this gets injected into the viewmodel:
@HiltViewModel
class VenuesViewModel @Inject constructor(
private val getVenuesUseCase: GetVenuesUseCase,
)
and this viewmodel gets used like this:
@Composable
fun VenuesScreenRoot(
viewModel: VenuesViewModel = hiltViewModel(),
) {
Text(text = "Temp")
viewModel.temp()
}
And in the app module:
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContent {
TempTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greeting(
name = "Android",
modifier = Modifier.padding(innerPadding)
)
VenuesScreenRoot(
)
}
}
}
}
}
When I run the build in debug everything works, but If I switch to the release build (minify enabled) it breaks.
The app module generates this missing_rules.txt
# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.temp.data.di.SingletonModule
-dontwarn com.temp.data.di.SingletonModule_ProvideHttpClientFactory
-dontwarn com.temp.data.di.SingletonModule_ProvideRemoteVenuesDataSourceFactory
-dontwarn com.temp.presentation.theme.ThemeKt
-dontwarn com.temp.presentation.venus.VenuesScreenKt
-dontwarn com.temp.presentation.venus.VenuesViewModel
and this error message:
Missing class com.temp.data.di.SingletonModule (referenced from: com.temp.data.di.SingletonModule com.temp.DaggerHoaxCoffeeApplication_HiltComponents_SingletonC$Builder.singletonModule and 5 other contexts)
Missing class com.temp.data.di.SingletonModule_ProvideHttpClientFactory (referenced from: java.lang.Object com.temp.DaggerHoaxCoffeeApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get())
Missing class com.temp.data.di.SingletonModule_ProvideRemoteVenuesDataSourceFactory (referenced from: java.lang.Object com.temp.DaggerHoaxCoffeeApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get())
Missing class com.temp.data.di.SingletonModule_ProvideTempFactory (referenced from: java.lang.Object com.temp.DaggerHoaxCoffeeApplication_HiltComponents_SingletonC$SingletonCImpl$SwitchingProvider.get())
Missing class com.temp.presentation.theme.ThemeKt (referenced from: void com.temp.ComposableSingletons$MainActivityKt$lambda-3$1.invoke(androidx.compose.runtime.Composer, int))
Missing class com.temp.presentation.venus.VenuesScreenKt (referenced from: void com.hoax.coffee.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(androidx.compose.foundation.layout.PaddingValues, androidx.compose.runtime.Composer, int))
Missing class com.temp.presentation.venus.VenuesViewModel (referenced from: void com.temp.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(androidx.compose.foundation.layout.PaddingValues, androidx.compose.runtime.Composer, int))
and
Caused by: [CIRCULAR REFERENCE: com.android.tools.r8.internal.g: Missing class com.temp.data.di.SingletonModule (referenced from: com.temp.data.di.SingletonModule com.temp.DaggerHoaxCoffeeApplication_HiltComponents_SingletonC$Builder.singletonModule and 5 other contexts)
But I dont want to add keep files into the app module because I would have to add so much in the end which I created I would lose the meaning of R8.
As you can see I also created the Theme file and a VenusViewModel in the presentation package and R8 also complains about it. If I would have to add every viewmodel which I create in the presentation package then R8 would just lose its meaning.
agp = "8.5.1"
hilt = "2.51.1"
kotlin = "2.0.0"
ksp = "1.8.10-1.0.9"