z***@163.com
z***@163.com
  • 发布:2023-09-06 18:28
  • 更新:2023-09-06 18:28
  • 阅读:311

原生Component插件开发笔记

分类:插件市场

目前只做了Android,两天时间,坑很多,后面还要踩ios的坑。

说实话,这个社区已经无力吐槽了。

安卓部分

  1. 下载离线SDK,使用其中的UNIPLUGIN-HELLO-AS(文中使用HA代替)项目进行扩展

  2. 开发者中心创建了新的项目,配置证书相关内容

  3. 更新了整个HA项目中的appidkeystore等配置

  4. 离线打包成功运行

  5. 使用AndroidStudio,在HA项目中新建了一个gesture library,包名为com.morphling.gesture, 内部只有一个GestureComponent.java文件。因为没有第三方依赖,所以配置很简单。
    build.gradle 配置如下:

    apply plugin: 'com.android.library'  
    
    android {  
        compileSdkVersion 29  
    
        defaultConfig {  
            minSdkVersion 16  
            targetSdkVersion 28  
            versionCode 1  
            versionName "1.0"  
    
            testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'  
    
        }  
    
        buildTypes {  
            release {  
                minifyEnabled false  
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'  
            }  
        }  
    
    }  
    
    repositories {  
        flatDir {  
            dirs 'libs'  
        }  
    }  
    
    dependencies {  
        compileOnly fileTree(dir: 'libs', include: ['*.jar'])  
        compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar'])  
    
        compileOnly 'androidx.recyclerview:recyclerview:1.0.0'  
        compileOnly 'androidx.legacy:legacy-support-v4:1.0.0'  
        compileOnly 'androidx.appcompat:appcompat:1.0.0'  
        compileOnly 'com.alibaba:fastjson:1.2.83'  
    }  
  6. 更新了dcloud_uniplugins.json,添加如下配置:

    {  
      "plugins": [  
        {  
          "type": "component",  
          "name": "MGesture",  
          "class": "com.morphling.gesture.GestureComponent"  
        }  
      ]  
    }  
  7. 新增测试ext-gesture.nvue文件,并配置好pages.json,并生成本地打包APP资源,然后替换HA项目对应的www文件目录

  8. AndroidStudiorun真机调试,新增的插件可以正常运行

  9. 按照官网说明,使用gradle编译插件的.aar文件,并在已有项目中添加nativeplugins文件夹,以及相关内容其结构为:

    nativeplugins  
    └── MGesture  
        ├── android  
        │   ├── gesture-release.aar  
        │   └── libs  
        └── package.json  

    其中的package.json文件内容如下

    {  
        "name": "MGesture",  
        "id": "MGesture",  
        "version": "1.0.0",  
        "description": "Gesture Detector Component",  
        "_dp_type":"nativeplugin",  
        "_dp_nativeplugin":{  
            "android": {  
                "plugins": [  
            {  
              "type": "component",  
              "name": "MGesture",  
              "class": "com.morphling.gesture.GestureComponent"  
            }  
                ],  
                "integrateType": "aar"  
            }  
    
        }  
    }  
    
  10. 提交云打包调试基座,中途没有遇到异常,顺利生成android_debug.apk

  11. 使用自定义基座运行模式生成的apk文件,我自己新建的插件不起作用,通过weex查看渲染结果,自定义组件只有一个div,没有生成对应的GestureComponent

  12. 请在真机卸载app后重新生成,具体原因我没有分析,但是我终于搞定了。o(╯□╰)o

0 关注 分享

要回复文章请先登录注册