3

I am modularising a large iOS app lets say, MyAppWithDatabase into two modules (i.e. projects). So I will have one main project MyApp as a host and a linked MyDataPlatform as a framework under same workspace MyApp.xcworkspace. When SQLCipher pod was integrated for target MyAppWithDatabase it worked fine, but as all of the database related codes are being moved into MyDataPlatform framework in refactoring, I want to integrate SQLCipher pod only for the framework to keep internal encryption mechanism abstract from host app. Now, when I have integrated for framework it started producing below build error.

Implicit declaration of function ‘sqlite3_key’ is invalid in C99

Note that this issue is being produced from one statement of MyApps source code as a warning but Xcode build treating it as error,

sqlite3_key(_db, [password UTF8String], (int)password.length);

I have the above line still remaining in MyApp because it takes time to move database related codes gradually into MyDataPlatform and I assume the SQLCipher headers are still supposed to be available in host app as the related framework in linked.

I have gone through many proposed solutions on the Internet but none of them worked for my case. I doubt most of the solutions are about integrating SQLCipher for host app only. What should I do when I get the error for framework in my case?

Below is the structure of my pod file (after refactored),

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

workspace 'MyApp.xcworkspace'

target 'MyApp' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!

  pod 'Google/Analytics'
  pod 'GoogleMaps'
  # ...

  target 'MyAppTests' do
    inherit! :search_paths
  end

end

target 'MyDataPlatform' do
  project 'MyDataPlatform/MyDataPlatform.xcodeproj'
  pod 'SQLCipher', '~>3.4.2'

  #https://discuss.zetetic.net/t/ios-11-xcode-issue-implicit-declaration-of-function-sqlite3-key-is-invalid-in-c99/2198/53
  post_install do | installer |
    print "SQLCipher: link Pods/Headers/sqlite3.h"
    system "mkdir -p Pods/Headers/Private && ln -s ../../SQLCipher/sqlite3.h Pods/Headers/Private"
  end
end

Previously SQLCipher was integrated under MyAppWithDatabase i.e.

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

target 'MyAppWithDatabase' do
  # Uncomment this line if you're using Swift or would like to use dynamic frameworks
  use_frameworks!

  pod 'Google/Analytics'
  pod 'GoogleMaps'
  pod 'SQLCipher', '~>3.4.2'
  # ...

  target 'MyAppWithDatabaseTests' do
    inherit! :search_paths
  end

end
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256

2 Answers2

2

My problem was solved after defining SQLITE_HAS_CODEC in application's,

MyApp -> Build Settings -> Other C Flags

Another solution also works after adding SQLITE_HAS_CODEC=1 in application's,

MyApp -> Build Settings -> Preprocessor Macros
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0

My problem was caused by SPACEs in my project's pathname. The sqlite 'make' script that should generate the sqlite3.c at compilation time seems to trip when there are SPACEs in the sqlcipher library's pathname. I temporarily removed the SPACEs from the pathname and compilation worked.

Sleiman
  • 1,620
  • 1
  • 12
  • 16