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.

Incorrectly getting error: There are multiple contributed bindings with the same bound type

See original GitHub issue

Hi folks I’m getting pretty certain that there is a bug in the version of anvil that brought in contributes subcomponent. I first saw it in sample app and now in our main app when integrating our anvil wrapping library. Generally what happens is I run the application and everything is fine, next I make a change. I rerun through android studio and I get a duplicate binding for a random class. Always a class that is a ContributesBinding and always a class that is in a file different than the class name. In my sample I moved all contributes bindings to their own file and the error has not happened since.

This is the trace. I’ve been a bit overwhelmed with life/baby and unable to make a sample for you but just wanted to let you know its still happening, its happened 5 times to me this am. Doing a clean fixes it every time. We are on kotlin 1.5.31. It surprises me no one else has hit/is reporting the same. I don’t believe my setup is atypical

com.squareup.anvil.compiler.api.AnvilCompilationException: Back-end (JVM) Internal error: There are multiple contributed bindings with the same bound type. The bound type is com.dropbox.common.feature_gating.`annotation`.FeatureGatingRegistrar. The contributed binding classes are: [com.dropbox.skeleton_sandbox.app.RealNoAuthFeatureGatingRegistry, com.dropbox.skeleton_sandbox.app.RealNoAuthFeatureGatingRegistry]
File is unknown

	at com.squareup.anvil.compiler.codegen.BindingModuleGeneratorKt.findHighestPriorityBinding(BindingModuleGenerator.kt:375)
	at com.squareup.anvil.compiler.codegen.BindingModuleGeneratorKt.access$findHighestPriorityBinding(BindingModuleGenerator.kt:1)
	at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.flush$lambda-13$getContributedBindingClasses(BindingModuleGenerator.kt:248)
	at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.flush(BindingModuleGenerator.kt:256)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted$flush(CodeGenerationExtension.kt:99)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted(CodeGenerationExtension.kt:110)

The first time I hit this issue was in github.com/dropbox/kaiken the next time was while integrating the newest version of Kaiken into our internal code base. I’m not sure if Kaiken has something that is an atypical config, the only thing I can think of is we have a code generator that plugs into Anvil

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
digitalbuddhacommented, Jan 19, 2022

I think I have a repo case with Kaiken sample: https://github.com/dropbox/kaiken/tree/main/sample/sample-with-di. Download the repo, open in studio, sync and press “play” for sample.sample-with-di.app It should deploy onto your device Change the following line to @BindsInstance app: Application from @BindsInstance app: SkeletonOwnerApplication,

https://github.com/dropbox/kaiken/blob/9c11e112ded52ad0dfafae88c5bad20c0b706058/sample/sample-with-di/app/src/main/java/com/dropbox/kaiken/sample/advancedsample/app/AdvancedKaikenSampleApplication.kt#L47

Press play again. It should give following error:

File is unknown

	at com.squareup.anvil.compiler.codegen.BindingModuleGeneratorKt.findHighestPriorityBinding(BindingModuleGenerator.kt:375)
	at com.squareup.anvil.compiler.codegen.BindingModuleGeneratorKt.access$findHighestPriorityBinding(BindingModuleGenerator.kt:1)
	at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.flush$lambda-13$getContributedBindingClasses(BindingModuleGenerator.kt:248)
	at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.flush(BindingModuleGenerator.kt:256)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted$flush(CodeGenerationExtension.kt:99)
	at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted(CodeGenerationExtension.kt:110)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$invokeExtensionsOnAnalysisComplete(TopDownAnalyzerFacadeForJVM.kt:112)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:122)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:86)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:252)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:243)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:113)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:243)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:90)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:56)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:412)
	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:112)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:358)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:300)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:160)
	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:81)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:607)
	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:96)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1658)
	at jdk.internal.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)

Clean and it should work again. Change back and same error Clean again error goes away

1reaction
RBusarowcommented, Jan 16, 2022

I don’t think this is related to @ContributesSubcomponent. The same goes for #349, obviously. The @ContributesSubcomponent issue (#459) is a problem because it’s trying to bind different classes to the same interface type. In this issue and #349, Anvil thinks we’re trying to bind the same implementation to the same interface two times.

Early in the compilation, Anvil looks for files with @ContributesBinding annotations, and generates lightweight “hint” files from them. Later, when generating components, Anvil looks for these hint files in order to get a list of bound types.

The file path is something like this: build/anvil/src-gen-debug/anvil/hint/binding/com/example/com_example_Parmesan.kt, with the important part being that it’s in the binding package. We get the fqName of each bound type by looking for “_reference” properties like this one:

public val com_example_Parmesan_reference: KClass<Parmesan> = Parmesan::class

So either there’s a duplicate file, a daemon thinks there’s a duplicate file, or perhaps we’re handling multiple source sets incorrectly (this is part of the issue with #459).

So if you’re getting an error that the same concrete type is bound multiple times…

  1. Is the build fixed if you kill the Kotlin daemon process?
  • Get the process ID from terminal:
$ jps

output should be something like:

3536 GradleDaemon
3489 
7589 GradleDaemon
4261 KotlinCompileDaemon
5288 GradleDaemon
798 
15775 Jps
  • Find the process ID matching the KotlinCompileDaemon, then kill it:
kill -9 4261
  1. Is the build fixed if you do ./gradlew --stop and then try again?
  2. Are there multiple binding hint files referencing the same type? Check other directories as well. Maybe just search the whole project for com_example_Parmesan_reference. a. If yes, where are they? Is the build fixed if you delete them all?

We can fix this issue (or band-aid the symptom) by ignoring duplicate FqNames when doing this “multiple contributed bindings” check and generating the code. That’s pretty simple. But obviously it would be nice to know why it’s happening first.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Knockout.js v2.3.0 error "You cannot apply bindings multiple ...
If you are reusing an element over and over (a Bootstrap modal dialog in my case), then calling ko.applyBindings(el) multiple times will cause...
Read more >
Troubleshooting Bindings - Xamarin.Android - Microsoft Learn
Problem : Missing C# types in generated output. The binding .dll builds but misses some Java types, or the generated C# source does...
Read more >
Template type checking - Angular
Just as TypeScript catches type errors in your code, Angular checks the expressions and bindings within the templates of your application and can...
Read more >
Multibindings - Dagger
Or you could have several modules contribute individual service providers to a map, keyed by name ... Now a binding in that component...
Read more >
Devicetree bindings - Zephyr Project Documentation
The baz-device node would get matched to a binding with a compatible: ... configuration. array-with-default: type: array default: [1, 2, 3] # Same...
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