Search code examples
iossqlitesqlcipherakavache

Akavache Sqlite linking errors


I am having an issue with SqlCipher and Akavache on iOS. When I add the Akavache library to my project with an existing implementation of SqlCipher I get a number of duplicate sqlite errors during linking.

What is the current behavior?

When I build iOS with Link SDK assemblies I receive the following Sqlite Linking Errors

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

  • Install/Implement SqlCipher
  • Install Akavache
  • Build Xamarin.iOS project

What is the expected behavior? That Akavache Sqlite and SqlCipher Sqlite just work together.

Which versions of Akavache, and which platform / OS are affected by this issue? Did this work in previous versions of Akavache?

  • Akavache 5.0.0
  • iOS 10.3

I wouldn't know. SqlCipher was implemented months ago, and we are just now adding Akavache to the project.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

  • Linking is set to SDK Asemblies only
  • This is a Xamarin Forms project and the Android Linking does not produce the same result. I am actually able to execute the code on Android and have proven that the technologies play nice (from what I can tell)
  • I contacted SqlCipher and the recommended approach is to fork Akavache and swamp the following line of code with another implementation.

  • https://github.com/akavache/Akavache/blob/develop/src/Akavache.Sqlite3/SQLite.cs#L224

Before I go down the road of maintaining a fork, I was wondering if there is better way?


Solution

  • What you're effectively doing here is adding Akavache, which contains a custom SQLite build, to an app which already contains a custom SQLite build. And because of the way iOS linking is done, that's a problem.

    I doubt you actually need a "fork" of Akavache. What you really need, IMO, is an implementation of Batteries_V2.Init() which talks to the SQLCipher instance you already have in your app.

    This is doable, as SQLitePCL.raw already contains multiple implementations of this "bundle" concept, and uses bait and switch to change from one to another.

    Your question is equivalent to one I get from time to time: "How do I use a custom SQLite build with SQLitePCL.raw?" The only difference in your situation is that you already have such a custom build as part of your app. Anyway, it's similar, and unfortunately, SQLitePCL.raw doesn't make this as easy as it should.

    Anyway, explaining how to bridge the gap between Akavache and your existing SQLCipher build is probably beyond the scope of this SO answer, but I might be able to help you head in the right direction. You can post an issue on https://github.com/ericsink/SQLitePCL.raw and I will see it.