Plugins architecture for an Android app?

Nicolas Raoul picture Nicolas Raoul · Apr 20, 2012 · Viewed 13.4k times · Source

THIS QUESTION HAS MOVED TO https://softwarerecs.stackexchange.com/questions/27841/plugins-architecture-for-an-android-app


I want to implement a plugin system for an Open Source app, because it has become really large, with many features that only a few users need. Releasing different apps is not a good solution, because userA wants feature7 and feature24 whilst userB wants feature39 and feature24.

Where can I find a good example of a plugin architecture?

Here is what I would like a plugin to be able to do:

For instance, one of the plugins must add a button on a particular screen, and clicking this button increments a value in the app's database. This is not doable with Content Providers and Intents, as far as I know.

I want to avoid making the core app's code complex with tons of hooks everywhere.

The form of the plugin could be a file on the SD card, an app, or anything else.

Answer

Cozytrony picture Cozytrony · Aug 12, 2012

I have done a framework that works like Robo-guice with some of its primary IoC functions. (Cut down on boilerplate codes that load views/service etc...)

But the core of which, I believe is the solution to your problem, is the ability to load separate APK "plugin" files, that includes "res" as well as <layouts>.xml files. The <layouts>.xml file can be independently inflated by the classes within that APK. That is, you can load a CustomView (that inflates its own <layout>.xml) into an originating/parent App. All this is done without the Parent App APK knowing how the UI was inflated in the plugin APK.

Example of what I mean: I have a Mapping App, the framework will dynamically scan installed APK that matches the "contract" for a "add-on function" plugin, and loads the UI specific to it onto the App's View as a floating panel.

I would say a plugin framework for Android is do-able, as Android has most if not all of the necessary built in APIs to accomplish this.

These are your friends in this area of plugin development for Android:

  1. PackageManager (Scan install packages, aka Plugins)
  2. DexClassLoader (ClassNotFoundException will be a pain if you don't use the correct ClassLoader btw)
  3. Java Reflection