[RFC] Automatic Integration Solution for Lynx Native Extensions #2653
Replies: 1 comment
-
|
Got a simple prototype for kotlin/ java native module with gradle autolinking I have a custom cli called tiger-module Record_2025-10-23-10-39-25.mp4 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
This RFC mainly discusses the introduction of the Autolink mechanism for Lynx. By packaging native code into an npm package according to specific specifications for distribution and leveraging the capabilities provided by the compilation framework plugin, it enables the rapid integration of Lynx components containing native code without modifying the compilation configuration on the native side of the application. This reduces the development and usage costs of Lynx native extension capabilities.
Glossary
Motivation
Lynx provides multiple mechanisms for calling Native-side capabilities through frontend code. However, when integrating these codes, it is necessary to modify the compilation configurations (such as build.gradle.kts, Podfile) and Native code of each platform separately.
To simplify the above process as much as possible, we plan to introduce the Autolink mechanism to Lynx.
Prior Arts
User Guide
Integrate an Extension
For applications that have already integrated the Autolink framework, it is expected that the integration of native extensions can be quickly achieved in the following ways:
# Suppose there is a button element implemented in native code. npm install @lynxjs/buttonDevelop Workflow
The following is the basic process of developing and using extensions after having the Autolink framework.

Extension Package
Project Layout
Here's the layout of a common extension project which contains the source code of both Lynx and native platforms:
Configuration File
The extension package needs to add a "platforms" field to the specified configuration file (lynx.ext.json) to declare which platforms the current package supports and provide information for the packaging tool and compilation framework plugins. The basic format of the configuration file is as follows
{ "platforms": { "android": { "packageName": "com.lynx.example" }, "ios": {}, "web": {} } }Extension Development
Define the APIs on the JS side
Native Module
Add type and interface definitions to a
.d.tsfileElement
There is no need to generate interface code for the element, so there is no need to define interfaces on the JS side. However, developers can still encapsulate components themselves if necessary
Code Generation
Developers can use the command-line tool to generate the following code in the project
Export JS Interface
To avoid exposing the generated path to extension users, the Native module needs to export the generated module
Implement Native Code
Android
Add the following annotations to the defined Native Module class in the source code for Android platform
iOS
Use a macro to annotate the native module
web
For web, we use a JS doc style comment to mark a native module
Element
Android
The components defined in Android source code need to add the following annotation. When other projects use the components, relevant code will be generated from annotations, and the components will be automatically registered in the application
iOS
web
Service
Android
iOS
web
Command Line
Project Creation
If developers want to create a lynx extension project, they need to use the
create-lynx-extensioncommand.The extension package created by the CLI consists of multiple template projects, including:
create-lynx-extensionwill first prompt the user to select the type of extension to support, and then complete the project generation according user's input:Code Generation
In addition to generating projects, a command-line tool will also be provided for code generation.
Here's the usage of the tool:
Integrate the Autolink Framework to Existing Application
To integrate the extension into your project, you just need to install it like any other npm package (npm install xxx). However, before you do this, make sure your application has already integrated the AutoLink framework. The integration steps are as follows:
Android
iOS
Install using the gem command.
or add it to the Gemfile (only when running pod install with Bundler)
LynxViewBuilderusingExtensionRegistryweb
Beta Was this translation helpful? Give feedback.
All reactions