This document explains how to configure your iOS project to use SwiftyTesseract version 4.0.1 with the tesseract_ocr Flutter plugin when integrating via CocoaPods.
SwiftyTesseract versions 4.0.0 and above dropped support for CocoaPods in favor of Swift Package Manager. However, to allow users of this plugin to utilize the features of 4.0.1 while still using CocoaPods, a custom podspec setup has been created within this plugin.
This custom setup involves:
tesseract_ocr.podspecnow depends on a custom pod namedSwiftyTesseract401.- A local podspec,
SwiftyTesseract401.podspec, is provided within the plugin'siosdirectory. This podspec points directly to the SwiftyTesseract 4.0.1 tag on GitHub. - SwiftyTesseract 4.0.1 itself depends on
libtesseract, which is also not available on CocoaPods. A local podspec,libtesseract.podspec, is provided to make thelibtesseract.xcframeworkavailable via CocoaPods.
Important: For this custom CocoaPods setup to work, you must manually obtain and include the libtesseract.xcframework in your project.
-
Download
libtesseract.xcframework: Download thelibtesseract.xcframework.zipfile for version0.2.0from the libtesseract GitHub Releases page. -
Extract and Place: Unzip the downloaded file and place the resulting
libtesseract.xcframeworkfolder directly into your Flutter app'siosdirectory (the same directory where your mainPodfileis located).Your
iosdirectory structure should look something like this:your_flutter_app/ios/ ├── Runner.xcodeproj ├── Runner.xcworkspace ├── Podfile <-- Your main Podfile ├── libtesseract.xcframework <-- Place the extracted folder here └── ... (other iOS files)
In your Flutter app's ios/Podfile, you need to reference the custom SwiftyTesseract401.podspec and libtesseract.podspec provided by the tesseract_ocr plugin using the :path option.
Locate your target 'Runner' block and add the following lines:
# Your main Podfile in your Flutter app (e.g., your_flutter_app/ios/Podfile)
# ... other Podfile content ...
target 'Runner' do
use_frameworks!
use_modular_headers!
# Reference the tesseract_ocr plugin's pod
# This line should already be here if you added the plugin via pubspec.yaml
pod 'tesseract_ocr', :path => '../.symlinks/plugins/tesseract_ocr/'
# Add the custom SwiftyTesseract401 and libtesseract pods
# These paths are relative from YOUR app's ios directory to the plugin's ios directory
# Adjust the '../../.symlinks/plugins/tesseract_ocr/ios' path if necessary
pod 'SwiftyTesseract401', :path => '../../.symlinks/plugins/tesseract_ocr/ios'
pod 'libtesseract', :path => '../../.symlinks/plugins/tesseract_ocr/ios'
# flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) # Keep this line
end
# ... other Podfile content (e.g., post_install hook) ...Note: The :path value ../../.symlinks/plugins/tesseract_ocr/ios is the standard path from your app's ios directory to a plugin's ios directory when using Flutter. If your project structure is different, you may need to adjust this path.
After modifying your Podfile, navigate to your ios directory in the terminal and run pod install:
cd your_flutter_app/ios
pod installCocoaPods should now be able to find and install the SwiftyTesseract401 and libtesseract pods using the provided custom podspecs and the libtesseract.xcframework located in your ios directory.
libtesseract.xcframeworkDistribution: Since thelibtesseract.podspecreferences the xcframework by a local file path, anyone who clones your repository and builds the app will need to also havelibtesseract.xcframeworkin the correct location (your_flutter_app/ios/libtesseract.xcframework). You may need to consider adding this xcframework to your repository (potentially using Git LFS if it's large) or providing separate instructions for obtaining it.- Plugin Users: If you are the author of the
tesseract_ocrplugin, users integrating your plugin into their apps via CocoaPods will need to follow these steps in their app'siosdirectory. The custom podspecs are now part of your plugin's distribution, but thelibtesseract.xcframeworkitself is not automatically included by CocoaPods when using:path.