Skip to content

Must run flutter clean before building when iOS app has watch extension, Failed to extract arm64 for .../PlugIns/WatchApp.appex/Frameworks #60351

Description

@Henrik-glt

Problem

Must run flutter clean between every build (run/debug) when app includes a WKExtension.
Seems like flutter uses the same "active architecture" for Apple Watch as it does for iPhone.
That in turn causes flutter to try extract the wrong architecture when building app for debug/run on device.

Steps to Reproduce

  1. Run flutter create bug.
  2. Add a watch extension (https://flutter.dev/docs/development/platform-integration/apple-watch
  3. Add a pod for your watch extension target (I use pod 'EFQRCode/watchOS', '~> 5.1.6', but any pod will do)
  4. Run your app on an iPhone or iOS simulator.
  5. Stop debug/run session after app has installed and launched on device/simulator.
  6. Again, run your app on an iPhone or iOS simulator.

Expected results:
App launches.

Actual results:
Build error.

Logs
Flutter.framework/_CodeSignature/CodeResources
               sent 98388907 bytes  received 120 bytes  65592684.67 bytes/sec
               total size is 98376483  speedup is 1.00
               PATH/TO/BUILD/Runner.app/Frameworks/App.framework/App: signed bundle with Mach-O universal (x86_64 arm64) [io.flutter.flutter.app]
               PATH/TO/BUILD/Runner.app/Frameworks/Flutter.framework/Flutter: replacing existing signature
               PATH/TO/BUILD/Runner.app/Frameworks/Flutter.framework/Flutter: signed bundle with Mach-O universal (armv7 x86_64 arm64) [io.flutter.flutter]
               fatal error: lipo: -extract arm64 specified but fat file: PATH/TO/BUILD/Runner.app/Watch/APP_NAME.app/PlugIns/WatchApp_staging Extension.appex/Frameworks/EFQRCode.framework/EFQRCode does not contain that architecture
               Failed to extract arm64 for PATH/TO/BUILD/Runner.app/Watch/APP_NAME.app/PlugIns/WatchApp_staging Extension.appex/Frameworks/EFQRCode.framework/EFQRCode. Running lipo -info:
               Architectures in the fat file: PATH/TO/BUILD/Runner.app/Watch/APP_NAME.app/PlugIns/WatchApp_staging Extension.appex/Frameworks/EFQRCode.framework/EFQRCode are: armv7k arm64_32
               Command PhaseScriptExecution failed with a nonzero exit code
               note: Using new build system
               note: Building targets in parallel
               note: Planning build
               note: Constructing build description
[✓] Flutter (Channel beta, 1.19.0-4.2.pre, on Mac OS X 10.15.5 19F101, locale en-NO)
    • Flutter version 1.19.0-4.2.pre at /Users/ME/Documents/Development/FLUTTER_SDK/flutter
    • Framework revision 9b9b543d92 (4 days ago), 2020-06-22 12:19:28 -0700
    • Engine revision 9a28c3bcf4
    • Dart version 2.9.0 (build 2.9.0-14.1.beta)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/ME/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.9.3

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

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 46.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

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

[✓] Connected device (4 available)

Activity

  1. added
    platform-iosiOS applications specifically
    c: fatal crashCrashes that terminate the process
    t: xcode"xcodebuild" on iOS and general Xcode project management
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jun 26, 2020
  2. changed the title [-]Must run flutter clean before building when iOS app has WKExtension[/-] [+]Must run flutter clean before building when iOS app has watch extension, Failed to extract arm64 for .../PlugIns/WatchApp.appex/Frameworks[/+] on Jul 14, 2020
  3. jmagman commented on Jul 14, 2020

    @jmagman
    Member

    Can we get your ios/Podfile?

  4. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 14, 2020
  5. jmagman commented on Aug 4, 2020

    @jmagman
    Member

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!

    Thanks for your contribution.

  6. Henrik-glt commented on Aug 25, 2020

    @Henrik-glt
    Author

    @jmagman From regenerated and updated Podfile (Flutter version 1.20.2).
    The problem still persists.
    The workaround I currently use is to comment out lines 219 & 227 in packages/flutter_tools/bin/xcode_backend.sh to avoid "crashing" the build.

    source 'https://cdn.cocoapods.org/'
    
    # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
    ENV['COCOAPODS_DISABLE_STATS'] = 'true'
    
    ios_deployment_target = '11.0'
    watchos_deployment_target = '5.0'
    
    project 'Runner', {
      'Debug' => :debug,
      'Release' => :release,
      'Profile' => :release,
    }
    
    def parse_KV_file(file, separator='=')
      file_abs_path = File.expand_path(file)
      if !File.exists? file_abs_path
        return [];
      end
      generated_key_values = {}
      skip_line_start_symbols = ["#", "/"]
      File.foreach(file_abs_path) do |line|
        next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
        plugin = line.split(pattern=separator)
        if plugin.length == 2
          podname = plugin[0].strip()
          path = plugin[1].strip()
          podpath = File.expand_path("#{path}", file_abs_path)
          generated_key_values[podname] = podpath
        else
          puts "Invalid plugin specification: #{line}"
        end
      end
      generated_key_values
    end
    
    abstract_target 'AbsPROJECT_NAME' do
      platform :ios, ios_deployment_target
    
      use_frameworks!
      use_modular_headers!
    
      pod 'GoogleIDFASupport'
      pod 'GoogleTagManager'
      pod 'Firebase'
      pod 'FirebaseInAppMessaging'
      pod 'Firebase/Analytics'
    
      target 'Runner'
      target 'Runner_staging'
    
    
      # Flutter Pod
    
      copied_flutter_dir = File.join(__dir__, 'Flutter')
      copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
      copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
      unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
        # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
        # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
        # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
    
        generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
        unless File.exist?(generated_xcode_build_settings_path)
          raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
        end
        generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
        cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
    
        unless File.exist?(copied_framework_path)
          FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
        end
        unless File.exist?(copied_podspec_path)
          FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
        end
      end
    
      # Keep pod path relative so it can be checked into Podfile.lock.
      pod 'Flutter', :path => 'Flutter'
    
      # Plugin Pods
    
      # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
      # referring to absolute paths on developers' machines.
      system('rm -rf .symlinks')
      system('mkdir -p .symlinks/plugins')
      plugin_pods = parse_KV_file('../.flutter-plugins')
      plugin_pods.each do |name, path|
        symlink = File.join('.symlinks', 'plugins', name)
        File.symlink(path, symlink)
        pod name, :path => File.join(symlink, 'ios')
      end
    end
    
    abstract_target 'AbsPROJECT_NAMEWatch' do
      platform :watchos, watchos_deployment_target
      # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
      use_frameworks!
      use_modular_headers!
      # Pods for Watch App
    
      pod 'EFQRCode/watchOS', '~> 5.1.6'
    
      target 'WatchApp Extension'
      target 'WatchApp_staging Extension'
    end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['ENABLE_BITCODE'] = 'YES'
        end
      end
    end
    `
    
  7. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 25, 2020
  8. jmagman commented on Aug 28, 2020

    @jmagman
    Member

    Reverted at #64829

  9. github-actions commented on Aug 12, 2021

    @github-actions

    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.

  10. locked as resolved and limited conversation to collaborators on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: fatal crashCrashes that terminate the processplatform-iosiOS applications specificallyt: xcode"xcodebuild" on iOS and general Xcode project managementtoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions