beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.59k stars 365 forks source link

Add ability to run iOS app on a physical device #860

Open freakboy3742 opened 2 years ago

freakboy3742 commented 2 years ago

At present, you can use briefcase run iOS (with an optional -d <device>) to run on an iOS simulator device. However, it is not possible to deploy to a physical iOS device that is attached by a USB cable.

Describe the solution you'd like

It should be possible to use briefcase run iOS to deploy to a physical device.

Describe alternatives you've considered

The current workaround is to:

  1. Open the Xcode project generated by Briefcase (The dev version of Briefcase simplifies this with briefcase open iOS)
  2. Select the root node of the Project in Xcode project explorer
  3. Select "Signing & Capabilities"
  4. Select a development team that has a Development or Distribution certificate
  5. Select a physical device from the device pulldown at the top of the screen
  6. Press the Run button.

Additional context

Xcode does a lot of automated management of signing identities and certificates, including automated registration of devices against the developer certificate. Any implementation of this feature will need to be careful about whether previous Xcode usage has "tainted" a clean developer environment.

xcodebuild provides a number of options for setting build properties (like signing identities). (e.g., passing in CODE_SIGN_IDENTITY as an option)

A list of physically attached devices can be obtained using xcrun xctrace list devices. This list also includes simulators; it may be possible to use a single call to list all available devices (simulator and physical).

derzhavets commented 1 year ago

I am also trying to run the app on physical iOS device using XCode, and getting this error:

Undefined symbols for architecture arm64: "_mknodat", referenced from: _os_mknod in libPython3.9.a(posixmodule.o) "_mkfifoat", referenced from: _os_mkfifo in libPython3.9.a(posixmodule.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

As I understand the python build that briefcase used is not suitable for arm64. How can this be resolved?

freakboy3742 commented 1 year ago

@derzhavets Firstly, this is a feature request ticket for adding a specific feature to Briefcase. If you've found a bug, it would be helpful if you log a bug ticket, rather than muddy the discussion about a potential new feature.

Secondly, when you raise that bug ticket, we're going to need a lot more detail about what you're doing. "I got an error" with a curated selection from a compiler error doesn't help us reproduce the problem or provide any guidance on how to fix the problem.

FWIW, I'm not aware of any ARM64 issues of the type you describe, and I'm not sure what would have given you that impression, beyond the issue you're seeing with your particular app. BeeWare most definitely supports ARM64, and has done for several years. We can't currently do CI testing on ARM64, but my daily development driver is an M1 laptop, and I also test on physical devices, so I do a lot of testing on ARM64, and I'm not aware of any systematic ARM64 problems.

woodworthkyle commented 1 month ago

Hi @freakboy3742, I think we would be able to take advantage of the devicectl sub-command of xcrun. It's similar to the simctl sub-command and has the json output argument for listing devices. I've also been helping out a rust-based cross-platform UI (floem) to support iOS and I had to go down the rabbit hole of code signing, certificates, provisioning profiles, and entitlements.

There is probably a way to use xcodebuild to create a signed app bundle with a provisioning profile. You can also create and sign the app bundle manually, you just have to have the correct payload/app-bundle structure and Info.plist contents. Once you have the app-bundle you can use devicectl to install and launch. There is also a --console argument when launching the app bundle from devicectl but will be available in the next release of Xcode (https://forums.developer.apple.com/forums/thread/756393).

# Install on iOS device
xcrun devicectl device install app --device <device_id> <path to app bundle we have built on dev machine>
# Launch on iOS device
xcrun devicectl device process launch --device <device_id> <path to app bundle on iOS device; found from the output of the previous command>