Currently, Lynx is not suitable for building a new application from scratch. You need to integrate Lynx (engine) with your native mobile app or web app, and load Lynx apps through Lynx views. With a few steps, you can start developing with Lynx in your application.
Choose your target platform to view the specific integration steps:
The core capabilities of Lynx Engine include basic capabilities such as parsing Bundle, style parsing, layout, and rendering views
Get the latest version of Lynx from Cocoapods. Then add Lynx to your Podfile:
Podfile
source 'https://cdn.cocoapods.org/'platform :ios, '10.0'target 'YourTarget' do pod 'Lynx', '3.2.0', :subspecs => [ 'Framework', ] pod 'PrimJS', '2.12.0', :subspecs => ['quickjs', 'napi']end
Lynx Service
Lynx Service includes LynxImageService, LynxLogService, etc. It aims to provide the ability to strongly correlate some host App features, allowing the App to inject custom Services at runtime, or use the default implementation provided by the official. For example, LynxImageService is implemented using the SDWebImage image library by default. Apps that do not integrate SDWebImage components can rely on other image libraries to implement Image Service.
Lynx provides standard native Image, Log, and Http service capabilities, which can be quickly accessed and used by the access party;
Get the latest version of Lynx Service from Cocoapods. Then add Lynx Service to your Podfile:
Podfile
source 'https://cdn.cocoapods.org/'platform :ios, '10.0'target 'YourTarget' do pod 'Lynx', '3.2.0', :subspecs => [ 'Framework', ] pod 'PrimJS', '2.12.0', :subspecs => ['quickjs', 'napi'] # integrate image-service, log-service, and http-service pod 'LynxService', '3.2.0', :subspecs => [ 'Image', 'Log', 'Http', ] # ImageService dependencies: pod 'SDWebImage','5.15.5' pod 'SDWebImageWebPCoder', '0.11.0'end
Run pod install to install dependencies, then open your Xcode project. Additionally, make sure to disable the Sandbox Scripting capability.
NOTE
In order to disable the Sandbox scripting, in Xcode click on your app, then on build settings. Filter for script and set the User Script Sandboxing to NO.
LynxEnv provides a global initialization interface for the Lynx Engine. Please ensure that the initialization of LynxEnv occurs before any interface call of the Lynx Engine.
For example, it can be initialized in AppDelegate
LynxView is the basic rendering unit provided by Lynx Engine. LynxView is an implementation inherited from iOS native UIView. You can quickly construct a LynxView and add it to the ViewController.
Lynx Engine itself does not have the ability to load resources, so it is necessary to initialize LynxEnv, or when constructing LynxView to pass in the specific implementation of the LynxTemplateProvider protocol. Lynx will use the injected resource loader to obtain the Bundle content
You can use various methods to obtain the contents of the Bundle. Here, we choose to embed the contents of the Bundle within the application.
First, please either generate the Bundle file from the Quick Start phase or download the file below to your local machine, and then follow these steps to embed the file:
After completing the above steps, all the work of initializing LynxView have been completed. Call the lynxView.loadTemplateFromURL method to render the corresponding Bundle onto the LynxView.
At this stage, you have successfully integrated Lynx into your App. Refer to our developing and debugging docs for in-depth insights on working with Lynx.
The core capabilities of Lynx Engine include basic capabilities such as parsing Bundle, style parsing, layout, rendering views and the basic code of the javascript runtime that Lynx pages rely on
Lynx Service includes LynxImageService, LynxLogService, etc. It aims to provide the ability to strongly correlate some host App features, allowing the App to inject custom Services at runtime, or use the default implementation provided by the official.For example, LynxImageService is implemented using the Fresco image library by default. Apps that do not integrate Fresco components can rely on other image libraries, such as Glide to implement Image Service.
Lynx provides standard native Image, Log, and Http service capabilities, which can be quickly accessed and used by the access party;
NOTE
Since Fresco depends on AndroidX, you also need to configure the following in gradle.properties:
android.useAndroidX=true
build.gradle
build.gradle.kts
build.gradle
dependencies { // lynx dependencies implementation "org.lynxsdk.lynx:lynx:3.2.0" implementation "org.lynxsdk.lynx:lynx-jssdk:3.2.0" implementation "org.lynxsdk.lynx:lynx-trace:3.2.0" implementation "org.lynxsdk.lynx:primjs:2.12.0" // integrating image-service implementation "org.lynxsdk.lynx:lynx-service-image:3.2.0" // image-service dependencies, if not added, images cannot be loaded; if the host APP needs to use other image libraries, you can customize the image-service and remove this dependency implementation "com.facebook.fresco:fresco:2.3.0" implementation "com.facebook.fresco:animated-gif:2.3.0" implementation "com.facebook.fresco:animated-webp:2.3.0" implementation "com.facebook.fresco:webpsupport:2.3.0" implementation "com.facebook.fresco:animated-base:2.3.0" implementation "com.squareup.okhttp3:okhttp:4.9.0" // integrating log-service implementation "org.lynxsdk.lynx:lynx-service-log:3.2.0" // integrating http-service implementation "org.lynxsdk.lynx:lynx-service-http:3.2.0"}
The obfuscation rules for Lynx Engine are as follows. It is recommended to refer to the latest source code configuration.
proguard-rules.pro
# LYNX START# use @Keep to annotate retained classes.-dontwarn android.support.annotation.Keep-keep @android.support.annotation.Keep class **-keep @android.support.annotation.Keep class ** { @android.support.annotation.Keep <fields>; @android.support.annotation.Keep <methods>;}-dontwarn androidx.annotation.Keep-keep @androidx.annotation.Keep class **-keep @androidx.annotation.Keep class ** { @androidx.annotation.Keep <fields>; @androidx.annotation.Keep <methods>;}# native method call-keepclasseswithmembers,includedescriptorclasses class * { native <methods>;}-keepclasseswithmembers class * { @com.lynx.tasm.base.CalledByNative <methods>;}# to customize a module, you need to keep the class name and the method annotated as LynxMethod.-keepclasseswithmembers class * { @com.lynx.jsbridge.LynxMethod <methods>;}-keepclassmembers class * { @com.lynx.tasm.behavior.LynxProp <methods>; @com.lynx.tasm.behavior.LynxPropGroup <methods>; @com.lynx.tasm.behavior.LynxUIMethod <methods>;}-keepclassmembers class com.lynx.tasm.behavior.ui.UIGroup { public boolean needCustomLayout();}# in case R8 compiler may remove mLoader in bytecode.# as mLoader is not used in java and passed as a WeakRef in JNI.-keepclassmembers class com.lynx.tasm.LynxTemplateRender { private com.lynx.tasm.core.LynxResourceLoader mLoader;}# the automatically generated setter classes use the class names of LynxBaseUI and ShadowNode and their subclasses.-keep class com.lynx.tasm.behavior.ui.LynxBaseUI-keep class com.lynx.tasm.behavior.shadow.ShadowNode-keep class com.lynx.jsbridge.LynxModule { *; }-keep class * extends com.lynx.tasm.behavior.ui.LynxBaseUI-keep class * extends com.lynx.tasm.behavior.shadow.ShadowNode-keep class * extends com.lynx.jsbridge.LynxModule { *; }-keep class * extends com.lynx.jsbridge.LynxContextModule-keep class * implements com.lynx.tasm.behavior.utils.Settable-keep class * implements com.lynx.tasm.behavior.utils.LynxUISetter-keep class * implements com.lynx.tasm.behavior.utils.LynxUIMethodInvoker-keep class com.lynx.tasm.rendernode.compat.**{ *;}-keep class com.lynx.tasm.rendernode.compat.RenderNodeFactory{ *;}# LYNX END
Lynx Service provides host feature-related capabilities and it is recommended to complete the initialization of Lynx Service during the Application#onCreate lifecycle of the application.
Lynx Service needs to be actively injected
TIP
Please specify your custom Application class in the AndroidManifest.xml file, since Lynx needs to perform some global initialization operations when the application starts.
LynxEnv provides the global initialization interface for the Lynx Engine. Please ensure that the initialization of LynxEnv occurs before any interface calls to the Lynx Engine. It is recommended to complete the initialization of LynxEnv during the Application#onCreate lifecycle of the application.
The parameters for the LynxEnv initialization method are described as follows:
appContext: The context object for the application lifecycle, i.e., ApplicationContext.
libraryLoader: The loader for native so files, the default value can be null, which will use the system default loader.
templateProvider: The global AppBundle loader, the default value can be null;
behaviorBundle: The list of custom components, the default value can be null. If there are customization requirements, please refer to custom-native-component
Lynx Engine itself does not have the ability to integrate downloading resources, so the existing app needs to provide the specific implementation of AbsTemplateProvider, and inject it when initializing LynxEnv or constructing LynxView. Lynx will use the injected resource loader to obtain the Bundle content
You can use various methods to obtain the contents of the Bundle. Here, we choose to embed the contents of the Bundle within the application.
First, please place the Bundle file generated in the Quick Start stage in the src/main/assets directory, or you can download the file below to your local machine and place it in the same directory:
LynxView is the basic rendering view provided by Lynx Engine. LynxView inherits from the native Android View. You can quickly construct a LynxView and add it arbitrarily to the native Android view tree.
After completing the above steps, all the work of initializing LynxView have been completed. Call the lynxView.renderTemplateUrl method to render the corresponding Bundle onto the LynxView view.
At this stage, you have successfully integrated Lynx into your App. Refer to our developing and debugging docs for in-depth insights on working with Lynx.
Lynx for Web implements the Lynx engine in web browsers. With Lynx for Web,
you can easily integrate Lynx apps into any existing web project, regardless
of whether the project uses React, Vue, Svelte, or plain HTML.
Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.