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

Apple Watch target detection does not work for new Apple Watch targets #99031

Closed
Rexios80 opened this issue Feb 23, 2022 · 4 comments
Closed
Labels
found in release: 2.10 Found to occur in 2.10 found in release: 2.11 Found to occur in 2.11 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-ios iOS applications specifically r: duplicate Issue is closed as a duplicate of an existing issue t: xcode "xcodebuild" on iOS and general Xcode project management tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@Rexios80
Copy link
Member

Rexios80 commented Feb 23, 2022

NOTE

This IS NOT an issue regarding Flutter supporting Apple Watch targets in general. I created #97721 already, but that one was closed as a duplicate. This is NOT a duplicate issue (unless someone beat me to it). Apple Watch targets created by older versions of Xcode used to build fine with Flutter.

Steps to Reproduce

  1. Create an iOS flutter project using flutter create
  2. Add an Apple Watch target
  3. Fix miscellaneous unrelated issues with the generated watch target (thanks Xcode)
  4. Run flutter build ios

Expected results:

Flutter detects that the project contains an Apple Watch target and adjusts the build settings accordingly. The following line should appear in the build log:

Watch companion app found.

Successful build

Actual results:

Flutter cannot detect that new Apple Watch targets created by Xcode exist because the structure of Apple Watch targets changed

Build failure

Code sample

https://github.com/Rexios80/flutter_apple_watch_build_failure

Logs
# The output was too long for this issue. Here are the relevant error lines:
[   +4 ms] Failed to build iOS app
[        ] Error output from Xcode build:

[        ]     objc[78128]: Class AMSupportURLConnectionDelegate is implemented
in both
               /usr/lib/libamsupport.dylib (0x2186c7678) and

/Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versi
               ons/A/MobileDevice (0x108acc2c8). One of the two will be used.
Which one is
               undefined.
               objc[78128]: Class AMSupportURLSession is implemented in both
               /usr/lib/libamsupport.dylib (0x2186c76c8) and

/Library/Apple/System/Library/PrivateFrameworks/MobileDevice.framework/Versi
               ons/A/MobileDevice (0x108acc318). One of the two will be used.
Which one is
               undefined.
               ** BUILD FAILED **
           
           
[        ] Xcode's output:

[        ]     Command line invocation:
                   /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
                   -configuration Release VERBOSE_SCRIPT_LOGGING=YES -workspace
                   Runner.xcworkspace -scheme Runner
                   BUILD_DIR=/Users/rexios/repos/apple_watch_test/build/ios -sdk
iphoneos
                   -destination generic/platform=iOS

SCRIPT_OUTPUT_STREAM_FILE=/var/folders/yc/vsrv7_gd6mb03mbn7xbd_qdm0000gn

/T/flutter_tools.wYAc23/flutter_ios_build_temp_dirrL1ONt/pipe_to_stdout
                   -resultBundlePath

/var/folders/yc/vsrv7_gd6mb03mbn7xbd_qdm0000gn/T/flutter_tools.wYAc23/fl
                   utter_ios_build_temp_dirrL1ONt/temporary_xcresult_bundle
                   -resultBundleVersion 3 FLUTTER_SUPPRESS_ANALYTICS=true
                   COMPILER_INDEX_STORE_ENABLE=NO
           
               User defaults from command line:
                   IDEBuildOperationResultBundlePath =

/var/folders/yc/vsrv7_gd6mb03mbn7xbd_qdm0000gn/T/flutter_tools.wYAc23/fl
                   utter_ios_build_temp_dirrL1ONt/temporary_xcresult_bundle
                   IDEPackageSupportUseBuiltinSCM = YES
                   IDERequestedResultBundleFormatVersion = 3
           
               Build settings from command line:
                   BUILD_DIR = /Users/rexios/repos/apple_watch_test/build/ios
                   COMPILER_INDEX_STORE_ENABLE = NO
                   FLUTTER_SUPPRESS_ANALYTICS = true
                   SCRIPT_OUTPUT_STREAM_FILE =

/var/folders/yc/vsrv7_gd6mb03mbn7xbd_qdm0000gn/T/flutter_tools.wYAc23/fl
                   utter_ios_build_temp_dirrL1ONt/pipe_to_stdout
                   SDKROOT = iphoneos15.2
                   VERBOSE_SCRIPT_LOGGING = YES
           
               Writing result bundle at path:

/var/folders/yc/vsrv7_gd6mb03mbn7xbd_qdm0000gn/T/flutter_tools.wYAc23/flutt
               	er_ios_build_temp_dirrL1ONt/temporary_xcresult_bundle
           
               note: Using new build system
               note: Planning
               Analyze workspace
           
               Create build description
               Build description signature: 4c767b9396f1a415ab21a9412e4215c7
               Build description path:

/Users/rexios/Library/Developer/Xcode/DerivedData/Runner-bizyiytzcpbfagdtkwx

glzekyvye/Build/Intermediates.noindex/XCBuildData/4c767b9396f1a415ab21a9412e
               4215c7-desc.xcbuild
           
               note: Build preparation complete
               note: Building targets in dependency order
               error: unable to resolve product type
               'com.apple.product-type.application.watchapp2' for platform
'iphoneos' (in
               target 'Watch' from project 'Runner')
               error: unable to resolve product type
               'com.apple.product-type.watchkit2-extension' for platform
'iphoneos' (in
               target 'Watch WatchKit Extension' from project 'Runner')
           
               Result bundle written to path:

/var/folders/yc/vsrv7_gd6mb03mbn7xbd_qdm0000gn/T/flutter_tools.wYAc23/flutt
               	er_ios_build_temp_dirrL1ONt/temporary_xcresult_bundle
           
           
[   +2 ms] Error (Xcode): unable to resolve product type
           'com.apple.product-type.application.watchapp2' for platform
'iphoneos'
           
[        ] Error (Xcode): unable to resolve product type
           'com.apple.product-type.watchkit2-extension' for platform 'iphoneos'
           
[   +1 ms] "flutter ios" took 2,868ms.
[   +2 ms] Encountered error while building for device.
[        ] 
           #0      throwToolExit
(package:flutter_tools/src/base/common.dart:10:3)
           #1      _BuildIOSSubCommand.runCommand
           (package:flutter_tools/src/commands/build_ios.dart:279:7)
           <asynchronous suspension>
           #2      FlutterCommand.run.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
           <asynchronous suspension>
           #3      AppContext.run.<anonymous closure>
           (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #4      CommandRunner.runCommand
(package:args/command_runner.dart:209:13)
           <asynchronous suspension>
           #5      FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure>
           (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand
           (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure>
           (package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure>
           (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:94:3)
           <asynchronous suspension>
           
           
[  +48 ms] ensureAnalyticsSent: 47ms
[        ] Running shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1
rexios@Aarons-iMac apple_watch_test % flutter analyze
Analyzing apple_watch_test...                                           
No issues found! (ran in 1.0s)
rexios@Aarons-iMac apple_watch_test % flutter doctor -v
[✓] Flutter (Channel stable, 2.10.1, on macOS 12.2.1 21D62 darwin-arm, locale
    en-US)
    • Flutter version 2.10.1 at /Users/rexios/dev/fvm/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db747aa133 (2 weeks ago), 2022-02-09 13:57:35 -0600
    • Engine revision ab46186b24
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version
    32.0.0-rc1)
    • Android SDK at /Users/rexios/Library/Android/sdk
    • Platform android-32, build-tools 32.0.0-rc1
    • Java binary at: /Users/rexios/.jenv/versions/zulu64-11.0.13/bin/java
    • Java version OpenJDK Runtime Environment Zulu11.52+13-CA (build
      11.0.13+8-LTS)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (3 available)
    • Aaron’s iPhone (mobile) • 00008110-0001459211C2801E • ios            • iOS
      15.3.1 19D52
    • macOS (desktop)         • macos                     • darwin-arm64   •
      macOS 12.2.1 21D62 darwin-arm
    • Chrome (web)            • chrome                    • web-javascript •
      Google Chrome 98.0.4758.109
    ! Error: Aaron’s iPhone is busy: Preparing the watch for development via
      Aaron’s iPhone. Xcode will continue when Aaron’s iPhone is finished. (code
      -10)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Additional Information

Currently, Flutter looks for a WKCompanionAppBundleIdentifier key in plist files, but that key no longer exists in new Apple Watch targets.

The watchkitapp target no longer contains a plist by default, and the watchkitextension target contains a plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSExtension</key>
	<dict>
		<key>NSExtensionAttributes</key>
		<dict>
			<key>WKAppBundleIdentifier</key>
			<string>dev.rexios.appleWatchTest.watchkitapp</string>
		</dict>
		<key>NSExtensionPointIdentifier</key>
		<string>com.apple.watchkit</string>
	</dict>
</dict>
</plist>

This issue can be worked around by adding the following items to the watchkitextension plist:

<key>WKCompanionAppBundleIdentifier</key>
<string>dev.rexios.appleWatchTest</string>

Ideally this workaround would be unnecessary.

Location of the issue in the Flutter repo:

final String? fromPlist = globals.plistParser.getStringValueFromFile(infoFile.path, 'WKCompanionAppBundleIdentifier');

@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Feb 25, 2022
@danagbemava-nc
Copy link
Member

Reproducible on stable and master with the sample in https://github.com/Rexios80/flutter_apple_watch_build_failure.

I can confirm the workaround works. See logs below

logs

build_log.txt
workaround.txt
master.txt

flutter doctor -v
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.2 21D49 darwin-arm, locale en-GB)
    • Flutter version 2.10.2 at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 097d3313d8 (6 days ago), 2022-02-18 19:33:08 -0600
    • Engine revision a83ed0e5e3
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[☠] IntelliJ IDEA Community Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
    • #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
      #1      Utf8Decoder.convert (dart:convert/utf.dart:351:42)
      #2      InputStream.readString (package:archive/src/util/input_stream.dart:207:30)
      #3      new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
      #4      ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
      #5      ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
      #6      IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
      #7      IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
      #8      IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
      #9      IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
      #10     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
      #11     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:109:18)
      #12     _rootRun (dart:async/zone.dart:1426:13)
      #13     _CustomZone.run (dart:async/zone.dart:1328:19)
      #14     _runZoned (dart:async/zone.dart:1861:10)
      #15     runZonedGuarded (dart:async/zone.dart:1849:12)
      #16     runZoned (dart:async/zone.dart:1780:12)
      #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
      #18     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:205:9)
      #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:309:47)
      #20     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:50:48)
      #21     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1320:12)
      <asynchronous suspension>
      #22     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1161:27)
      <asynchronous suspension>
      #23     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
      <asynchronous suspension>
      #25     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
      <asynchronous suspension>
      #26     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #27     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
      <asynchronous suspension>
      #28     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
      <asynchronous suspension>
      #29     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
      <asynchronous suspension>
      #30     main (package:flutter_tools/executable.dart:94:3)
      <asynchronous suspension>


[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (5 available)
    • M2007J20CG (mobile)         • 5dd3be00                  • android-arm64  • Android 11 (API 30)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 12 (API 31) (emulator)
    • Nexus (mobile)              • 00008020-001875E83A38002E • ios            • iOS 15.3 19D50
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 12.2 21D49 darwin-arm
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 98.0.4758.109

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.
[✓] Flutter (Channel master, 2.11.0-0.0.pre.681, on macOS 12.2 21D49 darwin-arm, locale en-GB)
    • Flutter version 2.11.0-0.0.pre.681 at /Users/nexus/dev/sdks/flutters
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a288bd5e3f (2 hours ago), 2022-02-24 23:06:19 -0600
    • Engine revision 1012ac4b5a
    • Dart version 2.17.0 (build 2.17.0-141.0.dev)
    • DevTools version 2.11.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-32, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)

[✓] IntelliJ IDEA Community Edition (version 2021.3)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 213.5744.122

[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (5 available)
    • M2007J20CG (mobile)         • 5dd3be00                  • android-arm64  • Android 11 (API 30)
    • sdk gphone64 arm64 (mobile) • emulator-5554             • android-arm64  • Android 12 (API 31) (emulator)
    • Nexus (mobile)              • 00008020-001875E83A38002E • ios            • iOS 15.3 19D50
    • macOS (desktop)             • macos                     • darwin-arm64   • macOS 12.2 21D49 darwin-arm
    • Chrome (web)                • chrome                    • web-javascript • Google Chrome 98.0.4758.109

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@danagbemava-nc danagbemava-nc added found in release: 2.10 Found to occur in 2.10 found in release: 2.11 Found to occur in 2.11 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-ios iOS applications specifically t: xcode "xcodebuild" on iOS and general Xcode project management tool Affects the "flutter" command-line tool. See also t: labels. and removed in triage Presently being triaged by the triage team labels Feb 25, 2022
@danagbemava-nc
Copy link
Member

/cc @jmagman

@jmagman
Copy link
Member

jmagman commented Feb 25, 2022

Duplicate of #92294.

@jmagman jmagman closed this as completed Feb 25, 2022
@danagbemava-nc danagbemava-nc added the r: duplicate Issue is closed as a duplicate of an existing issue label Feb 28, 2022
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
found in release: 2.10 Found to occur in 2.10 found in release: 2.11 Found to occur in 2.11 has reproducible steps The issue has been confirmed reproducible and is ready to work on platform-ios iOS applications specifically r: duplicate Issue is closed as a duplicate of an existing issue t: xcode "xcodebuild" on iOS and general Xcode project management tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests

3 participants