XCode能否列出所有子项目所用框架?求遍历子项目查框架的脚本
Answer
Absolutely—you can list all frameworks used by subprojects in Xcode, and there are straightforward ways to automate this to track down where sqlite3.dylib is being used. Here are your options:
Manual Inspection (Quick Checks)
For smaller projects, you can verify subprojects one by one:
- Open your Xcode project/workspace.
- For each subproject in the navigator:
- Select its target.
- Switch to the Build Phases tab.
- Look under Link Binary With Libraries—this lists all frameworks linked to the target, including
sqlite3.dylibif present.
- Note: Some frameworks might not appear in the project's
Frameworksgroup but are still linked via build settings, so the Build Phases tab is the most reliable spot.
Automated Scripts (For Larger Projects)
If you have many subprojects, scripts will save you time. Below are two reliable approaches:
Option 1: Ruby Script with Xcodeproj Gem
This script parses Xcode project files directly to check linked frameworks (requires the xcodeproj gem):
- First install the gem:
gem install xcodeproj - Save this as
find_sqlite_framework.rb:require 'xcodeproj' # Traverse all .xcodeproj files in your project directory and subfolders Dir.glob('./**/*.xcodeproj') do |proj_path| begin project = Xcodeproj::Project.open(proj_path) project.targets.each do |target| # Check linked frameworks in the build phase target.frameworks_build_phase.files.each do |file| if file.display_name == 'sqlite3.dylib' || file.display_name == 'libsqlite3.tbd' puts "Found #{file.display_name} in target: #{target.name} (Project: #{proj_path})" end end end rescue puts "Skipping invalid project file: #{proj_path}" end end - Run it from your project's root directory:
ruby find_sqlite_framework.rb
Option 2: Bash Script (No External Dependencies)
If you prefer a shell script that uses xcodebuild (built into Xcode):
- Save this as
find_sqlite.sh:#!/bin/bash FRAMEWORK_PATTERNS=("sqlite3.dylib" "libsqlite3.tbd") # Find all Xcode projects find . -name "*.xcodeproj" | while read proj; do # Get all targets in the project targets=$(xcodebuild -list -project "$proj" 2>/dev/null | grep -A 10 "Targets:" | tail -n +2 | awk '{print $1}') for target in $targets; do # Check build settings for references to the framework build_settings=$(xcodebuild -showBuildSettings -project "$proj" -target "$target" 2>/dev/null) for pattern in "${FRAMEWORK_PATTERNS[@]}"; do if echo "$build_settings" | grep -q "$pattern"; then echo "Found $pattern in target: $target (Project: $proj)" fi done done done - Make it executable and run:
chmod +x find_sqlite.sh ./find_sqlite.sh
Notes
- Newer Xcode versions often use
libsqlite3.tbd(text-based stub) instead ofsqlite3.dylib, so both scripts check for both variants. - If you're using CocoaPods, the script will still detect frameworks linked in the
Podssubproject.
内容的提问来源于stack exchange,提问作者mauron85
相关产品推荐
相关产品推荐

