dwyl / learn-flutter

🦋 Learn how to use Flutter to Build Cross-platform Native Mobile Apps
https://flutter.dev
GNU General Public License v2.0
73 stars 8 forks source link

How to connect a *real* `iPhone` to your Mac and test `Flutter` Apps #79

Open nelsonic opened 1 year ago

nelsonic commented 1 year ago

As stated in Mac Focussed? 🍏, we are focussing at least 50% of our dev/testing efforts on iPhone because that's where vast majority of people that pay for Apps are. 🎫 Obviously we will still devote the 40% to Android and we want the UI/UX to be seamless on as many devices as possible. But if we want our App & company to be sustainable, this iOS is where we need to focus. 🎯

Official docs look like a good starting point: https://docs.flutter.dev/deployment/ios 📜 And this looks decent too: https://medium.com/front-end-weekly/how-to-test-your-flutter-ios-app-on-your-ios-device-75924bfd75a8

How To Run App On Real iOS Device/iPhone [2021] Screen Mirroring Flutter App: https://youtu.be/AYNhO9dcbBI

image

Going to spend an hour:

nelsonic commented 1 year ago

Trouble-shooting: https://stackoverflow.com/questions/58619427/physical-device-ipad-not-detected-in-vs-code-for-flutter-but-detected-and-work ...

nelsonic commented 1 year ago

Seeing the following error in my VSCode debug console:

    /opt/homebrew/Cellar/cocoapods/1.11.3/libexec/bin/pod:25:in `load'
    /opt/homebrew/Cellar/cocoapods/1.11.3/libexec/bin/pod:25:in `<main>'
Error output from CocoaPods:
↳
    [!] Automatically assigning platform `iOS` with version `11.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.
To update the CocoaPods specs, run:
  pod repo update

Error running pod install
Error launching application on iPhone SE (3rd generation).
Exited

Investigating ... 🔍

nelsonic commented 1 year ago

Ran:

brew install cocoapods

That took a while:

==> Upgrading cocoapods
  1.11.3 -> 1.11.3_1

==> Installing dependencies for cocoapods: ca-certificates and ruby
==> Installing cocoapods dependency: ca-certificates
==> Pouring ca-certificates--2023-01-10.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /opt/homebrew/Cellar/ca-certificates/2023-01-10: 3 files, 216.9KB
==> Installing cocoapods dependency: ruby
==> Pouring ruby--3.2.0.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/ruby/3.2.0: 16,574 files, 46.8MB
==> Installing cocoapods
==> Pouring cocoapods--1.11.3_1.arm64_ventura.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/cocoapods/1.11.3_1: 13,476 files, 27.9MB
==> Running `brew cleanup cocoapods`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Removing: /opt/homebrew/Cellar/cocoapods/1.11.3... (13,517 files, 28.3MB)
==> Upgrading 2 dependents of upgraded formulae:
Disable this behaviour by setting HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
erlang 25.1.1 -> 25.2.2, elixir 1.14.1 -> 1.14.3
==> Fetching dependencies for erlang: m4, libtool, unixodbc, jpeg-turbo, libpng, xz and pcre2
==> Fetching m4
==> Downloading https://ghcr.io/v2/homebrew/core/m4/manifests/1.4.19
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/m4/blobs/sha256:11308abe8d607be35da9e88a1d789f191914bf043bca4fdde2b50a6cbf1713cc
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:11308abe8d607be35da9e88a1d789f191914bf043bca4fdde2b50a6cbf1713cc?se=2023-02-03T16%3A10%3A00Z&sig=iQIx93LrmCKcZE4MC%2Bh9
######################################################################## 100.0%
==> Fetching libtool
==> Downloading https://ghcr.io/v2/homebrew/core/libtool/manifests/2.4.7
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libtool/blobs/sha256:924534e0a6c2f0562d3b6d033be241bfb0554211103daa14c46790803b9a8b9e
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:924534e0a6c2f0562d3b6d033be241bfb0554211103daa14c46790803b9a8b9e?se=2023-02-03T16%3A10%3A00Z&sig=3IDewMdIFnHAPoLVEewRyJ
######################################################################## 100.0%
==> Fetching unixodbc
==> Downloading https://ghcr.io/v2/homebrew/core/unixodbc/manifests/2.3.11
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/unixodbc/blobs/sha256:4c0380e01085731950092d3fdbcb24865abcb7745cbb318759e21d77e14c2fa1
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:4c0380e01085731950092d3fdbcb24865abcb7745cbb318759e21d77e14c2fa1?se=2023-02-03T16%3A10%3A00Z&sig=AmXPJtckVSaT60GqaRSE%2
######################################################################## 100.0%
==> Fetching jpeg-turbo
==> Downloading https://ghcr.io/v2/homebrew/core/jpeg-turbo/manifests/2.1.5
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/jpeg-turbo/blobs/sha256:d00e1ed5362087315ba0d537102311e6d8432c5cbe9296697141a02d53a6cdbe
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:d00e1ed5362087315ba0d537102311e6d8432c5cbe9296697141a02d53a6cdbe?se=2023-02-03T16%3A10%3A00Z&sig=av7YhmorB3I6TgN4%2BDiV
######################################################################## 100.0%
==> Fetching libpng
==> Downloading https://ghcr.io/v2/homebrew/core/libpng/manifests/1.6.39
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libpng/blobs/sha256:5fcb6945c7fe220f8b983c18edd7a42d8d84a9d62696b4fec001c1697300fb61
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:5fcb6945c7fe220f8b983c18edd7a42d8d84a9d62696b4fec001c1697300fb61?se=2023-02-03T16%3A10%3A00Z&sig=sQ2pV0bwSBzIciyYC1n0ge
######################################################################## 100.0%
==> Fetching xz
==> Downloading https://ghcr.io/v2/homebrew/core/xz/manifests/5.4.1
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/xz/blobs/sha256:26ede511c3cc726f939dd2f61b7e6798409c86b62be4678f008a12d515584efb
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:26ede511c3cc726f939dd2f61b7e6798409c86b62be4678f008a12d515584efb?se=2023-02-03T16%3A10%3A00Z&sig=VO3fQkMFoIUdQjRMVNCdlt
######################################################################## 100.0%
==> Fetching pcre2
==> Downloading https://ghcr.io/v2/homebrew/core/pcre2/manifests/10.42
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pcre2/blobs/sha256:8423a338c590ab1a6f265b39a9d1a67ab1361a586f0e494a8c9555cff2867536
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:8423a338c590ab1a6f265b39a9d1a67ab1361a586f0e494a8c9555cff2867536?se=2023-02-03T16%3A10%3A00Z&sig=udYL%2BQEVj1EL6mEkiGfK
######################################################################## 100.0%
==> Fetching erlang
==> Downloading https://ghcr.io/v2/homebrew/core/erlang/manifests/25.2.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/erlang/blobs/sha256:fae10ce63eec4d616ad05434cb42c695a84d4a136a3a96e0b4879125c5e0b0a2
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:fae10ce63eec4d616ad05434cb42c695a84d4a136a3a96e0b4879125c5e0b0a2?se=2023-02-03T16%3A10%3A00Z&sig=QZ83dZDvX4UzU4ZUnC3C0G
######################################################################## 100.0%
==> Fetching elixir
==> Downloading https://ghcr.io/v2/homebrew/core/elixir/manifests/1.14.3
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/elixir/blobs/sha256:610af16d19faccbe2ceb01aa6003a0d5267967602ec831a88f2ef650474750f6
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:610af16d19faccbe2ceb01aa6003a0d5267967602ec831a88f2ef650474750f6?se=2023-02-03T16%3A10%3A00Z&sig=D7YOT4Z%2BkFP0VOu4%2FV
######################################################################## 100.0%
==> Upgrading erlang
  25.1.1 -> 25.2.2

==> Installing dependencies for erlang: m4, libtool, unixodbc, jpeg-turbo, libpng, xz and pcre2
==> Installing erlang dependency: m4
==> Pouring m4--1.4.19.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/m4/1.4.19: 13 files, 742.4KB
==> Installing erlang dependency: libtool
==> Pouring libtool--2.4.7.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libtool/2.4.7: 75 files, 3.8MB
==> Installing erlang dependency: unixodbc
==> Pouring unixodbc--2.3.11.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/unixodbc/2.3.11: 48 files, 2.3MB
==> Installing erlang dependency: jpeg-turbo
==> Pouring jpeg-turbo--2.1.5.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/jpeg-turbo/2.1.5: 44 files, 2.5MB
==> Installing erlang dependency: libpng
==> Pouring libpng--1.6.39.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libpng/1.6.39: 27 files, 1.3MB
==> Installing erlang dependency: xz
==> Pouring xz--5.4.1.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/xz/5.4.1: 95 files, 1.7MB
==> Installing erlang dependency: pcre2
==> Pouring pcre2--10.42.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/pcre2/10.42: 230 files, 6.2MB
==> Installing erlang
==> Pouring erlang--25.2.2.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/erlang/25.2.2: 7,888 files, 488.3MB
==> Running `brew cleanup erlang`...
Removing: /opt/homebrew/Cellar/erlang/25.1.1... (7,872 files, 487.7MB)
==> Upgrading elixir
  1.14.1 -> 1.14.3

==> Pouring elixir--1.14.3.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/elixir/1.14.3: 442 files, 6.7MB
==> Running `brew cleanup elixir`...
Removing: /opt/homebrew/Cellar/elixir/1.14.1... (442 files, 6.7MB)
==> Checking for dependents of upgraded formulae...
==> No broken dependents found!

Still get the same error ... 😞

Googling ...

nelsonic commented 1 year ago

Matches: https://stackoverflow.com/questions/64443888/flutter-cocoapodss-specs-repository-is-too-out-of-date-to-satisfy-dependencies reading ... ⏳

nelsonic commented 1 year ago

Had to enable Settings → Privacy & Security → "Developer Mode" on my (personal) iPhone to get this working.

nelsonic commented 1 year ago

And ... the iOS device (iPhone) must be on the same Apple (iTunes) account ... 🙄 In my case my iPhone is not on the same account as my Mac ... so I will need to ... 💭 Oh hold on, I do have an iPhone 6S I can use that is connected to my the same Apple Account as my Mac!! 🎉 BRB!

nelsonic commented 1 year ago

While I wait for my iPhone 6S (ancient but still working) device to update to iOS 15, Tried following the instructions in the SO answer:

rm ios/Podfile.lock
flutter run

Got the following error:

Failed to build iOS app
Error (Xcode): lib/database.g.dart:155:27: Error: The argument type 'String' can't be assigned to the parameter type 'void Function(GenerationContext)?'.

Could not build the application for the simulator.
Error launching application on iPhone SE (3rd generation).
nelsonic commented 1 year ago

Tried to run it on the iPad Pro 12" instead and got the following error:

Launching lib/main.dart on iPad Pro 12 in debug mode...
════════════════════════════════════════════════════════════════════════════════
No valid code signing certificates were found
You can connect to your Apple Developer account by signing in with your Apple ID
in Xcode and create an iOS Development Certificate as well as a Provisioning
Profile for your project by:
  1- Open the Flutter project's Xcode target with
       open ios/Runner.xcworkspace
  2- Select the 'Runner' project in the navigator then the 'Runner' target
     in the project settings
  3- Make sure a 'Development Team' is selected under Signing & Capabilities > Team.
     You may need to:
         - Log in with your Apple ID in Xcode first
         - Ensure you have a valid unique Bundle ID
         - Register your device with your Apple Developer Account
         - Let Xcode automatically provision a profile for your app
  4- Build or run your project again
  5- Trust your newly created Development Certificate on your iOS device
     via Settings > General > Device Management > [your new certificate] > Trust

For more information, please visit:
  https://developer.apple.com/library/content/documentation/IDEs/Conceptual/
  AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html

Or run on an iOS simulator without code signing
════════════════════════════════════════════════════════════════════════════════
Exception: No development certificates available to code sign app for device deployment
nelsonic commented 1 year ago

After a bit of digging, I've discovered that because I've got iOS 16.2 in my XCode and iPhone 6S only goes up to iOS 15, I cannot use it as a device for testing ... 😢

image

So I'm not going to be use this device for testing. 👎 Gonna need to retrieve the iPhone 8 from the Studio @home on Monday. ⏳

nelsonic commented 1 year ago

This seems convoluted: https://stackoverflow.com/a/71458394/1148249 ... 🤷‍♂️

nelsonic commented 1 year ago

Reading: https://codecrew.codewithchris.com/t/solved-install-cocoapod-on-m1-mac-sudo-gem-install-ffi-fail/15648 Perform all these in the macOS Terminal program, not iTerm, Warp, etc.

brew install libffi

Output:

==> Fetching libffi
==> Downloading https://ghcr.io/v2/homebrew/core/libffi/manifests/3.4.4
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/libffi/blobs/sha256:66d9dcb2182
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Pouring libffi--3.4.4.arm64_ventura.bottle.tar.gz
==> Caveats
libffi is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

For compilers to find libffi you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/libffi/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/libffi/include"

==> Summary
🍺  /opt/homebrew/Cellar/libffi/3.4.4: 17 files, 724.8KB
==> Running `brew cleanup libffi`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

What is libffi you ask? https://github.com/libffi/libffi "A portable foreign-function interface library." A few open issues for M1: https://github.com/libffi/libffi/issues?q=is%3Aissue+is%3Aopen+m1 💭

brew reinstall cocoapods

Quit the terminal, then re-open and pod install should work.

nelsonic commented 1 year ago

image

Still get the same error: image

Failed to build iOS app
Error (Xcode): lib/database.g.dart:155:27: Error: The argument type 'String'
can't be assigned to the parameter type 'void Function(GenerationContext)?'.

Could not build the application for the simulator.
Error launching application on iPhone SE (3rd generation).

What is lib/database.g.dart:155:27 ? 🤷 In it's current state: https://github.com/dwyl/flutter-stopwatch-tutorial/blob/33907b1b01760dd49db85fa97fb84ce4562252ae/lib/database.g.dart#L155

The file is generated ... Reading: https://docs.flutter.dev/development/data-and-backend/json#code-generation Read: https://infinum.com/handbook/flutter/basics/code-generation

Going to try deleting it and re-creating it ...

rm lib/database.g.dart
flutter pub run build_runner build

Ref: https://mixable.blog/flutter-generating-g-dart-files-for-json-serialization/ (⚠️ Warning: lots of ads + trackers ...)

Now when I run:

flutter run

I get:

image

Stopwatch works in simulator:

image

🚀

nelsonic commented 1 year ago

@iteles thanks for reminding me that I need to fire up the iPhone 8 to test this. 👌