gpt4 book ai didi

Android动态加载模块

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:01:45 30 4
gpt4 key购买 nike

我想编写一个可以使用模块(android 库)扩展的 android 应用程序。模块应在运行时加载。因此,它们将从 url 下载并存储在目录中。这些模块是 aar 文件。

有没有办法在运行时动态加载aar文件?

我知道可以使用 URLClassLoader 加载包含的 classes.jar。但是我无法加载布局、字符串……资源。嗯

有没有人知道如何解决这个问题?

编辑:

我找到了几个相关主题:

由于第一个链接的答案,它似乎不起作用。我希望我的想法是错误的。

最佳答案

我遇到了类似的问题。我想在运行时添加插件而不强制用户重新安装应用程序。

我在“The Busy Coder's Guide to Android Development”一书中找到了一个非常好的章节,叫做“插件模式”。我仍在阅读它,所以不能真正说它是否完全满足您的需求,但它包含大量可能对您的案例有用的信息。

这是一个sample本章的详细信息,可在图书网页上找到,因此您可以大致了解其涵盖的内容

For the purposes of this chapter, a “plugin model” refers to an app (the plugin “host”) that is being extended by other apps (the “plugins”) that are largely dedicated to that job.

Certainly, there are plenty of ways that apps can work together without one being a plugin to another. The user’s Web browser is not a plugin of your app when you call startActivity() to view a Web page, for example.

By contrast, the Locale app can be extended via plugins, written either by two forty four a.m. (the authors of Locale) or third parties. These plugins have no real value to the user other than by how they improve what Locale itself can do. This sort of structure, therefore, qualifies as a plugin model.

In particular, this chapter will focus on two general scenarios for wanting a plugin model, though others certainly exist:

You want to allow third parties to extend the capability of your app, much as two forty four a.m. wanted with Locale, or You want to reduce the number of permissions in your core app by delegating some permissions to plugins, so users can “opt into” those permissions

希望对您有所帮助。

关于Android动态加载模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26712638/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com