uniapp android 原生插件封装--入门篇

本文将介绍uniapp 插件封装官方例子的搭建,运行。和注意事项,避坑

1、文档地址:简介 | uni小程序SDK

开发者须知 | uni小程序SDK

Android平台第三方插件开发指导 - DCloud问答 这个介绍插件与原生的架构

2、下载官方示例:百度网盘 请输入提取码 : jrrb

3、下载最新的 android sdk .2023-3-1

编译项目:

这个版本默认的SDK是17,官方的例子是旧项目。会提示sdkb版本太高,需要如下设置:把sdk改为你本机的1.8

3、代码需要添加gradle 配置:uniplugin_richalert ->build.gradle

复制代码
dependencies {
    implementation 'androidx.test.ext:junit:1.1.5'
    compileOnly fileTree(dir: 'libs', include: ['*.jar'])

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'

    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'



    testImplementation 'junit:junit:4.12'

    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'

    compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar'])

    compileOnly 'com.alibaba:fastjson:1.1.46.android'
}
复制代码
uni.dcloud.io.uniplugin_richalert.ExampleInstrumentedTest.java 这个代码修改:
复制代码
package uni.dcloud.io.uniplugin_richalert;

import android.content.Context;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertEquals;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {

        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        assertEquals("uni.dcloud.io.uniplugin_richalert.test", appContext.getPackageName());
    }
}

到这步,编译可以通过了。

运行插件

接下来,如何运行插件,并进行测试:

1、在hbuilderx 导入项目:

2、申请appId

3、发行--》原生app本地打包--》生成本地资源

4、把打包的文件拷贝到 安卓开发的app/assets/apps/{appid}下。

5、配置这

6、需要配appKey 不然运行会提示没有配,这步需要导dcloud官网

手册:申请 | uni小程序SDK

申请过程需要 sha1 sha256 可以从目录下的这个文件提取:test.jks

javascript 复制代码
keytool -list -v -keystore test.jks

7、在android开发工具里配置 appkey:

包名要和申请的一样

都搞定了。运行:

相关推荐
2501_9159184114 小时前
uni-app 项目 iOS 上架踩坑经验总结 从证书到审核的避坑指南
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者814 小时前
iOS 上架 uni-app 流程全解析,从打包到发布的完整实践
android·ios·小程序·https·uni-app·iphone·webview
软工的小白1 天前
uniapp开发前端静态视频界面+如何将本地视频转换成网络地址
uni-app·音视频
2501_916008891 天前
iOS 抓包工具有哪些?全面盘点主流工具与功能对比分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 天前
iOS混淆工具实战 视频流媒体类 App 的版权与播放安全保护
android·ios·小程序·https·uni-app·iphone·webview
NewChapter °1 天前
如何通过 Gitee API 上传文件到指定仓库
前端·vue.js·gitee·uni-app
SY_FC1 天前
uniapp阿里云验证码使用
阿里云·uni-app·notepad++
—Qeyser1 天前
好看的背景颜色 uniapp+小程序
小程序·uni-app·uniapp·微信小游戏
2501_916008891 天前
uni-app iOS 日志与崩溃分析全流程 多工具协作的实战指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 天前
iOS混淆工具实战 在线教育直播类 App 的课程与互动安全防护
android·安全·ios·小程序·uni-app·iphone·webview