在项目“Runner.xcodeproj”中找不到名为“RunnerTests”的目标。

18

我在我的惠普笔记本上安装了Hackintosh。我试图在iOS模拟器上运行Flutter应用程序,但是它给了我这个错误:

[!] Unable to find a target named `RunnerTests` in project `Runner.xcodeproj`, did find `Runner`.

这是 Podfile 文件:

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

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

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

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
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

我复制了错误信息并在谷歌上搜索了一下。我发现了类似的问题,但它们的解决方案对我没有用。

5个回答

50

我也是Flutter的新手,不知道为什么会出现这个错误。但是如果你打开Podfile文件,你会在最前面的几行找到以下内容:

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

所以,并没有名为“RunnerTests”的项目,我所做的是在同一文件中注释该引用的使用,如下所示:

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
#   target 'RunnerTests' do
#     inherit! :search_paths
#   end
end

不确定为什么在那里引用了目标,但它可以工作 :)


1
好的,已经处理好了,谢谢。 - undefined

3

注意:我有一台M1 Mac,所以我必须使用arch -x86_64 pod install命令才能运行pod install。

我遇到了同样的问题,解决方法是删除我的ios文件夹,然后简单地使用以下命令。

flutter create --platform ios .
cd ios
arch -x86_64 pod install | For mac m1 users
pod install | for other users

非常感谢。但不幸的是,它没有起作用。当我在笔记本电脑上从头开始实现代码时,它可以工作。但如果我从GitHub克隆它,它就不能工作。 - Haya Hesham Abdel-azim

1
只需删除现有项目中的所有IOS文件夹,然后创建一个新的Flutter项目,将新项目中的IOS文件夹复制到旧项目中即可。

1
新的Flutter版本似乎需要一个RunnerTests配置文件。
只需创建一个新的Flutter项目,然后比较'ios/Runner.xcodeproj/project.pbxproj'文件即可。

1

当你在 Xcode 中尝试构建或运行指定项目中不存在的目标时,通常会出现“无法在项目 Runner.xcodeproj 中找到名为 Runner 的目标”的错误消息。这似乎是项目中的问题。

你可以通过从 Flutter 项目中删除 iOS 文件夹并创建一个新的 iOS 文件夹来解决此问题。

flutter create --platform ios .

请确保在 info.plist 中重新配置所有内容或者您对本地文件所做的任何更改,因为该命令将创建一个新文件夹。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接