Home  >  Article  >  Web Front-end  >  Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

青灯夜游
青灯夜游forward
2022-03-17 11:41:165440browse

How is the uniAPP native plug-in packaged on iOS? The following article will talk to you about the uniAPP native plug-in packaging process on iOS. I hope it will be helpful to you!

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

The beginning of nonsense: uniAPP is packaged using cloud compilation, that is to say, app NextiOS The native part of the code needs to be submitted to the background of uni for compilation. It can be understood that there is a Xcode running environment on the uni server. Of course, the cloud should be completed using the Xcode command. When HBuilderX performs cloud compilation, all local native libraries will be compressed and packaged to the cloud. Finally, the compiled ipa Download the package locally so it can be installed.

1. Static library settings

You can simply familiarize yourself with the project structure based on the Demo downloaded from the uni official website.

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

1. HBuilder-uniPlugin main project

It can actually be roughly understood as the cloud compilation time All compilation environments of Xcode, why do you say that? You can take a look at all the dependencies of this project.

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

The number of purely local dependencies is as many as 120, because uni considers the cost of cloud compilation. If all Libraries are uploaded by developers, so the compilation resources will be heavily occupied, so the remote third-party library reserve method is adopted, which can also be learned from the uni background.

The version description of the third-party library that iOS depends on

https://nativesupport.dcloud.net.cn/AppDocs/usemodule/iOSModuleConfig/dependentLibrary

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

Therefore, when developing uni native plug-ins, you can first refer to whether there is a supported third party on the remote end to avoid compilation symbol conflicts caused by repeated imports. .

Example: For example, the plug-in requires the IJKMediaFramework library of site B (about 160M, which is really large). Then, first check whether the cloud compilation has this library,

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

It is found that it already exists. Then, at this time, there is no need to submit the local IJKMediaFramework library. You only need to submit the manifest.json of HBuilderX Just check VideoPlayer under configuration.

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

In this way, the configuration of manifest.json of HBuilderX will tell the cloud compiler to add IJKMediaFramework Come to the project.

2. DCTestUniPlugin static library project

When making a static library, you need to set up support for the static library architecture.

Set under Build Setting -> Architectures

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

## and pay attention to when compiling, Select

Any iOS Device

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

What should I do if the static library requires a third-party library?

During development, you will definitely encounter situations that require third-party library support, such as:

AFNetWorking, here first check uni Far Whether the client supports it and it is found that the corresponding static library has not been improved, then it needs to be uploaded locally.

Because the self-made static library will eventually be loaded into the environment of

APP, so the strategy for self-made static libraries to rely on third parties is to add the third-party library .a file Add it to the HBuilder-uniPlugin main project, because the self-made static library needs to import the header file, then add it to Heard Search Paths under the DCTestUniPlugin static library project. Introduction of header files.

HBuilder-uniPlugin Main project

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

##DCTestUniPlugin

Static library projectHeard Search Paths

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

2. Configure iOS native plug-inpackage.json

All functions have been developed, the next step islocal plug-in package Configuration

For specific packaging steps, please refer to the link above. The final file directory structure is as follows:

Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing)

1, WSLUniPlugin is the overall file, which can contain android and ios (it is marked ios instead of iOS on the official website)

2. The ios file contains all required third-party libraries and self-made static libraries.

3 and package.json are related configurations. The internal information of package.json will tell the remote compilation which libraries to load and the folder locations of the libraries. Of course It also includes some configurations, such as which dynamic libraries need to be signed (although you can make your own dynamic libraries, they need to be signed).

3. package.json directory

{
    "name": "WSLUniPlugin",//插件名称
    "id": "WSLUniPlugin",//插件ID
    "version": "1.0",
    "description": "功能描述",//功能描述这里进行功能描述,添加后会在HBuilder下展示
    "_dp_type":"nativeplugin",//原生组件类型
    "_dp_nativeplugin":{
        "ios": {
            "plugins": [
                {
                    "type": "component",//插件类型,是功能组件(module)还是视图组件(component)
                    "name": "wsl-component",//在nvue文件内的标签tag
                    "class": "WSLComponent" //iOS 原生对象class,继承自 DCUniComponent
                },
            ],
            "integrateType": "framework",//自制库类型
            "hooksClass": "",这里声明 app 生命周期勾子对象,它会同时响应appDelegate 事件
            "frameworks": [
				"libAFNetworking.a",//uni远端非储备库,需要标注声明
				"Masonry.framework",//Masonry 为uni远端储备库,ios 文件夹里不需要再添加,否则编译出现符号重复错误
            ],
            "embedFrameworks": [
                "IDLFaceSDK.framework",//动态库
            ],
            "capabilities": {
                "entitlements": {
                },
                "plists": {
                }
            },
            "plists": {
            },
            "assets": [
                 "WSLUniPlugin.xcassets"//图片资源文件,这里填写的是与 ios 文件夹的相对路径,因为 WSLUniPlugin.xcassets 就在 ios 文件里,所以直接写。
            ],
            "privacies": [
            ],
            "embedSwift": false,
            "deploymentTarget": "8.0",//支持iOS版本
            "validArchitectures": [
                 "arm64"//架构
            ],
            "parameters": {
            },
            "resources": [
                "WSLUniPlugin.bundle",//这里是一些资源文件,比如 bundle,这里填写的是与 ios 文件夹的相对路径,因为 WSLUniPlugin.bundle 就在 ios 文件里,所以直接写。
            ]
        }
    }
}

The above is the basic configuration settings. Because the number of uni cloud compilations per day is limited (about 10 times), and the package size must be less than 40M, the excess number is 2 yuan per time, and the excess volume is 10 yuan per 100M. Is there a little pitfall? In this way, the cost of daily trial and error is extremely high, so I will record it here.

Recommended: "uniapp tutorial"

The above is the detailed content of Let’s talk about how the uniAPP native plug-in on iOS is packaged? (Packaging process sharing). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete