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!

##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


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

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

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

4. Code implementation

##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

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
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
The 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
- 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.

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

##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-

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-




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

##Uniapp Packaging
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)

HBuildX introduces the plug-in
Create nativeplugins in the project root directory-->plug-in name->android->plug-in aar file, synchronized storage under android
package.json (detailed introduction)
-
Tips: The plug-in id must be consistent with the name of the folder
Open manifest.json and configure the native plug-in
##Cloud packaging for plug-in function verification
IOS
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!