nisargjhaveri / vscode-ios-debug

iOS debugging in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=nisargjhaveri.ios-debug
86 stars 10 forks source link

Can't launch app on a real device #18

Open megabitsenmzq opened 6 months ago

megabitsenmzq commented 6 months ago

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.)

nisargjhaveri commented 6 months ago

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.

megabitsenmzq commented 6 months ago

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!"
}%
nisargjhaveri commented 6 months ago

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.

megabitsenmzq commented 6 months ago

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

nisargjhaveri commented 5 months ago

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

megabitsenmzq commented 5 months ago

OK! I will give it a try this weekend.

megabitsenmzq commented 4 months ago

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.

nisargjhaveri commented 4 months ago

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.

megabitsenmzq commented 4 months ago

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

nisargjhaveri commented 4 months ago

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?

megabitsenmzq commented 3 months ago

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 commented 3 months ago

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
nisargjhaveri commented 3 months ago

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:

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.

megabitsenmzq commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 1 month ago

It seems we have a new tool to connect to LLDB in XCode 16 Beta!

https://github.com/flutter/flutter/issues/133465#issuecomment-2159512125