Home > Web Front-end > uni-app > A brief discussion on how to develop Android native plug-ins in Uniapp

A brief discussion on how to develop Android native plug-ins in Uniapp

青灯夜游
Release: 2021-09-10 20:06:29
forward
5614 people have browsed it

How to develop Android native plug-ins in Uniapp? The following uniapp tutorial column will introduce you to the Uniapp Android native plug-in development method. I hope it will be helpful to everyone!

A brief discussion on how to develop Android native plug-ins in Uniapp

##Android

Environment preparation

l JAVA environment jdk1.8

l Android Studio download address:

Android Studio official website OR Android Studio Chinese community

l App offline SDK download : Please download the 2.9.8 version of

android platform SDK

Import the uni plug-in native project

l UniPlugin-Hello -AS project please search

l in App Offline SDK

and click Android Studio menu option File--->New--->Import ProjectApp Offline SDK

A brief discussion on how to develop Android native plug-ins in Uniapp

A brief discussion on how to develop Android native plug-ins in Uniapp

Plug-in development

uni-app plug-in currently only supports Module extension and Component Extension, Adapter extension is not supported for the time being. The following is the Module extension (non-UI function extension)

1. Create a new Module, File->New->New Module, select Android Library, fill in the information, Click Finish

A brief discussion on how to develop Android native plug-ins in Uniapp

2. Edit the build.gradle file of the new Module and add dependencies so that the Module has the ability to develop uniapp plug-ins

    移除默认依赖,修改为

    compileOnly fileTree(dir: 'libs', include: ['*.jar'])\
    compileOnly fileTree(dir: '../app/libs', include: ['uniapp-v8-release.aar'])\
    compileOnly "com.android.support:recyclerview-v7:28.0.0"\
    compileOnly "com.android.support:support-v4:28.0.0"\
    compileOnly "com.android.support:appcompat-v7:28.0.0"\
    compileOnly 'com.alibaba:fastjson:1.1.46.android'\
    implementation 'com.facebook.fresco:fresco:1.13.0'
Copy after login

A brief discussion on how to develop Android native plug-ins in Uniapp

3. Write logic and create a new java class in your own module for writing your own code logic

A brief discussion on how to develop Android native plug-ins in Uniapp

4. Code implementation

A brief discussion on how to develop Android native plug-ins in Uniapp

    • ##The first parameter is the incoming parameter, the structure is json, the required parameters are obtained through key, the second is the callback function, used to return Give the results required by the front page
    • If you need to use other permissions, you need to apply in the AndroidManifest.xml file, such as calendar reading and writing

A brief discussion on how to develop Android native plug-ins in Uniapp

    Edit the "app" Module root directory assets/dcloud_uniplugins.json file under the UniPlugin-Hello-AS project, in the nativePlugins node Register below, type: module, name fill in the name of the component you need to expose, class fill in the specific path of the method, package name + class name

A brief discussion on how to develop Android native plug-ins in Uniapp dcloud_uniplugins.json description:

nativePlugins: 插件根节点,可存放多个插件
hooksClass: 生命周期代理(实现AppHookProxy接口类)格式(完整包名加类名)
type : module 或 component类型
name : 注册名称
class : module 或 component 实体类完整名称
Copy after login

Register your own component in the app's build.gradle. The name is the name of the new module. When registering, you can use it in android studio

A brief discussion on how to develop Android native plug-ins in UniappThe code development is over now. The next step is to use android studio to verify the offline package. Portal

nativesupport.dcloud.net.cn/AppDocs/ use...

Packaging verification

Hbuildx creates a new project and calls the plug-in through uni.requireNativePlugin

  1. The current uniapp related packaging information needs to be prepared. I won’t go into details here. AppKey, APPID and Android package name all need to be configured accordingly in android studio, as well as Android certificate aliases and secret keys, etc.

1A brief discussion on how to develop Android native plug-ins in Uniapp

  1. Click Release->Local Packaging->Generate locally packaged App resources

1A brief discussion on how to develop Android native plug-ins in Uniapp

    ##Copy and paste the generated file into UniPlugin-Hello-AS\app\src\main\assets\apps, and modify the appid of the dcloud_control.xml file

1A brief discussion on how to develop Android native plug-ins in Uniapp

    Android packaging parameter configuration, package name, certificate alias, etc. (Figure 1), the certificate file needs to be placed under the app (Figure 2) AndroidManifest.xml configures the package name and AppKey, which is the second step above AppKey

1A brief discussion on how to develop Android native plug-ins in Uniapp

1A brief discussion on how to develop Android native plug-ins in Uniapp

1A brief discussion on how to develop Android native plug-ins in Uniapp

1A brief discussion on how to develop Android native plug-ins in Uniapp

# Connect the phone, turn on USB debugging, click Run

1A brief discussion on how to develop Android native plug-ins in Uniapp

##Uniapp Packaging1A brief discussion on how to develop Android native plug-ins in Uniapp

Plug-in Generation

Compile and generate the aar file of the module: Select Gradle--->plug-in module--->Tasks--->other--->assembleRelease (run the aar file that generates the module)

A brief discussion on how to develop Android native plug-ins in Uniapp

HBuildX introduces the plug-in2A brief discussion on how to develop Android native plug-ins in Uniapp

Create nativeplugins in the project root directory-->plug-in name->android->plug-in aar file, synchronized storage under android

package.json (detailed introduction)
  1. Tips: The plug-in id must be consistent with the name of the folder

2A brief discussion on how to develop Android native plug-ins in UniappOpen manifest.json and configure the native plug-in

##Cloud packaging for plug-in function verification2A brief discussion on how to develop Android native plug-ins in Uniapp

IOS2A brief discussion on how to develop Android native plug-ins in Uniapp

The first step is to buy a Mac

More For more programming-related knowledge, please visit: Introduction to Programming! !

The above is the detailed content of A brief discussion on how to develop Android native plug-ins in Uniapp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template