12

I wanna write an android application which can be extended with modules (android libraries). The modules shall be loaded at runtime. Therefore they'll be downloaded from an url and stored in a directory. The modules are aar files.

Is there a way to load aar files dynamically at runtime?

I know it's possible to just load the contained classes.jar with an URLClassLoader. But than I can't load the layout, string, ... resources. HM

Does anyone know a way how to solve this?

EDIT:

I found a few related topics:

It seems that it doesn't work because of the answer from the first link. I hope I'm wrong with that thinking.

Community
  • 1
  • 1
boeserwolf91
  • 166
  • 1
  • 7
  • See mozilla firefox for android, you can load a native plugin dynamically. – ceram1 Jul 12 '15 at 11:24
  • Did you ever succeed in dynamically loading aar-files? It seems only possible to dynamically load jar-files (since they have no resources). – jayeffkay Oct 27 '15 at 14:06
  • No, unfortunately I didn't find a way for loading aar-files dynamically. I wasn't successful with that. If you find a way, I would like to know it :) – boeserwolf91 Nov 05 '15 at 13:54
  • 1
    Have a look at [DashClock](https://github.com/romannurik/dashclock) for an example on how to make an app easily extensible. – Jonas Köritz Dec 10 '15 at 12:50
  • 1
    Hi ! Did you succeed in dynamically loading aar-files? :) – aeroxr1 May 21 '20 at 08:53
  • Maybe [Feature Delivery functionality of App Bundle](https://developer.android.com/platform/technology/app-bundle#customize-feature-delivery) could be used for this? – c0dehunter Aug 10 '20 at 04:43

2 Answers2

1

I'm having a kind of similar problem. i want to add plugins on runtime without forcing the user to reinstall the app.

I found a very good chapter called "Plugin Patterns" on "The Busy Coder's Guide to Android Development" book. I am still reading it so can't really say if it covers exactly your needs but it contains plenty of information that might be useful for your case.

Here is a sample of the chapter, found on the books web page, so you have an overview of what it covers

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

I hope that helps a bit.

Adam
  • 91
  • 3
  • 5
1

There is a gradle plugin that can help to decouple aar into resources and dexes. Check this out When you are building your project with inject dependency this plugin extract aar and merges resources with your project resources, than merges manifests and after that collects all jars(inside each aar and just jar dependencies) and creates a dex file which you can upload to any server and at runtime download that dex and load.

artyomd
  • 69
  • 3
  • 5