插件架构的Andr​​oid应用程序? [英] Plugins architecture for an Android app?

查看:143
本文介绍了插件架构的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个插件系统,一个开源应用,因为它已成为真正的大,有许多功能,只有少数用户需要。释放不同的应用程序并不是一个很好的解决方案,因为用户A希望feature7和feature24而用户B希望feature39和feature24。

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:

  • 重新定义一个特定的屏幕的布局(负载瘪XML ?)
  • 重新定义一个类的方法(<一个href="http://stackoverflow.com/questions/3022454/how-to-load-a-java-class-dynamically-on-android-dalvik">load DEX类?,<一个href="http://stackoverflow.com/questions/3759232/aspect-oriented-programming-in-android">AOP?)
  • Redefine the layout of a particular screen (load deflated XML?)
  • Redefine a method of a class (load dex class?, AOP?)

例如,插件必须增加一个特别的屏幕上的按钮,点击这个按钮递增应用程序的数据库中的值。这不是可行的与内容提供商和意图,因为据我所知。

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.

我想避免的核心应用程序的code复合物与吨挂钩随处可见。

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

插件的形式可以是SD卡,一个应用程序,或任何其他的文件。

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

推荐答案

我已经做了一个框架,就像机器人 - 吉斯它的一些主要的IoC功能。 (切下来的样板codeS的负载意见/服务等...)

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...)

但其中的核心,我认为这是解决问题的方法,是加载单独的APK插件文件的能力,包括资源以及&LT;布局&GT;的.xml 文件。该&LT;布局&GT;的.xml 文件可单独由APK中的类充气。也就是说,你可以加载一个CustomView(即膨胀自己的&LT;布局&GT;的.xml )到始发/父应用程序。所有这一切都是无父应用程序APK知道UI是如何膨胀的插件APK。

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.

我的意思例: 我有一个地图应用,该框架将动态扫描安装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.

我会说一个插件框架,Android是做,能,因为Android有大多数,如果不是所有必要的内置API来实现这一目标。

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.

这些都是你的朋友在这方面的插件开发的Andr​​oid版:

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

  1. 在PackageManager(扫描安装软件包,又名插件)
  2. DexClassLoader ClassNotFoundException的将是一个痛苦,如果你不使用正确的类加载器 BTW)
  3. Java反射
  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

这篇关于插件架构的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆