uniapp native Android development plug-in (module), and local debugging in the android environment (1)
1. Prospect
Continuing from the previous article , since uniapp only has a limited number of packaging times per day, each plug-in debugging is packaged into a base, which is not convenient, so another method is adopted: local debugging in the native environment of android
2. Preparation
- Offline AppKey
- uniapp generates resource bundles locally
- Android native environment (the project that has been imported in the previous article)
3. Offline APPKey
- Go to the uniapp developer center , then find your own application, click to find the information of each platform
- There are two cases of offline packaging Key: one is not created, and the other is already created
(1) For those that have not been created, click the Modify button to enter the interface shown in the figure below
Certificate: A certificate is required when packaging and publishing. Regarding how to generate ( certificate ), follow the instructions in the tutorial.
After filling in the information SHA1, MD5, and SHA256 information in the above figure. Click Submit. Go back to the list page. Click the View button again
- After the creation is complete
, click the View button
to copy the offline APP Key.
4. uniapp locally generates resource packs
First delete the local plug-in
and then directly write the code of the plug-in
. Introduce the plug-in to the page and describe the function
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<button @click="test">测试</button>
</view>
</view>
</template>
<script setup lang="ts">
const test= ()=>{
// 引入自定义插件
const testModule = uni.requireNativePlugin('sunmi-scan')
// 使用module的add方法
testModule.add({
a:1,b:3
},e=>{
uni.showToast({
title:JSON.stringify(e),
icon:'none'
})
})
}
</script>
Finally, generate a local resource package: Publish – Native APP – Local Packaging – Generate Local APP Resources
Finally, go to the resource package directory and copy all the folders named after the entire AppId
5. Android native environment
-
Go back to our android project (the previous article has been imported), put the folder copied in the above picture into app --src–assets–apps
-
Modify the appid in dcloud_control.xml and enable debug mode
-
Move the certificate to the app folder
-
Configure certificate information
signingConfigs {
config {
keyAlias '别名'
keyPassword '密码'
storeFile file('sinexcel.keystore')
storePassword '密码'
v1SigningEnabled true
v2SigningEnabled true
}
}
- Modify the dcloud_uniplugins.json file, add a custom plugin name, which will be called in uniapp, and add the corresponding class path, which is copied in the previously created business code class
{
"plugins": [
{
"type": "module",
"name": "",
"class": ""
}
]
}
- Configure the corresponding appkey (the initial offline packaging key is needed here)
<meta-data
android:name="dcloud_appkey"
android:value="你的离线打包key" />
- Modify the applicationId of the app-build.gradle file and change it to the package name of the uniapp project
Startup project
You're done! Ladies and gentlemen, please give me a thumbs up! !