33

Created a new flutter project from Android Studio using the wizard.

Newly created project folder does not have any of the Pods folders or podfile in the ios directory.

This Flutter.io page states (emphasis mine):

While there is a Podfile in the iOS folder in your Flutter project, only use this if you are adding native dependencies needed for per-platform integration.

There is no podfile at all in my ios directory.

I found this comment in a different question here suggesting running the project on the ios simulator would generate the file but running the project on the sim and device both do not result in any podfile creation for me.

Is there some step in the ios side of the new flutter project creation that I missed? There's no way for me to add ios-specific dependencies without the podfile.

Output of 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)
aaronfg
  • 474
  • 1
  • 5
  • 12

14 Answers14

50

Here is what I usually do:

  1. go into ios folder
  2. delete the Podfile.lock file
  3. rm -rf Pods
  4. pod cache clean --all
  5. pod deintegrate
  6. pod setup
  7. pod install

You may also want to do

pod repo update

Quintin Willison
  • 610
  • 6
  • 13
LiveRock
  • 1,419
  • 2
  • 17
  • 27
37

Once you run flutter build ios a Podfile and Podfile.lock will be created for you in the ios directory.

Follow the steps in the deploy steps official documentation.

Pablo Rocha
  • 530
  • 4
  • 9
  • It will only create a Podfile if there is no Podfile existing in ios directory. – Mantoska Oct 08 '19 at 19:52
  • 1
    I used to do that indeed but I've just generated a project in 1.17.3, ran `flutter build ios --release --no-codesign` and nothing... no Podfile generated – ncuillery Jun 12 '20 at 17:24
  • 4
    Ok I got it, I had to include a Flutter plugin with a native counterpart (like: webview_flutter: ^0.3.21). Now it generates the Podfile – ncuillery Jun 12 '20 at 17:33
  • @ncuillery can you please explain it in detail regarding what we should include and where are we supposed to include it – desu sai venkat Feb 04 '21 at 08:17
  • 2
    Really just add `webview_flutter: ^1.0.7` in the list of dependencies in your project.yaml, then run the build command. Note that I picked `webview_flutter` as an example but any dep with a native counterpart would do the job. – ncuillery Feb 05 '21 at 20:50
6

I will suggest simply go to your Flutter Package and do flutter create . It will automatically create all the missing files and even Podfile. I have used this command in my project and it is fruitful.

Yash Adulkar
  • 513
  • 5
  • 2
4

Recently, I encountered the same problem. No Podfile created even when I add dependency packages in the pubspec.yaml file. In the end, I have to manually add a Pod file in the ios directory and issue 'pod deintegrate', 'pod setup' and 'pod install'.

Here is my podfile. You can try it:

# 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

Also, I tried using Vcode to create a new Flutter project. Add package in pubspec.yaml file, save and the podfile was automatically created,

Create a new Flutter project using Vcode

  1. Start VS Code
  2. Invoke View>Command Palette…
  3. Type ‘flutter’, and select the ‘Flutter: New Project’ action
  4. Enter a project name (e.g. myapp), and press Enter
  5. Specify a location to place the project, and press the blue OK button
  6. Wait for the project creation to continue, and the main.dart file to appear
  7. Add a package in the pubspec.yaml file and save it.
  8. The podfile should be created.
LiveRock
  • 1,419
  • 2
  • 17
  • 27
  • Also, I tried using Vcode to create a new Flutter project. Add package in pubspec.yaml file, save and the podfile was automatically created, Create a new Flutter project using Vcode -Start VS Code -Invoke View>Command Palette… -Type ‘flutter’, and select the ‘Flutter: New Project’ action -Enter a project name (e.g. myapp), and press Enter -Specify a location to place the project, and press the blue OK button -Wait for the project creation to continue, and the main.dart file to appear -Add a package in the pubspec.yaml file and save it. -The podfile should be created. – LiveRock Nov 27 '18 at 03:34
  • 1
    yes it seems if you don't add any packages to the pubspec the podfile won't be created. That's weird behavior if you need to add iOS-only pods to a project. At the very least it should be mentioned in the docs I'd think. – aaronfg Nov 29 '18 at 20:31
  • I tried the steps yesterday but I think doing it in VScode is like doing it from the command line with `flutter create projectname` Does not create a pod file. – Ride Sun Mar 04 '20 at 20:29
4

[Windows/Android studio] To create podfile all you need is to run pod init in ios folder in your flutter project, If you are using window and not yet installed CocoPods, then you need to install ruby which is prerequires to install CocoPods (pod command) which in turn is used to create podfile

Once they are installed, navigate to ios folder in your flutter project and run the following command to create init podfile in ios folder:

pod init
Husam Alhwadi
  • 383
  • 3
  • 11
3
flutter:
      plugin:
        platforms:
          ios:
            pluginClass: AppDelegate

You need to add the above lines to the pubspec.yaml and then the pub would automatically generate the Podfile inside the ios folder.

desu sai venkat
  • 275
  • 3
  • 10
  • I tried this on a project generated on Android Studio (Jan 2021) and this works. I find it odd the the score was 0 – silencer07 Feb 07 '21 at 13:43
  • Exactly where and when is the file supposed to be created, plz? Immediately under the iOS directory, or? And `pub get` did not do it, for me at least... – Karolina Hagegård Apr 04 '21 at 09:33
  • This generated the Podfile file for me... Added it in the root ios folder. Note that the Podfile doesn't look like the basic Podfile created if you use pod init – Jason Allshorn May 31 '21 at 01:33
3

For me the reason the podfile in the ios folder was not being created was the fact that I had made it a module in the pubspec:

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

Removing this part from the pubspec made flutter generate the podfile again when running pub get. I'm using it as a module but like to be able to run the project standalone as well, so for that reason I put the module bit back in again after running a pub get.

1

I had just created a new project and didn't see the Podfile in the ios/ directory. I needed the Podfile in order to setup Firebase integration. Although it has been pointed out in a comment by @ncuillery, I thought I should add an answer for the reason that a comment may be missed very easily!

All you have to do is add a dependency to the pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2

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

Run pub get to get the dependencies. If the command exists successfully, in the terminal you should see:

Process finished with exit code 0

The Podfile should have been created after running the command with the dependency listed and can then be found at ios/Podfile.

gmdev
  • 2,725
  • 2
  • 13
  • 28
1

I found the Podfile and Podfile.lock in the ios folder as created by the Flutter tools, yet Pods.xcodeproj was missing in the Xcode view of the project. I opened a command-line terminal, went into ios folder and ran pod install that was enough for me to fix the project.

diegusz
  • 11
  • 3
1

Adding default Podfile content if that can be helpful for someone, else if needed proper solution resolved this issue inside other question

# 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__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end
CodingEra
  • 1,313
  • 10
  • 20
0

you can use this command to find this issue https://docs.flutter.dev/development/add-to-app/ios/project-setup. it's worked for me.

flutter build ios-framework --output=some/path/MyApp/Flutter/

use pwd command to get the current directory

replace --output=some/path/MyApp/Flutter/ by --output=currentdirectory/directoryapp/ios/Flutter

so

flutter build ios-framework --output=currentdirectory/directoryapp/ios/Flutter

for me it was:

flutter build ios-framework --output=/Users/ilimigroup/StudioProjects/Telia-ios/telia/ios/Flutter

after that, you can run in xcode

DIRKK
  • 3
  • 3
0

If you are on window please try this for pod file install in android studion npx pod install

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 15 '22 at 05:33
0

Step 1 : Open Runner.xcodeproj in X Code

Step 2 : Select Runner on Navigator panel

Step 3 : Select Runner under TARGET Panel

Step 4 : Select Signing & Capabilities on Top Panel

Step 5 : Select All or Desire Tab( Debug, Release or Profile)

Step 6 : Select Your Team

Reference Screenshot

ZEREN ZOU
  • 21
  • 3
-3

Easiest method that worked for me is just do:

pod init

in the terminal

Programmer12
  • 89
  • 1
  • 8