Hilt with Custom Views and @AndroidEntryPoint, generating @Nullable annotation twice
See original GitHub issueHi there 👋 I’m trying to migrate my project to use Hilt from Dagger Android.
I’ve run into an issue where adding @AndroidEntryPoint
onto a custom view, produces a compilation issue on the generated custom view component.
The custom view looks similar to the following:
@AndroidEntryPoint
class CustomShapeView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
CustomBaseView<ShapeLayer>(context, attrs, defStyleAttr) {
@Inject
lateinit var customInjectedClass: CustomInjectedClass
And now when I run the build, it breaks with the generated class for the view looking as follows:
/**
* A generated base class to be extended by the @dagger.hilt.android.AndroidEntryPoint annotated class. If using the Gradle plugin, this is swapped as the base class via bytecode transformation.
*/
@Generated("dagger.hilt.android.processor.internal.androidentrypoint.ViewGenerator")
public abstract class Hilt_CustomShapeView<T> extends CustomBaseView<T> implements GeneratedComponentManager<Object> {
private ViewComponentManager componentManager;
Hilt_CustomShapeView(@NotNull Context arg0, @Nullable @Nullable AttributeSet arg1,
int arg2) {
super(arg0, arg1, arg2);
inject();
}
Hilt_CustomShapeView(@NotNull Context arg0, @Nullable @Nullable AttributeSet arg1) {
super(arg0, arg1);
inject();
}
Hilt_CustomShapeView(@NotNull Context arg0) {
super(arg0);
inject();
}
You can see the first two generated constructors for the view has the @Nullable
annotation twice on the AttributeSet
.
The compilation error is the following:
error: Nullable is not a repeatable annotation type
Hilt_CustomShapeView(@NotNull Context arg0, @Nullable @Nullable AttributeSet arg1,
I tried to remove the @JvmOverloads
annotation and create the constructors one by one, but that didn’t seem to make a difference either.
I’m not sure if I’m missing something, but I think this is a bug.
Issue Analytics
- State:
- Created 3 years ago
- Comments:26 (6 by maintainers)
Top Results From Across the Web
Android ViewModel instantiate twice using hilt - Stack Overflow
viewModels() delegation create view model against the same instance i.e Fragment's instance in your case. What you need to do is to create...
Read more >Zac Sweers on Twitter: "☕️✍️ JavaPoet 1.13.0 is out with ...
Hilt with Custom Views and @AndroidEntryPoint, generating @Nullable annotation twice · Issue #1909... ... I'm trying to migrate my project to use ...
Read more >All about Hilt. Get deeper understanding about Hilt.
Hilt is a dependency injection framework for Android that is built on ... Step 5 - Create a custom scope annotation: Hope now...
Read more >Dependency injection with Hilt | Android Developers
Hilt is a dependency injection library for Android that reduces the boilerplate of doing manual dependency injection in your project.
Read more >Testing Fragments with Dagger-Hilt - Part 12 - YouTube
In this video I will show you a workaround to be able to test fragments with the help of Dagger- Hilt.⭐ Get certificates...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
JavaPoet 1.13.0 is available now on maven central: https://repo1.maven.org/maven2/com/squareup/javapoet/1.13.0/
Thanks to @egorand for the quick turnaround on it!
Heard back and they’re going to target releasing this week 👍