Comments (5)
Unfortunately, being able to override standard methods is going to be a requirement for using Hilt. In that BroadcastReceiver example, we inject in onReceive
, so there's not much we can do if it is final. I know there is a new onMessageReceived
that users are supposed to override, but there's not really going to be a good way for Hilt to know how to use that. Same for any other method we might try to use. Like for onCreate
there happens to be the lifecycle as an alternative (though that changes the timing and order as of calls), but for things like getDefaultViewModelProviderFactory
, we have to be able to override it. It would be too limiting to say Hilt has to deal with the possibility of any standard method being possibly unavailable to override.
The best you can do is raise issues to libraries that make these methods final and ask them to use something like @CallSuper
instead. Otherwise, as a workaround, you can try to use @EntryPoint
annotations to inject dependencies, though for things like Activities that have their own component that unfortunately won't help you create a component for the activity to own, it'll just help you get things from the SingletonComponent
.
I'm going to leave this issue open though since we could give a better error message in these cases, rather than just generating the method and letting the compiler catch the override issue.
from dagger.
Hi, Caleb, we had to override the lifecycle methods in order to lazily provide SavedStateHandle, I'll try to improve the error message, do you have to use final for those methods?
from dagger.
Let me follow up to see if we can get our own custom activity to remove final. I have a suspicion those were added a long time ago and is now obsolete. It's honestly also a bit of an antipattern anyways.
from dagger.
@wanyingd1996 - We removed final
from our base Activity classes. Can probably close this out. (That said, still wondering if there's another pattern of implementation that could avoid this, but probably another conversation to be had if this is a more common issue)
from dagger.
This effects any other abstract/custom implementation with final interface methods (like BroadcastReceivers on an SMS app using klinker logic).
from dagger.
Related Issues (20)
- Explain how to add dagger jar files manually to the android project HOT 2
- Annotate interface with default Bind implementation HOT 2
- Transitive vulnerability from symbol-processing-api HOT 1
- java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY` HOT 4
- Update of different dependency: Error "package javax.annotation.processing is not visible" HOT 4
- Compile time error with KSP with Generics HOT 4
- java.lang.IllegalArgumentException: Multiple entries with same key HOT 4
- Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction > java.lang.reflect.InvocationTargetException (no error message) HOT 2
- Stackoverflow when exposing parents of Subcomponents HOT 7
- Hilt not working with android testFixtures? HOT 2
- Hilt 2.44.2 - Class not found when use @AndroidEntryPoint at WidgetReceiver HOT 1
- Does Dagger 2.51 support JDK17 and JDK21? HOT 1
- [KSP] Intersection type bounds are not ordered correctly in generated factories HOT 1
- [KSP] KSP mode does not check for `@Provides` on interface methods HOT 1
- [KSP] Multibinding example from developer docs does not compile under Kotlin + KSP HOT 1
- [KSP] How to pass compiler argument to KSP? HOT 4
- The lack of sprite in the Friday Night Funkin character
- Subcomponent MembersInjector error in 2.51 HOT 1
- Does Hilt always execute app module during instrumented test? HOT 3
- [KSP] Dagger-KSP does not see typealiased dagger annotations HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.