google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.45k stars 2.02k forks source link

Problem with v2.40 and enableAggregatingTask #2997

Closed SteinerOk closed 2 years ago

SteinerOk commented 3 years ago

First of all: with 2.39.1 project compiles and run fine. After updating Dagger to 2.40 the project stopped building and gives an error:

* What went wrong:
Execution failed for task ':app:hiltJavaCompileGmsDebug'.
> java.lang.IllegalStateException: no component requirement expression found for ComponentRequirement{kind=BOUND_INSTANCE, wrappedType=MoreTypes.equivalence().wrap(ru.papirus.android.app.di.subcomponent.account.AccountPapirusSubApp), overrideNullPolicy=Optional.empty, key=Optional[ru.papirus.android.app.di.subcomponent.account.AccountPapirusSubApp], variableName=arg0}

I added code for disabling enableAggregatingTask:

hilt {
    enableAggregatingTask = false
}

After that, the build of the project is completed successfully, but at startup I get the application crash with the following error in the logs:

2021-11-09 03:25:30.592 27387-27387/ru.papirus.android.app.debug E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ru.papirus.android.app.debug, PID: 27387
    java.lang.RuntimeException: Unable to instantiate application ru.papirus.android.app.PapirusApp: java.lang.ClassNotFoundException: Didn't find class "ru.papirus.android.app.PapirusApp" on path: DexPathList[[dex file "/data/data/ru.papirus.android.app.debug/code_cache/.overlay/base.apk/classes20.dex", zip file "/data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/lib/arm64, /data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64, /system/product/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1268)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6690)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7664)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "ru.papirus.android.app.PapirusApp" on path: DexPathList[[dex file "/data/data/ru.papirus.android.app.debug/code_cache/.overlay/base.apk/classes20.dex", zip file "/data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/lib/arm64, /data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
        at androidx.core.app.CoreComponentFactory.instantiateApplication(CoreComponentFactory.java:52)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1160)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1260)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6690) 
        at android.app.ActivityThread.access$1300(ActivityThread.java:237) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:223) 
        at android.app.ActivityThread.main(ActivityThread.java:7664) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
        Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Lru/papirus/android/app/Hilt_PapirusApp;
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
                ... 14 more
     Caused by: java.lang.ClassNotFoundException: Didn't find class "ru.papirus.android.app.Hilt_PapirusApp" on path: DexPathList[[dex file "/data/data/ru.papirus.android.app.debug/code_cache/.overlay/base.apk/classes20.dex", zip file "/data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/base.apk"],nativeLibraryDirectories=[/data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/lib/arm64, /data/app/~~pIc67hHzc6AKwbXVC20BQA==/ru.papirus.android.app.debug-Y_hFu0ddHrOoZzjyT5Ug-Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/system_ext/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                ... 17 more
        [CIRCULAR REFERENCE:java.lang.NoClassDefFoundError: Failed resolution of: Lru/papirus/android/app/Hilt_PapirusApp;]
jraska commented 3 years ago

Hi, not using Hilt, but getting very similar issue with v2.40.1 after update from v2.39.1

@Subcomponent(modules = [SomeModule::class])
abstract class SomeSubcomponent {

    @Subcomponent.Factory
    interface Factory {
        fun create(@BindsInstance instance: InstanceType): SomeSubcomponent
    }
}

Results in failure:

Caused by: java.lang.IllegalStateException: no component requirement expression found for 
ComponentRequirement{kind=BOUND_INSTANCE, wrappedType=MoreTypes.equivalence().wrap(com.example.InstanceType), 
overrideNullPolicy=Optional.empty, key=Optional[com.example.InstanceType], variableName=arg0}

Changing to

@Subcomponent(modules = [SomeModule::class])
abstract class SomeSubcomponent {

    @Subcomponent.Builder
    interface Builder {
        @BindsInstance 
        fun instance(instance: InstanceType): Builder
        fun build(): SomeSubcomponent
    }
}

Fixes the issue, but fails later on different case of using the @Subcomponent.Factory.

bcorso commented 3 years ago

@jraska I wasn't able to repro the failure. Would you be able to create a sample project that repros this case?

jraska commented 3 years ago

Thanks for the fast reply :)

Will try soon once I get time for it - the snippets were extracted from larger project, though except subcomponents there is nothing too exotic 🤔

bcorso commented 2 years ago

@jraska thanks, I had some time to play around with it a bit more and was able to reproduce your error by moving the subcomponent into a separate Gradle module.

I think I found the issue and have a fix that I'll get out this week.