Skip to main content
On this page

Run and debug

Three ways to start (Build & Run, Run and Attach), what you see if a step fails after F5, panels and output during a debug session, launch.json fields and Dart debugging for Flutter.

Select your iPhone, set a breakpoint in your code and press F5. The extension builds, signs, installs and launches the app, then attaches the debugger, with no configuration. When a breakpoint hits you get the standard VS Code debug view. Here's an app running and debugging on a device from Windows.

The debug view stopped at a breakpoint

Three ways to start

ModeWhereWhat it does
Build & RunF5, ▶ in the view title bar, or the target row buttonBuilds with the current configuration, signs, installs on the selected device, launches and attaches the debugger
RunKXBuild: Run, or the target row buttonSkips the build. Installs the most recent build and launches it.
AttachKXBuild: Attach to Running AppLists the apps running on the iPhone and attaches the debugger to the one you pick

The build runs before the debug session starts, so the Restart button on the debug toolbar doesn't recompile. After changing code, stop and press F5 again.

Common errors

Every step after the build shows a progress notification you can cancel. If a step fails, the message names that step. Click "Show Output" for the full log.

MessageFix
No iOS device selectedSelect a device in the KXBuild view
Developer Mode is offTurn on Developer Mode on the iPhone and restart it
Developer Disk Image is not mountedReconnect the iPhone or run doctor
The device is not paired/trustedUnlock the iPhone and tap Trust
Not enough free space on the deviceFree up storage on the iPhone and try again
No valid provisioning profile, or the device is not in the provisioning profileSee Certificates and signing
did not report the app as launched in timeUnlock the iPhone and check the connection
didn't start in timeThe app may be crashing on launch. Check the device log.

While debugging

You can set breakpoints in Swift, Objective-C, C / C++ and the Kotlin code of Kotlin Multiplatform projects. Stepping, variables, the call stack, watch expressions and the Debug Console all work as in any VS Code debug session, and you can type lldb commands in the Debug Console. When you stop somewhere without source, open the assembly view. App output goes to Output > KXBuild Console and the build log to Output > KXBuild. Stopping the session quits the app on the iPhone, as Xcode does.

launch.json

F5 works without a launch.json. Add one only when you want to pin a device, target or build configuration. Set the debugger type to kxbuild. Here's an example and the available fields.

{ "version": "0.2.0", "configurations": [ { "type": "kxbuild", "request": "launch", "name": "KXBuild: Build & Run", "build": true }, { "type": "kxbuild", "request": "launch", "name": "KXBuild: Run", "build": false }, { "type": "kxbuild", "request": "attach", "name": "KXBuild: Attach", "attachPid": 0 } ] }
FieldDescription
buildtrue builds before installing. false installs the most recent build.
deviceDevice UDID. Omit to use the device selected in the view.
bundleBundle ID of the app target to run. Omit to use the project's only app target. If there are several, you're asked to pick one.
configurationDebug or Release. Omit to use the one selected in the view.
attachPidProcess ID to attach to. 0 shows a list to pick from when the session starts.

Flutter

In Flutter projects, F5 debugs the native Objective-C and Swift code right away. Debugging Dart code needs the VS Code Dart extension. If KXBuild detects a Flutter project without it, you're offered a one-click install. Afterwards run Build & Run again, and native and Dart breakpoints both work, with hot reload.

React Native

For React Native and Expo, KXBuild debugs the native side. For JS breakpoints, use the Metro / Hermes debugger. An imported uni-app project is a native shell around a WebView. Debug the native part in KXBuild and the page JS with the tools built into HBuilderX.

Next steps