반응형
TL; DR
2022-05-11, dagger 2.42, startup 1.20.0-alpha01 기준 불가능합니다.
문제
App Startup 적용 이후 AndroidTest(Instrumented Test)가 실행되지 않습니다. (debugger 무한 대기)
Logcat을 보니 다음과 비슷한 오류가 찍힙니다.
2022-04-11 10:41:09.352 24409-24409/com.example.appstartupinstrumentationtest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.appstartupinstrumentationtest, PID: 24409
java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
at android.app.ActivityThread.installProvider(ActivityThread.java:8195)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:7726)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7546)
at android.app.ActivityThread.access$1500(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: androidx.startup.StartupException: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:162)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:198)
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:38)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2429)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2399)
at android.app.ActivityThread.installProvider(ActivityThread.java:8190)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:7726)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7546)
at android.app.ActivityThread.access$1500(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
at dagger.hilt.internal.Preconditions.checkState(Preconditions.java:83)
at dagger.hilt.android.internal.testing.TestApplicationComponentManager.generatedComponent(TestApplicationComponentManager.java:96)
at dagger.hilt.android.testing.HiltTestApplication.generatedComponent(HiltTestApplication.java:49)
at dagger.hilt.EntryPoints.get(EntryPoints.java:59)
at dagger.hilt.android.EntryPointAccessors.fromApplication(EntryPointAccessors.kt:35)
at com.example.appstartupinstrumentationtest.InitializerEntryPoint$Companion.resolve(InitializerEntryPoint.kt:20)
at com.example.appstartupinstrumentationtest.SomeComponentInitializer.create(SomeComponentInitializer.kt:10)
at com.example.appstartupinstrumentationtest.SomeComponentInitializer.create(SomeComponentInitializer.kt:7)
at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:155)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:198)
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:38)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2429)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2399)
at android.app.ActivityThread.installProvider(ActivityThread.java:8190)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:7726)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7546)
at android.app.ActivityThread.access$1500(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
출처: https://github.com/google/dagger/issues/3356
따끈따끈한 이슈...
근데 사실 1년 전에도 제기된 적 있습니다.
https://github.com/google/dagger/issues/2016#issuecomment-788770446
이슈가 생성됐으니 해결을 해야죠! 해당 에러를 해결한 dagger 2.42가 어제 출시되었습니다. 빠르네요!
https://github.com/google/dagger/releases/tag/dagger-2.42
근데 간단한 샘플 앱에서는 문제가 해결되는 반면, 실제 앱에 적용하니 여전히 문제가 지속됩니다. 근본적인 문제는 startup의 초기화 시점과 관련이 있기 때문에... 일단은 dagger 팀에서 androidx.startup 팀에 이슈트래커를 남겨놓았습니다.
https://issuetracker.google.com/issues/230844558
따라서 androidx.startup이 새 버전으로 릴리즈 되고, 안정화 되기 전까지는 보류해야 하는 문제입니다...
교훈: 다들 AndroidTest를 사용하지 않는다!
반응형
'Android > TDD(Test Driven Development, 테스트 주도 개발)' 카테고리의 다른 글
kotest Project Config 다른 모듈과 공유 (0) | 2022.04.14 |
---|---|
Turbine 없이 kotest에서 StateFlow, SharedFlow 테스트 하기, Unit Test (1) | 2022.04.12 |
로버트 C. 마틴 TDD 3원칙 - TDD(Test Driven Development) (0) | 2021.12.17 |
Unit Test(유닛 테스트) 팁 5가지 - TDD(테스트 주도 개발) (0) | 2021.12.16 |
Mockito 프레임워크 - TDD(테스트 주도 개발) (0) | 2021.12.14 |