> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# Integrating Lynx DevTool

When encountering issues during Lynx page development, you can use [DevTool](/next/guide/devtool/panels.md) 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.

- **Package size**: DevTool will increase the package size.
- **Runtime**: Related modules are lazy loaded when enabled, which will increase memory overhead, and some features may affect the loading performance.

All code examples in this documentation can be found in the [integrating-lynx-demo-projects](https://github.com/lynx-family/integrating-lynx-demo-projects/tree/main).
:::

iOSAndroidHarmonyOS

### Adding Dependencies

Add the following dependencies to your Podfile: the `Devtool` subspec of `LynxService`, `LynxDevtool`, and `DebugRouter`. For `LynxService` and `LynxDevtool`, use the same version as `Lynx`.

Make sure your Podfile includes the `lynx-family` Specs repository as a source, as shown in the [Lynx integration guide](/next/guide/start/integrate-with-existing-apps.md?platform=ios).

```ruby title="Podfile" {2-8}
# Ensure Lynx DevTool version matches the Lynx version when integrating
target 'YourTarget' do
  pod 'LynxService', '4.2.0', :subspecs => [
      'Devtool',
  ]
  pod 'LynxDevtool', '4.2.0'

  pod 'DebugRouter', '5.0.15'
  pod 'DebugRouter/MessageTransceiverEnable', '5.0.15'
end
```

### Enabling DevTool

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

- `Lynx DevTool` controls main debugging features: element inspection and JavaScript debugging.
- `Lynx LogBox` manages the [LogBox](/next/guide/devtool/handle-errors.md).

> **These switches are disabled by default, you need to enable them.**
> 
> - `Lynx DevTool` and `Lynx LogBox` switches can only take effect after DevTool is in `ENABLED` state.
> - 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](/next/guide/start/integrate-with-existing-apps.md):

**Objective-C**

```objective-c title=AppDelegate.m {7-13}
#import <Lynx/LynxEnv.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // ...
  // Prepare DevTool
  [LynxEnv prepareDevToolForDevelopmentBeforeInit];
  LynxEnv *lynxEnv = [LynxEnv sharedInstance];
  // Enable Lynx DevTool Switch
  lynxEnv.devtoolEnabled = YES;
  // Enable Lynx LogBox Switch
  lynxEnv.logBoxEnabled = YES;
  return YES;
}
```

**Swift**

```objective-c title="YourTarget-Bridging-Header.h"
#import <Lynx/LynxEnv.h>
```

```swift title=AppDelegate.swift {5-11}
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // ...
    // Prepare DevTool
    LynxEnv.prepareDevToolForDevelopmentBeforeInit()
    let lynxEnv = LynxEnv.sharedInstance()
    // Enable Lynx DevTool Switch
    lynxEnv.devtoolEnabled = true
    // Enable Lynx LogBox Switch
    lynxEnv.logBoxEnabled = true
    return true
  }
}
```

:::info
In addition to the switches introduced earlier, there are more switches that can help you control the behavior of DevTool. Please refer to the [Lynx DevTool Switch Page](/next/guide/start/integrate-lynx-devtool-advanced.md#debugging-devtool-switch).
:::

### Adding Dependencies

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

**build.gradle**

```groovy
// Ensure Lynx DevTool version matches the Lynx version when integrating
dependencies {
  implementation "org.lynxsdk.lynx:lynx-devtool:4.2.0"
  implementation "org.lynxsdk.lynx:lynx-service-devtool:4.2.0"
}
```

**build.gradle.kts**

```kotlin
// Ensure Lynx DevTool version matches the Lynx version when integrating
dependencies {
  implementation ("org.lynxsdk.lynx:lynx-devtool:4.2.0")
  implementation ("org.lynxsdk.lynx:lynx-service-devtool:4.2.0")
}
```

:::info
It is recommended to use the latest [Lynx version](https://github.com/lynx-family/lynx/releases) when integrating
:::

### Registering DevTool Service

DevTool Service provides some bootstrap values to control default behaviors. You can configure them as needed; the snippets below apply the development defaults to the values that have not been set.

**Java**

```java title=YourApplication.java {3-6}
private void initLynxService() {
  // ...
  // register DevTool service
  LynxServiceCenter.inst().registerService(LynxDevToolService.getINSTANCE());
  // Prepare DevTool
  LynxEnv.inst().prepareDevToolForDevelopmentBeforeInit();
}

```

**Kotlin**

```kotlin title=YourApplication.kt {3-6}
private fun initLynxService() {
  // ...
  // register DevTool service
  LynxServiceCenter.inst().registerService(LynxDevToolService.INSTANCE)
  // Prepare DevTool
  LynxEnv.inst().prepareDevToolForDevelopmentBeforeInit()
}
```

### Enabling DevTool

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

- `Lynx DevTool` controls main debugging features: element inspection and JavaScript debugging.
- `Lynx LogBox` manages the [LogBox](/next/guide/devtool/handle-errors.md).

> **These switches are disabled by default, you need to enable them.**
> 
> - `Lynx DevTool` and `Lynx LogBox` switches can only take effect after DevTool is in `ENABLED` state.
> - When debugging Lynx pages with the DevTool Desktop, `Lynx DevTool` needs to be enabled.
>   - If you need to use JavaScript debugging, you also need to set the `LoadQJSBridge` or `LoadV8Bridge` bootstrap value to `true`.
>     - `LoadQJSBridge` controls loading the PrimJS engine debugging library.
>     - `LoadV8Bridge` controls loading the V8 engine debugging library.
> - LogBox helps you quickly identify and diagnose issues.
> 


You can configure these switches during [Lynx Environment Initialization](/next/guide/start/integrate-with-existing-apps.md):

**Java**

```java title=YourApplication.java {3-8}
private void initLynxEnv() {
  LynxEnv.inst().init(this, null, null, null);
  // Advance DevTool to ENABLED state
  LynxEnv.inst().enableLynxDebug(true);
  // Enable Lynx DevTool Switch
  LynxEnv.inst().enableDevtool(true);
  // Enable Lynx LogBox Switch
  LynxEnv.inst().enableLogBox(true);
}

```

**Kotlin**

```kotlin title=YourApplication.kt {3-8}
private fun initLynxEnv() {
  LynxEnv.inst().init(this, null, null, null)
  // Advance DevTool to ENABLED state
  LynxEnv.inst().enableLynxDebug(true)
  // Enable Lynx DevTool Switch
  LynxEnv.inst().enableDevtool(true)
  // Enable Lynx LogBox Switch
  LynxEnv.inst().enableLogBox(true)
}
```

:::info
In addition to the switches introduced earlier, there are more that can help you control the behavior of DevTool. Please refer to the [DevTool Switch Page](/next/guide/start/integrate-lynx-devtool-advanced.md#debugging-devtool-switch).
:::

### Adding Dependencies

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

**oh-package.json5**

```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"
}
```

**build-profile.json5**

```json5
// Since @lynx/lynx_devtool is dynamically imported via a variable,
// to include the devtool module in the build,
// you also need to add a runtimeOnly buildOption in buildOption within build-profile.json5.
"buildOption": {
    "arkOptions": {
      "runtimeOnly": {
        "packages": [
          "@lynx/lynx_devtool"
        ]
      }
    },
}
```

:::info
It is recommended to use the latest [Lynx version](https://github.com/lynx-family/lynx/releases) when integrating
:::

### Registering DevTool Service

**ETS**

```ts title=YourEntryAbility.ets {2 - 3}
// 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 some important switches:

- `Lynx DevTool` controls main debugging features: element inspection and JavaScript debugging.
- `Lynx LogBox` manages the [LogBox](/next/guide/devtool/handle-errors.md).

> **LogBox is on by default, DevTool is off. Enabling DevTool is recommended.**
> 
> - `Lynx DevTool` and `Lynx LogBox` switches can only take effect after DevTool is in `ENABLED` state.
> - 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](/next/guide/start/integrate-with-existing-apps.md):

**ETS**

```ts title=YourEntryAbility.ets {4-9}
public initLynxEnv() {
  LynxEnv.initialize(this.context);

  // Advance DevTool to ENABLED state
  LynxEnv.enableLynxDebug(true);
  // Enable Lynx DevTool Switch
  LynxEnv.enableDevtool(true);
  // Enable Lynx LogBox Switch
  LynxEnv.setLogBoxEnabled(true);
}

```

:::info
In addition to the switches introduced earlier, there are more that can help you control the behavior of DevTool. Please refer to the [DevTool Switch Page](/next/guide/start/integrate-lynx-devtool-advanced.md#debugging-devtool-switch).
:::

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](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/doc/devtool_connected_success.png)

- [More DevTool Switches](/next/guide/start/integrate-lynx-devtool-advanced): Need more advanced configurations for DevTool?


## Compatibility

**Compatibility Table**

**Query:** `devtool.integration`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/devtool/integration.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| lazy&#95;load | Yes (3.0) | Yes (3.0) | Yes (3.0) | Unknown | Unknown | No |
| switch.switchPage | Yes (3.0) | Yes (3.0) | Yes (3.0) | Unknown | Unknown | No |
| connection.usb | Yes (3.0) | Yes (3.0) | Yes (3.0) | Unknown | Unknown | No |

**`lazy_load`**

Lazy load

**`switch.switchPage`**

Switch page

**`connection.usb`**

USB connection


## Next Step

- [Use DevTool](/next/guide/devtool/panels): Learn how to use Lynx DevTool Desktop for in-depth debugging capabilities

