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:

包名要和申请的一样

都搞定了。运行:

相关推荐
小徐_23331 天前
uni-app vue3 也能使用 Echarts?Wot Starter 是这样做的!
前端·uni-app·echarts
iOS阿玮2 天前
永远不要站在用户的对立面,挑战大众的公知。
uni-app·app·apple
xw52 天前
uni-app中v-if使用”异常”
前端·uni-app
!win !2 天前
uni-app中v-if使用”异常”
前端·uni-app
2501_915918412 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张2 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview
00后程序员张2 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
海绵宝宝不喜欢侬2 天前
uniapp-微信小程序分享功能-onShareAppMessage
微信小程序·小程序·uni-app
2501_915106322 天前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
xkxnq2 天前
Uniapp崩溃监控体系构建:内存泄漏三维定位法(堆栈/资源/线程)
uni-app