rickmcrick
rickmcrick

Reputation: 23

Flutter iOS build error with watchOS target in VSCode but not in Xcode

I have a Flutter app and added a native watchOS target to it. Everything works fine from Xcode: I can build both the iOS app and the watchOS app as targets, and everything functions as intended. When I build the iOS app, it includes the watchOS app, and I can install the watch app via the iPhone system Watch app.

However, when I try to build the iOS app from VSCode via the flutter run command, the build fails with the following error message:

Launching lib/main_development.dart on iPhone in debug mode...
Automatically signing iOS for device deployment using specified development team in Xcode project: 
Xcode build done.                                           58,7s
Failed to build iOS app
Could not build the precompiled application for the device.
Swift Compiler Error (Xcode): No such module 'CryptoSwift'
PathToFile/File.swift:7:7

Error launching application on iPhone.

" The CryptoSwift module is a pod only for my watchOS target. The iOS and watchOS targets have different pods. The watch app is included in the iOS build, so it makes sense that the code gets compiled, but it works in Xcode, so why does it fail in VSCode?

The error occurs with every dependency in my watch target. I tried removing the CryptoSwift package to see if it would work, but then it failed because it couldn't find the Alamofire package. So, it seems to have problems with all dependencies in my watch target.

Maybe there's an issue with my Podfile? I'm not sure why it works in Xcode but not in VSCode. Does anyone have any ideas on how to fix this issue? I've already spent a lot of time trying to solve it.

The Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}


target 'Watch App' do
  platform :watchos, '3.0'
  use_frameworks!
  use_modular_headers!
  
  pod 'Alamofire', '~> 5.9.0'
  pod 'CryptoSwift', '~> 1.4.0'
  pod 'SwiftLint'
end

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end
  
  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!
  
  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
  target 'RunnerTests' do
    inherit! :search_paths
  end
  
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      flutter_additional_ios_build_settings(target)
      
      # Start of the permission_handler configuration
      target.build_configurations.each do |config|
        
      end
      
    end
  end
end

Thanks for any help you can provide!

Upvotes: 0

Views: 143

Answers (1)

blokvin
blokvin

Reputation: 34

You can only build apps for iPhone in Xcode, use VScode/Android Studio to build apps with the Android operating system.

Upvotes: 0

Related Questions