sqlite3.dart
sqlite3.dart copied to clipboard
iOS: Could not build Objective-C module 'SQLite3' when install drift
Hello. I have the following problem. I am running sqlite tests with native code. In iOS I have the code in the image, at first while testing it was working fine. But when I installed drift I get the following error and the app does not start. I am importing the default sqlite3 library. is there any way to fix it or should I use a third party library for native swift code?
PS: On android there is no problem.
Thanks in advance
Full Log:
Launching lib/main.dart on iPhone 15 Pro Max in debug mode...
Xcode build done. 13,3s
Failed to build iOS app
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_file'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:728:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_io_methods'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:834:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_vfs'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:1464:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_mem_methods'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:1764:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_module'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7287:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_index_info'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7431:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_index_constraint'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7434:9
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_index_orderby'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7441:9
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_index_constraint_usage'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7446:9
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_vtab'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7609:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_vtab_cursor'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:7633:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_mutex_methods'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:8130:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_pcache_page'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:8902:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_pcache_methods2'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:9067:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_pcache_methods'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:9090:7
Swift Compiler Error (Xcode): Redefinition of 'sqlite3_snapshot'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:10464:15
Swift Compiler Error (Xcode): Typedef redefinition with different types ('struct (unnamed struct at /Users/victortinoco/Documents/GitHub/sqlite_test/build/ios/Debug-iphonesimulator/sqlite3/sqlite3.framework/Headers/sqlite3.h:10465:16)' vs 'struct sqlite3_snapshot')
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Pods/sqlite3/sqlite-src-3450000/sqlite3.h:10466:2
Swift Compiler Error (Xcode): Could not build Objective-C module 'SQLite3'
/Users/victortinoco/Documents/GitHub/sqlite_test/ios/Runner/DatabaseHelper.swift:8:7
Could not build the application for the simulator.
Error launching application on iPhone 15 Pro Max.
Exited (1).
So the problem is that SQLite.swift will also try to link sqlite3
, but it doesn't use the sqlite3
pod for this and instead will always use the sqlite3 library from the system.
Since it also includes its own sqlite header, there are redefinitions when sqlite3_flutter_libs
tries to actually compile sqlite3 into your application.
Unfortunately, I'm not experienced enough with Cocoapods to know how to fix this. I think you can override the SQLite.swift pod to not link sqlite3, and perhaps also exclude its sqlite3.h
from being part of its source?
I'm having the same problem. have you found a workaround? @simolus3 @victj99
writing this comment if you have the same problem as me and are desperate for a fix, maybe this works for you.
If you are using drift database package and using sqlite3_flutter_libs
package only to making sqlite3 database to work on Android. maybe you can fork the repo and delete the iOS side of the plugin. that way iOS compiles successfully and Android app works as well.
here is my fork if you need it.
https://github.com/easazade/sqlite3.dart/tree/remove-ios
I also encountered this problem. Is there any solution?
Perhaps it works if you use the standalone subspec of SQLite.swift? That one has a dependency on the sqlite3
pod so there is no difference in the way that package and sqlite3_flutter_libs
are linking sqlite3.
Perhaps it works if you use the standalone subspec of SQLite.swift? That one has a dependency on the
sqlite3
pod so there is no difference in the way that package andsqlite3_flutter_libs
are linking sqlite3.
it really help me
Excuse me, @simolus3 , I don't understand how to fix the issue in a Flutter project, can you explain for dummies where to inject that code?
Also, on another topic, why don't you erase the ios part of sqlite3_flutter_libs
like @easazade did? Just question, huh. I don't pretend you change the package is just for understanding.
explain for dummies where to inject that code?
I'm not too familiar with Cocoapods, but I think adding a pod 'SQLite.swift/standalone'
dependency to the target 'Runner'
section of your podfile should do it.
@Rodsevich nope still the same
@simolus3 the helped a bit I get only this now /Users/psikosen/StudioProjects/mama_bear_fe/ios/Pods/sqlite3/sqlite-src-3460100/sqlite3ext.h:32:8 Type 'struct sqlite3_api_routines' has incompatible definitions in different translation units
`dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter
cupertino_icons: ^1.0.2 card_swiper: ^3.0.1 app_links: ^6.1.4 http: ^1.0.0 in_date_utils: ^1.2.0+2 google_fonts: ^6.2.1 connectivity_plus: ^6.0.5
url_launcher: ^6.3.0 faker_dart: ^0.2.2 dio: ^5.5.0+1 flutter_hooks: ^0.20.5 hooks_riverpod: ^2.1.1 freezed: ^2.5.2 freezed_annotation: ^2.4.4 json_annotation: ^4.7.0 json_serializable: ^6.5.4 uuid: ^4.4.2 go_router: ^14.2.2 sizer: ^3.0.3 font_awesome_flutter: ^10.2.1 liquid_swipe: ^3.0.0 scroll_date_picker: ^3.6.0 percent_indicator: ^4.2.2 geolocator: ^13.0.1 logger: ^2.4.0 shared_preferences: ^2.2.1 permission_handler: ^11.3.1 camera: ^0.11.0+1 video_player: ^2.5.1 webviewtube: ^2.0.0 path_provider: ^2.0.12 http_parser: ^4.0.2 syncfusion_flutter_calendar: ^26.2.7 awesome_notifications_core: ^0.9.3 awesome_notifications: ^0.9.3+1 sensors_plus: ^6.0.0
local_auth: ^2.1.8 local_auth_darwin: ^1.3.1 local_auth_android: ^1.0.42 flutter_secure_storage: ^9.2.2 dio_smart_retry: ^6.0.0 syncfusion_flutter_datepicker: ^26.2.7 crypto: ^3.0.2 pay: ^2.0.0 syncfusion_flutter_pdfviewer: ^26.2.13 app_tracking_transparency: ^2.0.4 flutter_paypal: ^0.2.0 fc_native_video_thumbnail: ^0.12.0 image: ^4.0.15 encrypt: ^5.0.1 native_device_orientation: ^2.0.3 chewie: ^1.7.5 syncfusion_flutter_gauges: ^26.2.7 toggle_list: ^0.3.0 in_app_purchase: ^3.2.0 package_info_plus: ^8.0.1 flutter_exit_app: ^1.1.4 upgrader: ^11.0.0 shared_preferences_foundation: ^2.3.4 device_info_plus: ^10.1.1 drift: ^2.20.0 drift_flutter: ^0.2.0`
It's hard too say which of these packages might be linking sqlite3 as a native dependency - can you check whether adding this snippet to your podfile changes anything though?