I'm using Hilt for dependency injection in my Android project. The project builds and runs perfectly on macOS, but I encounter a NullPointerException when building on Windows 10. The error occurs during Hilt's processing phase, specifically related to AggregatedDepsMetadata.
Error Message:
error: [Hilt]
Could not get element for com.junenineposeTemplate.MyApp_GeneratedInjector: java.lang.NullPointerException: Could not get element for com.junenineposeTemplate.MyApp_GeneratedInjector
...
[Hilt] Processing did not complete. See error above for details.
1 error
FAILURE: Build failed with an exception.
Code Snippets:
AppModule:
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
private const val BASE_URL = "/"
@Singleton
@Provides
fun providesHttpLoggingInterceptor() = HttpLoggingInterceptor()
.apply {
level = HttpLoggingInterceptor.Level.BODY
}
@Singleton
@Provides
fun providesOkHttpClient(httpLoggingInterceptor: HttpLoggingInterceptor): OkHttpClient =
OkHttpClient
.Builder()
.addInterceptor(httpLoggingInterceptor)
.build()
@Singleton
@Provides
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
}
MyApp:
@HiltAndroidApp
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
FirebaseApp.initializeApp(this)
}
}
Environment Details:
Android Studio Ladybug | 2024.2.2 Hilt version 2.46.1
Gradle 8.1.2
Kotlin 1.9.21
JDK 17 (Windows), JDK 17 (macOS)