最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Hilt NullPointerException on Windows 10: Could not get element for MyApp_GeneratedInjector - Stack Overflow

programmeradmin1浏览0评论

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)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论