往期参考:
插件框架代码已经开源,欢迎使用并反馈。https://github.com/cmguo/android-plugins
插件入口类
实现插件入口类,该类实现通用插件接口,完成插件的启动,停止工作。插件类不提供具体功能,插件里面的其他类,提供具体功能。
public class Plugin extends PluginBase { @Override public int init(Context context) { // do something return 0; } } |
插件描述
插件描述包括:
- 基本信息:名字、作者、描述、图标
- 管理信息:模板(环境)、依赖
<?xml version="1.0" encoding="utf-8"?> <plugin xmlns:android="http://schemas.android.com/apk/res/android" android:name="@string/app_name" android:author="@string/author" android:thumbnail="@drawable/ic_launcher" android:description="@string/description" android:settingsActivity="com.xxx.yyy.SettingsActivity" templates="@array/plugin_template" depends="@array/plugin_depend" /> |
注册插件
在Manifest中注册插件信息,插件的包名就是APK的包名。插件支持的SDK Level 范围通过use-sdk定义。另外需要在Application的meta-data中注册插件描述xml资源。
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxx.yyy" android:versionCode="1" android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.base.plugin" android:resource="@xml/plugin"/> </application>
</manifest> |