Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't launch app on a real device #18

Open
megabitsenmzq opened this issue Jan 1, 2024 · 20 comments
Open

Can't launch app on a real device #18

megabitsenmzq opened this issue Jan 1, 2024 · 20 comments

Comments

@megabitsenmzq
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

OK! I will give it a try this weekend.

@megabitsenmzq
Copy link
Author

megabitsenmzq commented Mar 24, 2024

I found this issue ios-control/ios-deploy#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
Copy link
Owner

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
Copy link
Author

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

@nisargjhaveri
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

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

ios-control/ios-deploy#588 (comment)

It seems to work perfectly on my device.

image

@nisargjhaveri
Copy link
Owner

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.

@megabitsenmzq
Copy link
Author

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
Copy link
Author

megabitsenmzq commented Apr 1, 2024

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
Copy link
Author

megabitsenmzq commented Apr 1, 2024

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
Copy link
Author

megabitsenmzq commented Apr 1, 2024

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: libimobiledevice/libimobiledevice#1452

Maybe ditching ios-deploy is the right way.

@megabitsenmzq
Copy link
Author

megabitsenmzq commented Apr 3, 2024

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
Copy link
Author

I required the automation script made by sk2122 from the original iOS-deploy issue. Maybe we can use some of it. ios-control/ios-deploy#588 (comment)

@megabitsenmzq
Copy link
Author

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

flutter/flutter#133465 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants