vscode-ios-debug icon indicating copy to clipboard operation
vscode-ios-debug copied to clipboard

Can't launch app on a real device

Open megabitsenmzq opened this issue 6 months ago ā€¢ 19 comments

Simulator works. But real devices are not. The app installed successfully but can't start the debug server.

Log below:

2024-1-2 1:14] [INFO] resolveDebugConfiguration {
    "name": "Launch without Installing",
    "type": "lldb",
    "request": "launch",
    "program": "${workspaceFolder}/build/Debug-${command:ios-debug.targetSdk}/Furecas.app",
    "iosBundleId": "com.JinyuMeng.Furecas",
    "iosTarget": "last-selected",
    "iosInstallApp": false,
    "__configurationTarget": 6,
    "expressions": "native",
    "relativePathBase": "/Users/megabits/Documents/Files/File Exchange/Furecas/Furecas App",
    "_adapterSettings": {
        "displayFormat": "auto",
        "showDisassembly": "auto",
        "dereferencePointers": true,
        "suppressMissingSourceFiles": true,
        "evaluationTimeout": 5,
        "consoleMode": "commands",
        "sourceLanguages": null,
        "terminalPromptClear": null,
        "evaluateForHovers": true,
        "commandCompletions": true,
        "reproducer": false
    }
}
[2024-1-2 1:14] [INFO] Checking if device (udid: 00008030-000DA9D11ABBAA2E) is still valid
[2024-1-2 1:14] [INFO] Found device with udid: 00008030-000DA9D11ABBAA2E
[2024-1-2 1:14] [INFO] resolveDebugConfigurationWithSubstitutedVariables {
    "name": "Launch without Installing",
    "type": "lldb",
    "request": "launch",
    "program": "/Users/megabits/Documents/Files/File Exchange/Furecas/Furecas App/build/Debug-iphoneos/Furecas.app",
    "iosBundleId": "com.JinyuMeng.Furecas",
    "iosTarget": {
        "udid": "00008030-000DA9D11ABBAA2E",
        "name": "Megabits Dev iPhone",
        "type": "Device",
        "version": "17.2.1",
        "buildVersion": "21C66",
        "runtime": "iOS 17.2.1",
        "sdk": "iphoneos",
        "modelName": "iPhone SE 2G",
        "source": "local"
    },
    "iosInstallApp": false,
    "__configurationTarget": 6,
    "expressions": "native",
    "relativePathBase": "/Users/megabits/Documents/Files/File Exchange/Furecas/Furecas App",
    "_adapterSettings": {
        "displayFormat": "auto",
        "showDisassembly": "auto",
        "dereferencePointers": true,
        "suppressMissingSourceFiles": true,
        "evaluationTimeout": 5,
        "consoleMode": "commands",
        "sourceLanguages": null,
        "terminalPromptClear": null,
        "evaluateForHovers": true,
        "commandCompletions": true,
        "reproducer": false
    },
    "iosRequest": "launch",
    "initCommands": [
        "platform select remote-ios",
        "command script import '/Users/megabits/.vscode/extensions/nisargjhaveri.ios-debug-0.4.0/lldb/simulator_focus.py'",
        "command script import '/Users/megabits/.vscode/extensions/nisargjhaveri.ios-debug-0.4.0/lldb/logs.py'"
    ]
}
[2024-1-2 1:14] [INFO] Getting path for app (bundle id: com.JinyuMeng.Furecas) on device (udid: 00008030-000DA9D11ABBAA2E)
[2024-1-2 1:14] [INFO] App device path (/private/var/containers/Bundle/Application/27340600-1C8C-433E-B963-6AC5D496D1DB/Furecas.app) retrieved in 282 ms
[2024-1-2 1:14] [INFO] Starting debugserver for device (udid: 00008030-000DA9D11ABBAA2E)
[2024-1-2 1:14] [ERROR] Error: Command failed: /Users/megabits/.vscode/extensions/nisargjhaveri.ios-debug-0.4.0/bin/ios-deploy --id 00008030-000DA9D11ABBAA2E --nolldb --faster-path-search --json


(Device UUID are fake for privacy.)

megabitsenmzq avatar Jan 01 '24 16:01 megabitsenmzq

You can try running the failing ios-deploy command directly and see what the error is? We need to improve logging a bit to actually log the command output as well in case of failure, but in the meantime this can give us some idea on why is it failing for you.

nisargjhaveri avatar Jan 05 '24 17:01 nisargjhaveri

It says:

{
  "Event" : "PasswordProtectedStatus",
  "Status" : 0
}{
  "Event" : "DeviceSupportError",
  "Status" : "Unable to locate DeviceSupport directory with suffix 'DeveloperDiskImage.dmg'. This probably means you don't have Xcode installed, you will need to launch the app manually and logging output will not be shown!"
}%

megabitsenmzq avatar Jan 08 '24 11:01 megabitsenmzq

The DeviceSupportError reported seems very relevant. Do you have the correct version of Xcode installed that support your device's iOS version?

If yes, need to debug further why ios-deploy can't find the DeveloperDiskImage for your device.

nisargjhaveri avatar Jan 11 '24 18:01 nisargjhaveri

Iā€˜m using the latest Xcode every day. And it's not a beta version. So the version should not be a problem.

After checking the Xcode.app content, I found that there is no iOS 17.2 DeviceSupport in /Applications/Xcode-15.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/. The newest version is iOS 16.4.

But there is an SDK for 17.2. /Applications/Xcode-15.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk

As I know, the current version of Xcode needs to download platform dmg after installed. Maybe the DeveloperDiskImage you need is there. /Library/Developer/CoreSimulator/Images

megabitsenmzq avatar Jan 13 '24 10:01 megabitsenmzq

Could you please try using latest ios-deploy directly.

If the issue still persists, it might be useful to create an issue on ios-deploy. If it gets fixed, we need to update ios-deploy here.

https://github.com/ios-control/ios-deploy

nisargjhaveri avatar Feb 13 '24 06:02 nisargjhaveri

OK! I will give it a try this weekend.

megabitsenmzq avatar Feb 14 '24 12:02 megabitsenmzq

I found this issue https://github.com/ios-control/ios-deploy/issues/588

It seems iOS-deploy is not supporting Xcode 15 now. Because "Apple has FINALLY created a non-hack mechanism with devicectl".

So maybe we can just switch to devicectl.

xcrun devicectl device install app --device 00008110-001XXXXXXXXXX ./xgen/Build/Products/Release-iphoneos/nilo.app
xcrun devicectl device process launch --device 00008110-001XXXXXXXXXX file:///private/var/containers/Bundle/Application/1604D2D5-35F3-4E43-8B47-1DEF5D778480/nilo.app

This first command should give you the file URL for the second command. I tried it out. It works perfectly.

megabitsenmzq avatar Mar 24 '24 07:03 megabitsenmzq

This is unfortunate. We do use ios-deploy for other actions such as starting the debugserver as well, which I believe devicectl does not yet support.

nisargjhaveri avatar Mar 26 '24 12:03 nisargjhaveri

Is it possible to only use devicectl to launch the app for now?

megabitsenmzq avatar Mar 26 '24 13:03 megabitsenmzq

Is it possible to only use devicectl to launch the app for now?

Even if launching works with devicectl, my hunch is that debugserver etc won't work as it also requires the developer image. We can try out by replacing launch part to devicectl, but not sure how much value it adds by simply launching if it fails to start debugging?

nisargjhaveri avatar Mar 28 '24 14:03 nisargjhaveri

Oh šŸ˜­. I'll check if there is any alternative way to launch the debug server. I'll tell you if I managed to find any.

megabitsenmzq avatar Mar 29 '24 15:03 megabitsenmzq

Right below the devicectl part, there is someone who suggested using pymobiledevice3 to connect LLDB.

https://github.com/ios-control/ios-deploy/issues/588#issuecomment-1907913430

It seems to work perfectly on my device.

image

megabitsenmzq avatar Mar 29 '24 15:03 megabitsenmzq

This is good that we have a solution!

Have a look at src/lib/devices.ts. We'd need to find alternatives for all or most of the methods we're using ios-deploy for.

Couple of additional thoughts:

  • It might be tricky to embed/take dependency on python modules from the VS Code extension. Should be possible though.
  • pymobiledevice3 seems to need to be run as privilleged process. This could be tricky to achieve from within the extension.

Happy to discuss on the design more or take in PRs in this direction. Though, if we know a fix for iOS 17, thinking if it would be possible to fix ios-deploy itself? Fixing ios-deploy may give more benefit overall. Though, not really sure how much work it would be port the solution from pymobiledevice3 to ios-deploy and would it even make sense.

nisargjhaveri avatar Mar 31 '24 18:03 nisargjhaveri

I don't quite know how to develop a vscode extension. Nether typescript. But I also thought Python in an extension might be tricky.

I'm looking at the source code of ios-deploy. Almost all the stuff is in a giant 3896 line file. It's kinda scary. I am mainly working on Swift. OC/C/C++ is not very familiar to me. Let me see if I can understand the code. šŸ˜‚

By the way, is the ios-deploy well maintained these days? If it has been somehow abandoned, maybe it's better to migrate to pymobiledevice3 from now on.

megabitsenmzq avatar Apr 01 '24 16:04 megabitsenmzq

It seems I found the code in ios-deploy which locates the device support image. Let me see if I can inject some code to make it work temporarily.

megabitsenmzq avatar Apr 01 '24 16:04 megabitsenmzq

Oh, I had a problem immediately. I can hard code the dmg URL, but it still won't work. Because for all the "DeveloperDiskImage.dmg" before iOS 17, there is a "DeveloperDiskImage.dmg.signature" file. Which is required to mount it to the device. But for the new ones, I can't find any. I'm stuck now. It seems Apple is using ".trustcache" files instead of ".signature" files. I can't find any document for it from Apple about how to use it. It's beyond my ability.

The new disk image is located at "/Library/Developer/DeveloperDiskImages/iOS_DDI.dmg". Inside the dmg file, there is "/Volumes/Xcode_iOS_DDI_Personalized/Restore/022-15428-264.dmg". That is the new iOS 17 disk image. And there is a "022-15428-264.dmg.trustcache" too.

megabitsenmzq avatar Apr 01 '24 17:04 megabitsenmzq

I did find how pymobiledevice3 solved this issue though: https://github.com/doronz88/pymobiledevice3/blob/master/pymobiledevice3/services/mobile_image_mounter.py

And other people from libimobiledevice discussing it: https://github.com/libimobiledevice/libimobiledevice/issues/1452

Maybe ditching ios-deploy is the right way.

megabitsenmzq avatar Apr 01 '24 17:04 megabitsenmzq

I'll continue trying to learn how iOS-deploy and pymobiledevice3 work. And see if there is any way to make ios-deploy work with ".trustcache". I can also research other solutions. (That's the only thing I can do because I know little about front-end stuff and extensions). Meanwhile, you can check if it's reasonable to embed pymobiledevice3 in the extension. In either way, we can make progress. Feel free to tell me if you have anything you want to test. šŸ˜Š

(Today I also tried facebook/idb, libimobiledevice/ideviceimagemounter, etc. None of them support iOS 17+ now.)

megabitsenmzq avatar Apr 03 '24 16:04 megabitsenmzq

I required the automation script made by sk2122 from the original iOS-deploy issue. Maybe we can use some of it. https://github.com/ios-control/ios-deploy/issues/588#issuecomment-2042088605

megabitsenmzq avatar Apr 08 '24 11:04 megabitsenmzq