开发步骤
-
导入
UniPlugin-Hello-AS
示例项目 -
gradle中添加插件模块
-
app/src/main/assets/dcloud_uniplugins.json
添加插件配置:{ "nativePlugins": [ { "plugins": [ { "type": "module", "name": "zker-sip", "class": "cn.zker.uniplugin.sip.SipPlugin" }, { "type": "component", "name": "zker-input", "class": "cn.zker.uniplugin.component.ZkerInput" } ] } ] }
-
插件开发
class TestPlugin : UniModule { @UniJSMethod fun add(json: JSONObject, callback: UniJSCallback){ // 处理逻辑 callback.invoke(JSONObject(){}) } }
-
组件开发
public class ZkerInput extends UniComponent<EditText> { public ZkerInput(UniSDKInstance uniSDKInstance, AbsVContainer absVContainer, int i, AbsComponentData absComponentData) { super(uniSDKInstance, absVContainer, i, absComponentData); } @Override protected EditText initComponentHostView(@NonNull Context context) { return new EditText(context); } @UniJSMethod @UniComponentProp(name = "text") public void setText(String text) { getHostView().setText(text); } }
-
打包
-
编译文件:gradle => task => other => assembleRelease
-
创建插件目录:
- [plugin-name] - package.json - android - [plugin-name].aar - ios
-
添加package.json
{ "name": "插件中文名称", "id": "plugin-name", "version": "1.0.0", "description": "", "_dp_type": "nativeplugin", "_dp_nativeplugin": { "android": { "integrateType": "aar", "plugins": [ { "type": "module", "name": "zker-sip", "class": "cn.zker.uniplugin.sip.SipPlugin" }, { "type": "component", "name": "zker-input", "class": "cn.zker.uniplugin.component.ZkerInput" } ] } } }
-
参考资料
- uni-app原生插件集成指南
- uniapp 原生插件开发-android
- Android平台第三方插件开发指导
- Android Studio Gradle列表任务不见了?2步搞定
- “同步资源失败,未得到同步资源的授权,请停止运行后重新运行,并注意手机上的授权提示”的解决方法