Integrating Lynx DevTool

When encountering issues during Lynx page development, you can use DevTool for debugging. However, you need to follow these steps to integrate DevTool first.

INFO

It is recommended to integrate DevTool in non-production environments to keep your production builds lightweight. All code examples in this documentation can be found in the integrating-lynx-demo-projects.

Adding Dependencies

You need to add two components: LynxDevTool and the Devtool subcomponent of LynxService.

Podfile
# Ensure Lynx DevTool version matches the Lynx version when integrating
target 'YourTarget' do
  pod 'LynxService', '3.4.1', :subspecs => [
      'Devtool',
  ]
  pod 'LynxDevtool', '3.4.1'
end

Enabling DevTool

DevTool provides several debugging switches. Here are three important switches:

  • Lynx Debug is the switch that controls all DevTool debugging.
  • Lynx DevTool controls main debugging features: element inspection and JavaScript debugging.
  • Lynx LogBox manages the LogBox.
These three switches are disabled by default, you need to enable them.
  • Lynx DevTool and Lynx LogBox switches can only take effect after Lynx Debug is enabled.
  • When debugging Lynx pages with the DevTool Desktop, Lynx DevTool needs to be enabled.
  • LogBox helps you quickly identify and diagnose issues.

You can configure these switches during Lynx Environment Initialization:

Objective-C
Swift
AppDelegate.m
#import <Lynx/LynxEnv.h>
#import <Lynx/LynxService.h>
#import <Lynx/LynxServiceDevToolProtocol.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // ...
  LynxEnv *lynxEnv = [LynxEnv sharedInstance];
  // Enable Lynx Debug
  lynxEnv.lynxDebugEnabled = YES;
  // Enable Lynx DevTool
  lynxEnv.devtoolEnabled = YES;
  // Enable Lynx LogBox
  [LynxService(LynxServiceDevToolProtocol) setLogBoxPresetValue:YES];
  lynxEnv.logBoxEnabled = YES;
  return YES;
}
INFO

In addition to the three switches introduced earlier, there are more switches that can help you control the behavior of DevTool. Please refer to the Lynx DevTool Switch Page.

Adding Dependencies

You need to integrate these two components: lynx-service-devtool and lynx-devtool

build.gradle
build.gradle.kts
// Ensure Lynx DevTool version matches the Lynx version when integrating
dependencies {
  implementation "org.lynxsdk.lynx:lynx-devtool:3.4.1"
  implementation "org.lynxsdk.lynx:lynx-service-devtool:3.4.1"
}
INFO

It is recommended to use the latest Lynx version when integrating

Registering DevTool Service

Java
Kotlin
YourApplication.java
private void initLynxService() {
  // ...
  // register DevTool service
  LynxServiceCenter.inst().registerService(LynxDevToolService.getINSTANCE());
}

Enabling DevTool

DevTool provides several debugging switches. Here are three important switches:

  • Lynx Debug is the switch that controls all DevTool debugging.
  • Lynx DevTool controls main debugging features: element inspection and JavaScript debugging.
  • Lynx LogBox manages the LogBox.
These three switches are disabled by default, you need to enable them.
  • Lynx DevTool and Lynx LogBox switches can only take effect after Lynx Debug is enabled.
  • When debugging Lynx pages with the DevTool Desktop, Lynx DevTool needs to be enabled.
  • LogBox helps you quickly identify and diagnose issues.

You can configure these switches during Lynx Environment Initialization:

Java
Kotlin
YourApplication.java
private void initLynxEnv() {
  LynxEnv.inst().init(this, null, null, null);
  // Enable Lynx Debug
  LynxEnv.inst().enableLynxDebug(true);
  // Enable Lynx DevTool
  LynxEnv.inst().enableDevtool(true);
  // Enable Lynx LogBox
  LynxDevToolService.getINSTANCE().setLogBoxPresetValue(true);
  LynxEnv.inst().enableLogBox(true);
}
INFO

In addition to the three switches introduced earlier, there are more that can help you control the behavior of DevTool. Please refer to the DevTool Switch Page.

Adding Dependencies

You need to integrate these two components: @lynx/lynx_devtool and @lynx/lynx_devtool_service.

oh-package.json5
build-profile.json5
// Ensure Lynx DevTool version matches the Lynx version when integrating
"dependencies": {
  "@lynx/lynx_devtool": "@param:dependencies.lynx_version",
  "@lynx/lynx_devtool_service": "@param:dependencies.lynx_version"
}
INFO

It is recommended to use the latest Lynx version when integrating

Registering DevTool Service

ETS
YourEntryAbility.ets
// Initialize LynxDevToolService first, as LynxEnv initialization
// depends on LynxDevToolService from LynxService
LynxServiceCenter.registerService(
  LynxServiceType.DevTool,
  LynxDevToolService.instance,
);

Enabling DevTool

DevTool provides several debugging switches. Here are three important switches:

  • Lynx Debug is the switch that controls all DevTool debugging.
  • Lynx DevTool controls main debugging features: element inspection and JavaScript debugging.
  • Lynx LogBox manages the LogBox.
Lynx Debug and LogBox are on by default; DevTool is off. Enabling DevTool is recommended.
  • Lynx DevTool and Lynx LogBox switches can only take effect after Lynx Debug is enabled.
  • When debugging Lynx pages with the DevTool Desktop, Lynx DevTool needs to be enabled.
  • LogBox helps you quickly identify and diagnose issues.

You can configure these switches during Lynx Environment Initialization:

ETS
YourEntryAbility.ets
public initLynxEnv() {
  LynxEnv.initialize(this.context);

  // Enable Lynx Debug
  LynxEnv.enableLynxDebug(true);
  // Enable Lynx DevTool
  LynxEnv.enableDevtool(true);
  // Enable Lynx LogBox
  LynxEnv.setLogBoxEnabled(true);
}
INFO

In addition to the three switches introduced earlier, there are more that can help you control the behavior of DevTool. Please refer to the DevTool Switch Page.

Congratulations! You have completed the DevTool integration. Now, you may launch the Lynx DevTool Desktop and connect your app via USB to start debugging.

Integrate Lynx DevTool Successfully

Next Step

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.