uniapp calls the Android native plug-in Android native calls the third-party sdk (how to convert the aar developed by the third-party native to the aar that can be used by uni)

Recently, I was working on a project about uniapp and encountered a requirement. There is a native plug-in of aar developed natively, which is not in the plug-in market. The development shows that the natively developed plug-in cannot be directly provided to uniapp. It needs to be remade into an aar that can be used by uniapp according to the uniapp native plug-in development document. (Halfway to become a monk) It took two days of research to figure it out. Sort out the steps.
Here is how to change a third-party aar to be usable in uniapp, so you don't need to have a good Android background.

1. Need an Android studio version 4.1.1 I use
2. Download the official SDK (note that the version of hbuliderx must match the SDK version) the
official link
insert image description here
3. After the download is complete, unzip the folder and open Hello-AS with Android studio
insert image description here
insert image description here
insert image description here
4. Create a new Module (Android Library)
insert image description here
insert image description here
and configure the Module name, package name, Android SDK version, etc., as follows (note that the MiniMum SDK in the red box should not be greater than 19, otherwise errors may occur when uniapp is packaged):
insert image description here

5. Copy the files under the libs file in the app directory to the libs folder of the newly created module (humesdk-1.0.0) is the third-party aar 6.build.gradle file I need to use,
insert image description hereadd the following code
insert image description here
class is The path of the new module
insert image description here
insert image description here
7. Write your own plug-in (you must inherit UniModule, the method must add @UniJSMethod (uiThread = true) and the other is the method callback.invoke that I call the third-party plug-in, which is the callback function to js, ​​and the return value, See the official document for details)
insert image description here
8. Generate aar that can be used by uniapp (click gradle on the right side of the development tool after writing the native plug-in logic, find the corresponding Module, double-click as shown below to generate an aar package for use after running.) 9.
insert image description here
Find The generated aar (copy the aar file to your uniapp project)
**Bold style** insert image description here
10 (Import to the uniapp project, the red module name remains the same, the yellow part pays attention, if you reference the third-party sdk, you must also import it, otherwise the first step that may be executed The method of three modules does not take effect, calss is the path of the new module (class and the last UpdateModule is the business logic file).
insert image description here
11. Finally, select the local plug-in, and then customize the base cloud packaging and debugging
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/Jonn1124/article/details/127281234