Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: Could not build Objective-C module 'SQLite3' when install drift #208

Open
victj99 opened this issue Feb 5, 2024 · 8 comments
Open

Comments

@victj99
Copy link

victj99 commented Feb 5, 2024

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

image

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).
@simolus3 simolus3 transferred this issue from simolus3/drift Feb 5, 2024
@simolus3
Copy link
Owner

simolus3 commented Feb 5, 2024

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?

@easazade
Copy link

easazade commented Feb 29, 2024

I'm having the same problem. have you found a workaround? @simolus3 @victj99

@easazade
Copy link

easazade commented Mar 5, 2024

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

@tbfungeek
Copy link

I also encountered this problem. Is there any solution?

@simolus3
Copy link
Owner

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.

@tbfungeek
Copy link

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.

it really help me

@Rodsevich
Copy link

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.

@simolus3
Copy link
Owner

simolus3 commented Jul 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants