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_915106328 小时前
CDN 可以实现 HTTPS 吗?实战要点、部署模式与真机验证流程
网络协议·http·ios·小程序·https·uni-app·iphone
LoveEate1 天前
uniapp 运行/发版微信小程序
微信小程序·小程序·uni-app
fakaifa2 天前
【高级版】沃德政务招商系统源码+uniapp小程序
小程序·uni-app·源码下载·沃德政务招商系统·招商系统源码
weixin_446938872 天前
uniapp vue-i18n如何使用
前端·vue.js·uni-app
有来技术2 天前
UniApp 自定义导航栏适配指南:微信小程序胶囊遮挡、H5 与 App 全端通用方案
微信小程序·uni-app
卷Java2 天前
违规通知功能修改说明
java·数据库·微信小程序·uni-app
卷Java3 天前
用户权限控制功能实现说明
java·服务器·开发语言·数据库·servlet·微信小程序·uni-app
王佳斌3 天前
sass变量默认
uni-app
二饭3 天前
uniapp与webview通信
uni-app
2501_915909063 天前
iOS 抓包工具有哪些?实战对比、场景分工与开发者排查流程
android·开发语言·ios·小程序·uni-app·php·iphone