question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build failes or hangs when using ContributesSubcomponent and you rename the module

See original GitHub issue

Basically the build failes after you rename a module and on the next build it hangs when using ContributesSubcomponent and you rename module.

I have done 3 attemps to build the project, on all of the attempts the code is correct, I haven’t changed anything.

1st: The build fails because it was trying to build the module which is renamed 2nd: The build hangs for 10 minutes 3rd: The build is successful.

Here is the minimum code with which you can reproduce it, this new file is inside the library module, next to the God, Description & DescriptionComponent classes.

package com.squareup.anvil.sample

import com.squareup.anvil.annotations.ContributesSubcomponent
import com.squareup.anvil.annotations.ContributesTo
import com.squareup.scopes.AppScope
import com.squareup.scopes.SingleIn
import dagger.BindsInstance
import dagger.Module
import dagger.Provides

class MyComponentScope private constructor()
class Argument(val value: Int)
class MappedArgument(val value: Int)

@SingleIn(MyComponentScope::class)
@ContributesSubcomponent(
  scope = MyComponentScope::class,
  parentScope = AppScope::class,
  modules = [MyComponentModule3::class]
)
interface MyComponent  {

  @ContributesTo(AppScope::class)
  interface ParentComponent {
    fun createSettingsFactory(): MyComponent.Factory
  }

  @ContributesSubcomponent.Factory
  interface Factory {

    fun create(@BindsInstance argument: Argument): MyComponent
  }
}

@Module
object MyComponentModule3 {

  @Provides
  fun arg(argument: Argument): MappedArgument = MappedArgument(argument.value)
}

The first time that i tried to build the project it failed with the following exception:

[kokeroulis@MacBook-Pro-2:~/github/anvil on main] 
% ./gradlew :sample:app:assembleDebug     

> Configure project :
Versions: [Kotlin:1.6.10, Gradle:7.4, Kotlin use IR in tests:true]

> Configure project :sample:app
Unable to detect AGP versions for included builds. All projects in the build should use the same AGP version. Class name for the included build object: org.gradle.composite.internal.DefaultIncludedBuild$IncludedBuildImpl_Decorated.

The following Kotlin source sets were configured but not added to any Kotlin compilation:
 * androidAndroidTestRelease
 * androidRelease
 * androidTestRelease
You can add a source set to a target's compilation by connecting it with the compilation's default source set using 'dependsOn'.
See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets

> Task :sample:library:compileKotlin FAILED
e: /Users/kokeroulis/github/anvil/sample/library/build/anvil/src-gen-main/com/squareup/anvil/sample/MyComponentModule2_ArgFactory.kt: (13, 34): Unresolved reference: MyComponentModule2
e: /Users/kokeroulis/github/anvil/sample/library/build/anvil/src-gen-main/com/squareup/anvil/sample/MyComponentModule2_ArgFactory.kt: (32, 36): Unresolved reference: MyComponentModule2

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sample:library:compileKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2s
52 actionable tasks: 1 executed, 51 up-to-date

I checked on the directory and MyComponentModule2_ArgFactory.kt is actually missing from the disk and MyComponentModule3_ArgFactory.kt is actually there.

Then i tried to build the project again and the build hang. I was waiting for 10 minutes on the task :sample:app:compileDebugKotlin.

Then I killed the build (ctrl + c on terminal), i build it again and it worked.

Steps to reproduce:

  1. Rename MyComponentModule to a different name e.g. (MyComponentModule2, MyComponentModule3 etc). I was doing the rename manually on the file without using the refactor functionality from AS (right click -> refactor -> rename).
  2. Build the project (./gradlew :sample:app:assembleDebug)
  3. Repeat until the build hangs or it fails to build.

Here is a screenshot of the 2nd attemp which caused the build to hang and from the 3rd attemp where the project build successfully.

Screenshot 2022-05-29 at 22 22 27

I am using AS bumblebee and the java version which is bundled with it.

[kokeroulis@MacBook-Pro-2:~/github/anvil on main]
% java -version                                                                                                                                                                                                                            
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7590822, mixed mode)

I am not quite sure how to debug this further. If you need anymore information, please let me know.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
vRallevcommented, Aug 17, 2022

I’m closing the issue for now, because I don’t see clear path forward. I’m happy to reopen the issue anytime.

0reactions
vRallevcommented, Aug 13, 2022

Does it hang when building from the command line? This could be an IDE issue. I have a hard time to suggest what else you could provide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ContributesSubcomponent issue in testing #459
Bit of context, I have a monorepo with 3 apps. Each app uses the same scopes, however each app is not feature identical....
Read more >
android - Dagger subcomponent with contributor
Problem is, while it's compiling and running, it crashes once it reaches to any feature fragments due to No injector factory bound for...
Read more >
Using Dagger in Android apps
Creating a new Dagger module (e.g. SubcomponentsModule ) passing the subcomponent's class to the subcomponents attribute of the annotation.
Read more >
Dagger 2. Part I. Basic principles, graph dependencies, ...
Dagger 2 is a library which helps the developer to implement a pattern of Dependency Injection (one specific form of Inversion of control)....
Read more >
Troubleshoot Start menu errors - Windows Client
Learn how to troubleshoot common Start menu errors in Windows 10. For example, learn to troubleshoot errors related to deployment, crashes, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found