Skip to main content
On this page

uni-app Offline iOS Build on Windows with uniapp2xcode

Export an HBuilderX uni-app project and the DCloud iOS offline SDK as an Xcode project, then build, debug and package it locally with kxbuild.

Last updated

For a uni-app offline iOS build on Windows, uniapp2xcode does the first step in one command. It calls HBuilderX to compile the pages and exports them with the DCloud iOS offline SDK as an Xcode project, which kxbuild then compiles into an .ipa locally, with no queue and no build limit. After that, when only pages change, re-export with --update in a few seconds.

Usage: uniapp2xcode --project <uni-app project> --sdk <iOS offline SDK> --output <output dir> [options]. uniapp2xcode is a standalone program installed with kxbuild. It also has two subcommands, sdk (import and list offline SDKs) and config (set the bundle ID and AppKey). With the KXBuild plugin in HBuilderX you don't run it yourself, because the plugin does. For the full workflow from development to the App Store, see the uni-app stack page.

What options does uniapp2xcode take?

OptionDescription
-p, --project DIRHBuilderX uni-app project directory, containing manifest.json. Required.
--sdk DIR|autoRequired. auto uses the SDK you imported with sdk import that matches the current HBuilderX version. You can also pass the root of an unzipped SDK, containing HBuilder-Hello/, SDK/ and uniapp.podspec (SDKs for HBuilderX 5.13 and later). Download the SDK from the iOS offline SDK download page.
--hbx-version X.YWith --sdk auto, the HBuilderX version to pick the SDK for. Read from HBuilderX if omitted.
-o, --output DIROutput directory for the generated Xcode project. Required.
--cleanEmpties the output directory before exporting.
--updateUpdates a project exported earlier to the same output directory. When only the pages changed, only the pages are replaced, which takes a few seconds. When native settings or the SDK changed, it exports again.
--dcloud-appkey KEYDCloud app key. Required, or the app reports an AppKey error at launch. Apply for one at dev.dcloud.net.cn for your bundle ID. You can leave it out once it's saved in the project with config.
--bundle-id IDBundle ID. Required if nativeResources/ios/Info.plist doesn't set one.
--display-name NAMEApp name shown on the Home Screen.
--version-name / --version-codeOverrides the version and build number from manifest.json.
--team-id IDDevelopment team ID written to the project.
--hbx DIRHBuilderX install directory. Detected automatically if omitted.
--skip-buildSkips compiling the pages and uses the existing build output.
--force-buildCompiles the pages even if build output already exists.
--versionPrints the version.

How do I export a uni-app project as an Xcode project?

The export calls HBuilderX to compile the pages, then generates an Xcode project from them and the SDK, and installs the modules checked in manifest.json with CocoaPods. The app name, version, icons and permission descriptions come from manifest.json. Put any extra Info.plist keys in nativeResources/ios/Info.plist in the uni-app project. Both are applied on every export. The generated project is HBuilder-Hello\HBuilder-Hello.xcworkspace in the output folder.

Modules the current SDK doesn't have or can't link are skipped and listed at the end of the export, for example face verification in the 5.26 SDK. You can also add or remove modules after the export in the uniapp_subspecs list of HBuilder-Hello\Podfile, then run pod install in that folder.

> uniapp2xcode --project D:\work\myuniapp --sdk D:\sdk\HBuilder-iOS-SDK --output D:\work\myuniapp-ios --bundle-id com.example.myapp --dcloud-appkey YOUR_APPKEY --clean

After you change page code in HBuilderX, export again to bring the changes into the iOS project. Once the SDK is imported and the config is saved, update with --sdk auto and --update. When only the pages changed, this takes a few seconds:

> uniapp2xcode --project D:\work\myuniapp --sdk auto --output D:\work\myuniapp-ios --update

How do I import the DCloud iOS offline SDK (sdk)?

Import the iOS offline SDK zip you downloaded from DCloud once. After that, export with --sdk auto and the SDK matching your HBuilderX version is picked automatically. You don't need to unzip it, and you import each HBuilderX version once.

> uniapp2xcode sdk import D:\Downloads\iOS-SDK.zip

uniapp2xcode sdk list lists the imported SDK versions. To import the same version again, add --force. Both subcommands accept --json for JSON output.

How do I save the bundle ID and AppKey in the project (config)?

Saves the bundle ID and DCloud AppKey to nativeResources/ios/Info.plist in the uni-app project, so later exports don't need --bundle-id and --dcloud-appkey. Values entered in the HBuilderX plugin are saved there too. With only --project, it prints the current values.

> uniapp2xcode config --project D:\work\myuniapp --bundle-id com.example.myapp --dcloud-appkey YOUR_APPKEY

What do the uniapp2xcode exit codes mean?

CodeMeaning
0Success
1Any other error. See the output for the reason
3--sdk auto found no SDK matching the HBuilderX version. Import one with sdk import first
4The bundle ID or AppKey is missing. Save them with config, or pass them on the command line

How do I compile the exported project into an .ipa on Windows?

The .xcworkspace in the output directory is an ordinary iOS project. Run doctor on it first, then build it or debug it in VS Code.

> kxbuild doctor D:\work\myuniapp-ios\HBuilder-Hello\HBuilder-Hello.xcworkspace
> kxbuild build D:\work\myuniapp-ios\HBuilder-Hello\HBuilder-Hello.xcworkspace -s HBuilder -c Release --export app-store

The Release build with --export app-store gives you an .ipa ready for the App Store, which completes the uni-app offline iOS build. For signing, iPhone debugging and submission, see uni-app iOS build on Windows.

Next steps