Due to the large differences in mobile phones, HBuilder does not provide an App simulator. Regardless of uni-app or 5+App/wap2app projects, you need to connect a real mobile phone or mobile phone emulator to run the test, which is called "real machine running".

  • Android平台 HBuilder支持adb协议,在HBuilder运行的电脑上,可以使用usb线连接Android设备,也可以使用安装在电脑上的Android模拟器(包括google官方模拟器,三方模拟器如“雷电”、“夜神”等)
  • iOS平台 HBuilder支持itunes协议,在HBuilder运行的电脑上,使用usb线连接iPhone或iPad;如果是mac电脑,则可以连接XCode自带的iOS模拟器。如果是arm架构cpu,还可以直接启动真机运行基座。

The purpose of running the real machine is to realize the hot refresh of code modification and avoid packaging to see the effect. Edit the code in HBuilder, see the modification effect in real time on the mobile phone, and you can see the log in the HBuilder console.

# Run entry

The run entry can be activated through the run menu at the top of HBuilder, the run button on the toolbar, or a shortcut key.

  1. HBuilder顶部运行菜单
  1. Toolbar run button

Menu items can be quickly selected by number. For example, press "4" to select "Run to Android App Dock". You can also press the up and down keys and then enter to select.

Compared with the run menu at the top of HBuilder, the run menu under the run button on the toolbar has less content, and only the most common runs are reserved.

  1. 快捷键【Ctrl+r】

Actually activates the toolbar run button. You can continue to match the number keys to achieve quick operation without a mouse.

# connect device

点击运行到iOS或Android设备时,会弹出选择界面,需选择要连接的手机设备或模拟器。

可以多设备运行,每个运行设备会在HBuilder底部控制台新开一个独立窗口,互不干扰。 But a device can only run one project at the same time, and when different projects run to the same mobile phone, only the last project takes effect.

If you can't find your phone during the process of connecting the device, you can try to click the "Refresh" button. If you still can't find your phone, please refer to Real Phone Running FAQs

# Android设备选择

注意事项

  • 如果电脑里安装有模拟器(Android模拟器需要先启动),HBuilder会直接检测到设备并显示在候选列表中。可以参考如何安装模拟器
  • Make sure the USB debugging mode is turned on in the Android phone settings. Usually in the [Settings] [Developer Options] of the mobile phone, some mobile phones can also be set in the system notification bar after plugging in the data cable. Note that it cannot be set to U disk mode. If it is charging mode, you must set the charging time at the same time. Allow usb debugging.

# iOS设备选择

HBuilderX中自带的标准真机运行基座使用DCloud向苹果申请的企业开发者证书签名,根据苹果开发者企业计划许可协议要求,使用企业开发者证书签名的App只允许企业员工内部使用,不允许企业外部人员安装使用。 因收到苹果公司警告,自2022年9月14日起iOS真机设备不再支持使用标准真机运行基座,详情见论坛公告:https://ask.dcloud.net.cn/article/40041 在iOS真机设备上运行请向苹果申请证书制作自定义基座或者在Mac电脑使用iOS模拟器

注意事项

  • 确保usb线的连接通畅(有些数据线质量不佳,需使用高电压usb端口,如果无法识别时候请尝试更换数据线)
  • 如果windows电脑连接iOS设备需电脑安装iTunes软件,并确保apple的mobile device服务开启、iTunes可找到手机
  • 手机连接电脑后,确保在手机上弹出的“要信任此电脑吗?”提示框中点了“信任”按钮

# iOS模拟器

上面的界面会额外显示搜索框,因XCode的iOS模拟器非常多,可通过搜索框过滤快速选择需要使用的模拟器。

# run

When you run it for the first time, you will be prompted to install the "real machine running plug-in".

The plugin has a built-in "Standard Run Dock", which uses DCloud's package name, certificate and third-party SDK configuration. If you want to customize, you need to use custom playground

在运行菜单中选择要运行的手机设备或模拟器,点击运行按钮,会执行如下流程:

  1. uni-app项目编译(5+ App/Wap2App项目无需编译)
  2. 通过数据线给手机安装真机运行基座(需要手机屏幕高亮并在手机端点击允许)
  3. 编译后的代码同步到手机设备上
  4. 启动手机端的真机运行基座,加载同步到手机的代码(iPhone手机需手动点击桌面图标启动)

运行成功后,HBuilder底部的控制台显示成功日志。此后修改代码会差量同步到手机上,手机程序会动态热刷。同时console.log代码会打印到控制台上,点击打印日志可以跳转到相关代码。

# Run the project to the iOS real machine App to start automatically

Currently only supports MacOSX, not Windows

HBuilderX 3.7.0+ version, newly added to run the App project to the real iOS device, after running successfully, the App on the phone will be opened automatically.

As shown below:

Note: MacOSX needs to install the Xcode version that matches the iOS phone system. For example, if the iPhone system is iOS 16.2, you also need to install an Xcode version that supports iOS 16.2. If there is no iOS Platforms that matches the mobile phone system in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport directory, then the App cannot be launched automatically. Please click the running dock icon on the mobile phone to start it manually.

Use the following command to view Xcode iOS Platforms data.

ls -lh  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport

On MacOSX, if the App cannot be started automatically, please check the following reasons:

  • The iOS phone system does not match the Xcode version
  • The mobile phone is in the off-screen state
  • Failed to compile and run the project, or failed to install the base

# 标准基座

The standard operating base is provided by DCloud to facilitate the low-threshold debugging of developers. This base App uses DCloud's package name, certificate and third-party SDK configuration.

Under the condition that the native layer remains unchanged, dynamic codes such as js can be dynamically loaded on the running base to realize hot reload operation.

HBuilderX3.7.1版本调整标准基座支持的系统版本

  • Android平台 要求Android5(API Leavel 21)及以上系统,如需在Android4.4设备真机运行,请使用自定义基座。更多App支持的最低版本设置参考文档
  • iOS平台 Requires iOS10 and above. If you need to run on iOS9.* devices, please use a custom dock. For more minimum version settings supported by App, refer to [deploymentTarget] of manifest.json (https://uniapp.dcloud.net.cn/collocation/manifest-app.html#ios)

# 自定义基座

If you want to customize the native layer, you need to go through the packaging process of iOS or Android, and compile and package by XCode or Android studio to generate an ipa or apk installation package.

However, after packaging, it cannot be easily debugged, and cannot be hot reloaded and console logs displayed. So HBuilder provides a special option when packaging, packaging a "custom run base".

The entry of the packaged App is in the release menu at the top of HBuilder, or the shortcut key [Ctrl+u]

自定义运行基座可以所有配置生效(主要是manifest.json的配置),包括:

  • App名称、图标、封面splash、包名、证书
  • App module configuration, third-party sdk configuration (such as WeChat, push, map, voice recognition, etc. third-party sdk configuration)
  • App权限配置
  • uni原生插件
  • Configurations mentioned in other manifest.json documents that need to be packaged to take effect

After packaging the custom runtime base, HBuilder will automatically store the generated apk and ipa packages in the project directory/unpackage/debug directory, and the file names are android_debug.apk and iOS_debug.ipa respectively.

Only one custom pedestal can be generated for a project, and multiple generation only keeps the last result.

生成自定义基座后,在设备选择窗口,可以选择自定义基座,如下图所示:

注意:自定义运行基座必须在HBuilderX中真机运行使用,不可直接安装使用,启动时会弹出toast提示信息。正式发版时需要按正常打包方式重新打包。

HBuilderX 3.7.13起,MacOSX系统,App项目,支持运行自定义基座到iOS模拟器。参考文档

# Offline packaging to generate a custom running base

You can use the offline SDK package to generate a custom running base (the cli method is not supported, drag and drop the src into the editor, and re-identify the project type), and store the apk and ipa packages in the project directory/unpackage/debug directory after generation , and the file names are android_debug.apk and iOS_debug.ipa respectively.

# 基座闪退获取日志

# android平台

默认标准基座闪退 可以查看手机存储根目录 /Android/data/io.dcloud.HBuilder/logs/io.dcloud.HBuilder/crash/ 崩溃日志文件

自定义基座闪退 可以查看手机存储根目录 /Android/data/packageName/logs/packageName/crash/ 崩溃日志文件

packageName: apk包名

apk包名是“uni.UNIB89CXX”,目录则为:/Android/data/uni.UNIB89CXX/logs/uni.UNIB89CXX/crash/

注意不是所有崩溃都能捕获到并保存文件