Recently studied cross-end, recording some usage scenarios, first record, further organize later.
The front end and client collaborate to complete the development of functions. For real machine testing, it is still necessary to test on both the simulator and the real machine.
For example, when we implement Event, the actual return value of the event may differ on different devices, and it can only be confirmed by running it on a real machine.
The following tasks need to be completed:
- Switch the x-ios project to dev
- Switch uni-app to dev
- Ensure both folders are in the same directory
- Compile and run x-ios on Xcode to successfully run a project
- Find the resource files of the application in this simulator, see below
Find the Resource Files of the Application in This Simulator#
Find the Device ID of the Current Simulator#
Select xcode - window - Devices and Simulators - Your Device
Find Identifier
For example, my simulator's ID is
79FEB78D-E6F7-44E3-9741-44F6DAD53BC0
Enter the Simulator Resource Manager#
拼一下地址
Use Finder to open cmd+shift +g
and enter the address below, the string at the end is your ID
open ~/Library/Developer/CoreSimulator/Devices/Copy your device ID
# open ~/Library/Developer/CoreSimulator/Devices/79FEB78D-E6F7-44E3-9741-44F6DAD53BC0
Generally looks like this
Use cmd+shift+g
or command to enter hidden directories:
# Relative directory
cd data/Containers/Data/Application
# Absolute directory, for reference only
cd /Users/otto/Library/Developer/CoreSimulator/Devices/79FEB78D-E6F7-44E3-9741-44F6DAD53BC0/data/Containers/Data/Application
This is all installed apps, only one of them is the app, you can sort by the latest modification time or directly search for the uni-app-x
folder, usually the last one or the second to last.
Find uni-app-x/apps
, for reference only, the actual will change. It is recommended to save a Finder bookmark for quick access later.
cd /Users/otto/Library/Developer/CoreSimulator/Devices/79FEB78D-E6F7-44E3-9741-44F6DAD53BC0/data/Containers/Data/Application/2222EA54-73C7-4F89-ABCA-E1D35D80CFD7/Documents/uni-app-x
Generally contains the following content:
Supplement: This -dev.js also needs to be brought over.
The www directory here is the actual resources that need to be run, and you can replace the resources of hx.
Next, I will introduce how to replace.
hx's compilation output
Quick Code#
During subsequent debugging, it is necessary to frequently move the build dist folder of the IDE into the package of the simulator app. Here are a few shortcut commands, using soft links to achieve directory and file mapping.
This places the compilation output of buiderx onto the phone for debugging, and you can usually use the simulator for this.
Note that the simulator here has an additional native-app-service.js
, which we will look into later.
Related
- [What is uni-app-x-framework-dev.js?]
- What is app-service?
Below is the logic for replacing files
#!/bin/bash
source_dir="/Users/otto/mycode/dcloud/basic-hx-vue2/basic-uts-0117/unpackage/dist/dev/app"
target_dir="/Users/otto/Library/Developer/CoreSimulator/Devices/79FEB78D-E6F7-44E3-9741-44F6DAD53BC0/data/Containers/Data/Application/2222EA54-73C7-4F89-ABCA-E1D35D80CFD7/Documents/uni-app-x"
www_dir="$target_dir/apps/HBuilder/www"
# app-config.js
ln -sf "$source_dir/app-config.js" "$www_dir"
ln -sf "$source_dir/app-service.js" "$www_dir"
ln -sf "$source_dir/manifest.json" "$www_dir"
# Here you need to delete the original static first before executing
ln -sf "$source_dir/static" "$www_dir"
ln -sf /Users/otto/mycode/dcloud/about-ios/uvue-jsframework/packages/uni-framework/dist/uni-app-x-framework-dev.js "$target_dir"
# Below is the jsframework
How to Test the Latest Framework#
In uvue-jsframework
, perform build:framework
to obtain dist/uni-app-x-framework-dev.js
.
Copy this file to the uni-app-x
directory shown above, at the same level as apps
.
Kill the application on the simulator, and restart to get the latest version.
Next is how to set breakpoints and observe the actual running situation. Open the developer tools in Safari, this will be organized later.
Select Develop - Simulator - jscontext
After opening, select the source, see the screenshot, set breakpoints, for example, the touch event can be triggered.
How to Test Your Page and Demo#
Prerequisites include an Apple developer certificate, hbuilderx dev version, and an updated hosts file.
In hbuilderx Dev, create a new default blank project, select uts, and run it. If the certificate is prepared in advance, you can connect to the iOS device and start it.
The above is the compilation of custom pages to obtain the output. Below is how to replace the custom output into the simulator being tested.
Find unpackage/dist/dev/app
, this is the output.
Open the uni-app-x/apps/www
in the simulator application and make a replacement.
For example, mine is
cd /Users/otto/Library/Developer/CoreSimulator/Devices/B2B64986-2B82-4194-8CFE-1A8D0CD8A4C3/data/Containers/Data/Application/29CA23C3-A092-4959-9837-9DADE92874EB/Documents/uni-app-x/apps/HBuilder/www
Restart the application. This way, the content is replaced.
Subsequently, after implementing the function or needing to test, compile through hx. Place the output into the www directory of the simulator just now, equivalent to using hx as the compilation process for testing the output.
How to Replace Application Resources on the Phone#
Resources installed on the real phone need to use a phone assistant, such as iTunes Assistant, to achieve folder access and resource replacement.
Through such operations, resource file replacement can be achieved.
How to Start an Android Emulator#
First, start Android Studio, open Tools - Device Manager
, find a prepared emulator, click edit on the right, and find the name of this emulator.
It opens like this, copy the AVD Name.
Register emulator
to the global variable, it's better to place it under android.
# android
export ANDROID_HOME="/Users/otto/Library/Android/sdk"
## android studio simulator
export PATH="/Users/otto/Library/Android/sdk/emulator:$PATH"
Later, it was discovered that there is a command to list the inventory, using this method is simpler.
# The return value is the avd name
emulator -list-avds
# Later directly use the following quick start
emulator -avd Pixel_3a_API_34_extension_level_7_arm64-v8a
Appendix related command lines
Option | Description |
---|---|
-list-avds | List available AVDs. |
-sysdir <dir> | Search for system disk images in the specified directory. |
-system <file> | Read the initial system image from the specified file. |
-vendor <file> | Read the initial vendor image from the specified file. |
-writable-system | Make the system and vendor images writable after "adb remount". |
-delay-adb | Delay ADB communication until boot is complete. |
-datadir <dir> | Write user data to the specified directory. |
-kernel <file> | Use a specific simulated kernel. |
-ramdisk <file> | Use the specified ramdisk image (default is system/ramdisk.img). |
-image <file> | Deprecated; use -system <file> . |
-initdata <file> | Same as -init-data <file> . |
-data <file> | Use the specified data image (default is datadir/userdata-qemu.img). |
-encryption-key <file> | Read the initial encryption key image from the specified file. |
-logcat-output <file> | Output logcat to the specified file (default is none). |
-partition-size <size> | Set the size of the system/data partition, in MB. |
-cache <file> | Use the specified cache partition image (default is a temporary file). |
-cache-size <size> | Set the size of the cache partition, in MB. |
-no-cache | Disable the cache partition. |
-nocache | Same as -no-cache . |
-sdcard <file> | Use the specified SD card image (default is datadir/sdcard.img). |
-quit-after-boot <timeout> | Exit the emulator after the guest machine fully boots or after the specified timeout (in seconds). |
-qemu-top-dir <dir> | Use the emulator in the specified directory (relative or absolute path). |
-monitor-adb <verbose_level> | Monitor ADB messages between the guest and host, disabled by default. |
-snapstorage <file> | Store all state snapshots in the specified file (default is datadir/snapshots.img). |
-no-snapstorage | Disable all snapshot functionality. |
-snapshot <name> | Automatically start and save using the specified snapshot from the storage file (default is "default-boot"). |
-no-snapshot | Perform a full boot without automatic saving, but qemu vmload and vmsave operate on snapstorage. |
-no-snapshot-save | Do not automatically save to snapshot on exit: discard changed state. |
-no-snapshot-load | Do not automatically start from snapshot: perform a full boot. |
-snapshot-list | Display a list of available snapshots. |
-no-snapshot-update-time | Do not attempt to correct snapshot time upon restoration. |
-wipe-data | Reset the user data image (copy it from initdata). |
-avd <name> | Use a specific Android virtual device. |
-avd-arch <target> | Use a specific target architecture. |
-skindir <dir> | Search for skins in the specified directory (default is system/skins). |
-skin <name> | Select the given skin. |
-no-skin | Deprecated: create an AVD without a skin. |
-noskin | Same as -no-skin . |
How to Start an iOS Simulator#
After installing Xcode, you can directly start simulator
.