Official document: https://docs.flutter.dev/development/add-to-app/ios/project-setup#option-a---embed-with-cocoapods-and-the-flutter-sdk
Complete official sample code: https://github.com/flutter/samples/tree/main/add_to_app/books
1. From the terminal, go to your current iOS native project, for eg: /Users/.../reproduce_issue_ios_native_addtoapp_optionA/
2. Group all current files/directories into a new directory (named MyApp
for eg)
3. Create flutter module and go to module directory
flutter create --template module my_flutter
cd my_flutter
Make sure your existing application and the Flutter module are in sibling directories
➜ reproduce_issue_ios_native_addtoapp_optionA tree -L 2
.
├── MyApp
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Pods
│ ├── reproduce_issue_ios_native_addtoapp_optionA
│ ├── reproduce_issue_ios_native_addtoapp_optionA.xcodeproj
│ └── reproduce_issue_ios_native_addtoapp_optionA.xcworkspace
└── my_flutter
├── README.md
├── analysis_options.yaml
├── lib
├── my_flutter.iml
├── my_flutter_android.iml
├── pubspec.lock
├── pubspec.yaml
└── test
9 directories, 8 files
4. init Podfile and edit it
cd MyApp
pod init
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
flutter_application_path = '../my_flutter'
load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')
target 'reproduce_issue_ios_native_addtoapp_optionA' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for reproduce_issue_ios_native_addtoapp_optionA
install_all_flutter_pods(flutter_application_path)
end
post_install do |installer|
flutter_post_install(installer) if defined?(flutter_post_install)
end
5. Run pod install in MyApp (Done)
pod install
Result:
➜ MyApp pod install
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin22/rbconfig.rb:21: warning: Insecure world writable dir /Users/huynq/Documents/GitHub/flutter/bin in PATH, mode 040777
Analyzing dependencies
Downloading dependencies
Installing Flutter (1.0.0)
Installing FlutterPluginRegistrant (0.0.1)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `reproduce_issue_ios_native_addtoapp_optionA.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
[!] Automatically assigning platform `iOS` with version `16.1` on target `reproduce_issue_ios_native_addtoapp_optionA` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.