uni-app Android原生插件使用自己的包名无法导入插件

uni-app Android原生插件使用自己的包名无法导入插件

开发环境 版本号 项目创建方式
Windows 10 3.2.16 HBuilderX

示例代码:

<template>  
    <view class="content">  
        <image class="logo" src="/static/logo.png" @click="onMuTest"></image>  
        <view class="text-area">  
            <text class="title">{{title}}</text>  
        </view>  
    </view>  
</template>  

<script>  
    let muTest;  
    export default {  
        data() {  
            return {  
                title: 'Hello'  
            }  
        },  
        onLoad() {  
            muTest = uni.requireNativePlugin('Mu-Test')  
            this.title = !muTest ? '插件导入失败' : '插件导入成功'  
        },  
        methods: {  
            onMuTest() {  
                uni.showToast({  
                    title: '点击了',  
                    icon: 'none'  
                });  

                if(muTest) {  
                    muTest.test({  
                        code: 1  
                    }, res => {  
                        this.title = JSON.stringify(res)  
                    })  
                }  
            }  
        }  
    }  
</script>  

<style>  
    .content {  
        display: flex;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
    }  

    .logo {  
        height: 200rpx;  
        width: 200rpx;  
        margin-top: 200rpx;  
        margin-left: auto;  
        margin-right: auto;  
        margin-bottom: 50rpx;  
    }  

    .text-area {  
        display: flex;  
        justify-content: center;  
    }  

    .title {  
        font-size: 36rpx;  
        color: #8f8f94;  
    }  
</style>

插件module代码

package mu.test;  

import com.alibaba.fastjson.JSONObject;  
import io.dcloud.feature.uniapp.annotation.UniJSMethod;  
import io.dcloud.feature.uniapp.bridge.UniJSCallback;  

/**  
 * @author LiYejun  
 * @date 2021/12/9 10:01  
 */  
public class TestModule {  

    @UniJSMethod()  
    public void test(JSONObject options, UniJSCallback callback) {  
        if(callback != null) {  
            JSONObject data = new JSONObject();  
            data.put("code", "success");  
            data.put("data", options);  
            callback.invoke(data);  
        }  
    }  
}

插件配置dcloud_uniplugins.json

{  
  "nativePlugins": [  
    {  
      "hooksClass": "",  
      "plugins": [  
        {  
          "type": "module",  
          "name": "Mu-Test",  
          "class": "mu.test.TestModule"  
        }  
      ]  
    }  
  ]  
}

更多关于uni-app Android原生插件使用自己的包名无法导入插件的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

跟包名没关系 只要你配置的class能找到相关的类 name与你requireNativePlugin填写的内容是一样的。那就不会有问题。自己检查下配置的class是否在apk中能找到或是被混淆了。

更多关于uni-app Android原生插件使用自己的包名无法导入插件的实战教程也可以访问 https://www.itying.com/category-93-b0.html


确实混淆问题

回到顶部