简体   繁体   English

AAR 库的 Application()

[英]Application() of a AAR library

我在 android 上创建了一个 AAR 库并将其导入到另一个项目中当我尝试从这个库中执行一些东西时,它给出了一个错误,说 Room 没有启动,我在我的应用程序 () 中启动了 Room,这让我认为没有调用 AAR 库的 Application() 如何让这个 Application() 启动?

There isn't any application class in the android-library that triggered automatically. android-library中没有任何自动触发的应用程序类。 You should expose an entry point in your library in order to receive the context and init everything you need from there (for example the Room DB).您应该在库中公开一个入口点,以便接收上下文并从那里初始化您需要的一切(例如 Room DB)。

Another way (maybe a little bit more complicated) is to create a provider and attach it in the application's lifecycle.另一种方法(可能有点复杂)是创建一个提供者并将其附加到应用程序的生命周期中。 Here is an example .这是一个例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM