fix(ios): resolve SQLite linking conflicts with pkgx

Fixes iOS build failures caused by linker picking up macOS SQLite
libraries from pkgx instead of iOS system SQLite, resulting in
undefined symbol errors for all sqlite3 functions.

Changes:
- Explicitly link system SQLite library (-lsqlite3) in podspec
- Detect and unset pkgx environment variables during iOS builds
- Add warnings to guide users if manual intervention needed

The issue occurs when pkgx (or similar package managers) set
DYLD_LIBRARY_PATH or PKGX_DIR, causing the linker to find macOS
SQLite dylibs at /Users/*/.pkgx/sqlite.org/*/lib/libsqlite3.0.dylib
instead of the iOS system SQLite library.

This fix ensures the iOS build always uses the correct system SQLite
library regardless of environment variable interference.
This commit is contained in:
Jose Olarte III
2026-01-14 18:41:46 +08:00
parent aaac23111c
commit 630fd3de81
2 changed files with 23 additions and 1 deletions

View File

@@ -11,7 +11,13 @@ Pod::Spec.new do |s|
s.dependency 'Capacitor', '>= 5.0.0' s.dependency 'Capacitor', '>= 5.0.0'
s.dependency 'CapacitorCordova', '>= 5.0.0' s.dependency 'CapacitorCordova', '>= 5.0.0'
s.swift_version = '5.1' s.swift_version = '5.1'
s.xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1' } # Explicitly link against system SQLite library to avoid conflicts with
# macOS SQLite libraries (e.g., from pkgx or other package managers that
# may set DYLD_LIBRARY_PATH or similar environment variables)
s.xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
'OTHER_LDFLAGS' => '$(inherited) -lsqlite3'
}
s.deprecated = false s.deprecated = false
# Set to false so Capacitor can discover the plugin # Set to false so Capacitor can discover the plugin
# Capacitor iOS does not scan static frameworks for plugin discovery # Capacitor iOS does not scan static frameworks for plugin discovery

View File

@@ -149,6 +149,15 @@ build_plugin_for_test_app() {
build_plugin_for_test_app_ios() { build_plugin_for_test_app_ios() {
log_info "Building iOS test app..." log_info "Building iOS test app..."
# Warn about pkgx interference with SQLite linking
if [ -n "$PKGX_DIR" ] || [ -d "$HOME/.pkgx" ]; then
log_warn "⚠️ pkgx detected - this may interfere with iOS SQLite linking"
log_warn " Temporarily unsetting PKGX_DIR and DYLD_LIBRARY_PATH for build..."
unset PKGX_DIR
unset DYLD_LIBRARY_PATH
unset LD_LIBRARY_PATH
fi
# Ensure symlink is in place FIRST (before building) # Ensure symlink is in place FIRST (before building)
# The test app expects the plugin at node_modules/@timesafari/daily-notification-plugin # The test app expects the plugin at node_modules/@timesafari/daily-notification-plugin
SYMLINK="test-apps/daily-notification-test/node_modules/@timesafari/daily-notification-plugin" SYMLINK="test-apps/daily-notification-test/node_modules/@timesafari/daily-notification-plugin"
@@ -374,6 +383,13 @@ build_ios() {
exit 1 exit 1
fi fi
# Warn about pkgx interference with SQLite linking
if [ -n "$PKGX_DIR" ] || [ -d "$HOME/.pkgx" ]; then
log_warn "⚠️ pkgx detected - this may interfere with iOS SQLite linking"
log_warn " If you see 'sqlite3' undefined symbol errors, try:"
log_warn " unset PKGX_DIR && unset DYLD_LIBRARY_PATH && ./scripts/build-native.sh --platform ios"
fi
# Detect project type # Detect project type
if [ -d "test-apps/daily-notification-test" ]; then if [ -d "test-apps/daily-notification-test" ]; then
log_info "Detected test app. Building plugin and test app together..." log_info "Detected test app. Building plugin and test app together..."