在Android库中使用击键

问题描述:

我想在Android库中尝试Hilt DI.

I would like to try Hilt DI in the android library.

它是另一个项目的依赖项,带有其自己的子模块.我遇到的第一个问题是用@HiltAndroidApp标记Application的要求.现在我的ofc库中没有扩展Application的任何东西,但想利用Hilt及其预定义的组件.

It is a dependency on another project, with its own submodule. The very first problem I've encountered is the requirement of marking Application with @HiltAndroidApp. Now I do not have anything that extends Application in my library ofc but would like to utilize Hilt and its predefined components.

是否有可能或者仅在这种情况下才应使用Dagger?我找到了Dagger的解决方案,其中完全依赖于库依赖注入(客户端不知道库的DI):

Is it possible or should I go with Dagger only in such a case? I've found a solution for Dagger, where library dependency injection is made totally independently (the client is unaware of the library's DI): Dagger solution, would love to hear any opinion on that, maybe someone already put a great effort into that issue and can share his insights.

如果您尝试将Hilt包含在android 中,那么您应该期望android 应用 >(您的图书馆的客户的客户)将其Application标记为@HiltAndroidApp.

If you're trying to include Hilt in an android library, then you should expect the android app (client of your library) to mark its Application with @HiltAndroidApp.

您应该在 library 模块中包括整个设置(入口点,模块,依赖项,...,无论您想在库中拥有什么),并进行需求,以便库的客户端使用@HiltAndroidApp正确使用您的.

You should include your whole setup (entry points, modules, dependencies, ... whatever you want to have in your library) in the library module, and make the requirement for the client of the library to use the @HiltAndroidApp to use your library correctly.