【问题标题】:Flutter Podfile and Pods folders not created in ios directoryFlutter Podfile 和 Pods 文件夹未在 ios 目录中创建
【发布时间】:2019-01-07 01:00:06
【问题描述】:

使用向导从 Android Studio 创建了一个新的 Flutter 项目。

新创建的项目文件夹在 ios 目录下没有任何 Pods 文件夹或 podfile。

This Flutter.io 页面状态(强调我的):

虽然你的 Flutter 项目的 iOS 文件夹中有一个 Podfile, 仅当您添加所需的本机依赖项时才使用它 每个平台的集成。

我的 ios 目录中根本没有 podfile。

我在这里的另一个问题中发现this comment 建议在 ios 模拟器上运行项目会生成文件,但在 sim 和设备上运行项目都不会为我创建任何 podfile。

我错过了新的颤振项目创建的 ios 方面的一些步骤吗?如果没有 podfile,我无法添加特定于 ios 的依赖项。

flutter doctor的输出:

[✓] Flutter (Channel beta, v0.5.1, on Mac OS X 10.12.6 16G1408, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.2)
[✓] Android Studio (version 3.1)
[!] VS Code (version 1.25.1)
[✓] Connected devices (1 available)

【问题讨论】:

    标签: ios flutter


    【解决方案1】:

    这是我通常做的:

    1. 进入ios文件夹
    2. 删除Podfile.lock文件
    3. rm -rf Pods
    4. pod cache clean --all
    5. pod deintegrate
    6. pod setup
    7. pod install

    你可能也想做

    pod repo update

    【讨论】:

    • 嗯,也没有Podfile.lock 文件...!
    【解决方案2】:

    运行 flutter build ios 后,PodfilePodfile.lock 将在 ios 目录中为您创建。

    按照deploy steps 官方文档中的步骤操作。

    【讨论】:

    • 只有在 ios 目录下没有 Podfile 时才会创建 Podfile。
    • 我曾经确实这样做过,但我刚刚在 1.17.3 中生成了一个项目,运行了 flutter build ios --release --no-codesign 并且什么都没有......没有生成 Podfile
    • 好的,我知道了,我必须包含一个带有原生对应物的 Flutter 插件(例如:webview_flutter: ^0.3.21)。现在它生成 Podfile
    • @ncuillery 你能详细解释一下我们应该包括什么以及我们应该在哪里包括它
    • 真的只要在你的project.yaml的依赖列表中添加webview_flutter: ^1.0.7,然后运行build命令。请注意,我选择了 webview_flutter 作为示例,但是任何具有本地对应的 dep 都可以完成这项工作。
    【解决方案3】:

    最近,我遇到了同样的问题。即使我在 pubspec.yaml 文件中添加依赖包,也没有创建 Podfile。最后,我必须手动在 ios 目录中添加一个 Pod 文件并发出 'pod deintegrate'、'pod setup' 和 'pod install'。

    这是我的 podfile。你可以试试:

    # Uncomment this line to define a global platform for your project
    platform :ios, '9.0'
    
    # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
    ENV['COCOAPODS_DISABLE_STATS'] = 'true'
    
    pod 'Firebase/Core'
    pod 'FBSDKLoginKit' #optional
    pod 'GoogleAnalytics'
    
    def parse_KV_file(file, separator='=')
      file_abs_path = File.expand_path(file)
      if !File.exists? file_abs_path
        return [];
      end
      pods_ary = []
      skip_line_start_symbols = ["#", "/"]
      File.foreach(file_abs_path) { |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)
            pods_ary.push({:name => podname, :path => podpath});
          else
            puts "Invalid plugin specification: #{line}"
          end
      }
      return pods_ary
    end
    
    target 'Runner' do
      # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
      # referring to absolute paths on developers' machines.
      use_frameworks! 
      system('rm -rf .symlinks')
      system('mkdir -p .symlinks/plugins')
    
      # Flutter Pods
      generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
      if generated_xcode_build_settings.empty?
        puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
      end
      generated_xcode_build_settings.map { |p|
        if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
          symlink = File.join('.symlinks', 'flutter')
          File.symlink(File.dirname(p[:path]), symlink)
          pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
        end
      }
    
      # Plugin Pods
      plugin_pods = parse_KV_file('../.flutter-plugins')
      plugin_pods.map { |p|
        symlink = File.join('.symlinks', 'plugins', p[:name])
        File.symlink(p[:path], symlink)
        pod p[:name], :path => File.join(symlink, 'ios')
      }
    end
    
    
    #pre_install do |installer|
      # workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
     # Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
    #end
    
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['ENABLE_BITCODE'] = 'NO'
          config.build_settings['SWIFT_VERSION'] = '4.2'
        end
    
        # Peter aded on 8 Oct 2018
        # workaround for https://github.com/CocoaPods/CocoaPods/issues/7463
        #target.headers_build_phase.files.each do |file|
         # file.settings = { 'ATTRIBUTES' => ['Public'] }
        #end
    
      end
    end
    

    另外,我尝试使用 Vcode 创建一个新的 Flutter 项目。在 pubspec.yaml 文件中添加包,保存并自动创建 podfile,

    使用 Vcode 创建一个新的 Flutter 项目

    1. 开始 VS 代码
    2. 调用视图>命令面板...
    3. 输入“flutter”,然后选择“Flutter: New Project”操作
    4. 输入项目名称(例如 myapp),然后按 Enter
    5. 指定放置项目的位置,然后按蓝色的OK 按钮
    6. 等待项目创建继续,main.dart 文件 出现
    7. 在 pubspec.yaml 文件中添加一个包并保存。
    8. 应该创建 podfile。

    【讨论】:

    • 另外,我尝试使用 Vcode 创建一个新的 Flutter 项目。在 pubspec.yaml 文件中添加包,保存并自动创建 podfile,使用 Vcode 创建一个新的 Flutter 项目 -Start VS Code -Invoke View>Command Palette... -Type 'flutter',然后选择 'Flutter: New Project' 操作- 输入项目名称(例如myapp),回车 - 指定放置项目的位置,并按下蓝色的OK按钮 - 等待项目创建继续,出现main.dart文件 - 在中添加包pubspec.yaml 文件并保存。 - 应该创建 podfile。
    • 是的,如果您不向 pubspec 添加任何包,则似乎不会创建 podfile。如果您需要将仅限 iOS 的 pod 添加到项目中,这是一种奇怪的行为。至少应该在我认为的文档中提到它。
    • 我昨天尝试了这些步骤,但我认为在 VScode 中执行此操作就像在命令行中使用 flutter create projectname 执行此操作一样,不会创建 pod 文件。
    【解决方案4】:

    我建议你直接去你的 Flutter Package 做 flutter create . 它会自动创建所有丢失的文件,甚至 Podfile。 我在我的项目中使用过这个命令,效果很好。

    【讨论】:

    • 这绝对是人们应该尝试的。这就像魔术!
    【解决方案5】:
    flutter:
          plugin:
            platforms:
              ios:
                pluginClass: AppDelegate
    

    您需要将以上行添加到 pubspec.yaml 中,然后 pub 会在 ios 文件夹中自动生成 Podfile

    【讨论】:

    • 我在 Android Studio(2021 年 1 月)上生成的一个项目上尝试了这个,并且成功。我觉得奇怪的是分数是 0
    • 该文件应该在何时何地创建,请问?直接在iOS目录下,还是?而pub get 并没有这样做,至少对我来说......
    • 这为我生成了 Podfile 文件...将其添加到根 ios 文件夹中。请注意,Podfile 看起来不像使用 pod init 时创建的基本 Podfile
    【解决方案6】:

    我在 Flutter 工具创建的 ios 文件夹中找到了 Podfile 和 Podfile.lock,但项目的 Xcode 视图中缺少 Pods.xcodeproj。 我打开一个命令行终端,进入 ios 文件夹并运行 吊舱安装 这足以让我修复项目。

    【讨论】:

      【解决方案7】:

      我刚刚创建了一个新项目,在ios/ 目录中没有看到Podfile。我需要Podfile 来设置Firebase 集成。虽然@ncuillery在评论中已经指出了,但我想我应该添加一个答案,因为很容易错过评论!

      您所要做的就是向pubspec.yaml 文件添加一个依赖项:

      dependencies:
        flutter:
          sdk: flutter
      
        cupertino_icons: ^1.0.2
      
        firebase_auth: ^1.0.2 # <--- add this line (doesn't have to be firebase_auth)
      

      运行pub get 以获取依赖项。如果命令成功存在,您应该在终端中看到:

      进程以退出代码 0 结束

      Podfile应该在运行具有列出的依赖项的命令后创建,然后可以在 ios/Podfile 找到。

      【讨论】:

      • 这对我不起作用“进程以退出代码 0 完成”
      【解决方案8】:

      对我来说,没有创建 ios 文件夹中的 podfile 的原因是我在 pubspec 中将它作为一个模块:

        module:
          androidX: true
          androidPackage: ******
          iosBundleIdentifier: ******
      

      从 pubspec 中删除这部分使得 Flutter 在运行 pub get 时再次生成 podfile。我将它用作模块,但也希望能够独立运行项目,因此我在运行 pub get 后再次将模块位放回原处。

      【讨论】:

        【解决方案9】:

        对我来说最简单的方法就是做:

        pod init
        

        在终端中

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-07-12
          • 2019-02-25
          • 2013-08-06
          • 2016-01-11
          • 2011-05-05
          • 1970-01-01
          • 1970-01-01
          • 2019-08-29
          相关资源
          最近更新 更多