1
votes

I recently moved across to SQLite-net due to it supporting the new changes in Android 7.0 but it's bringing me major issues. I think it's related to linkers but not too sure how to handle the problem.

Firstly, if build my app in debug & release it works perfectly. No issues. If I then archive my app (Generate a signed APK) it starts to crash at different points depending on linker setting.

If I set my app to build with Sdk & user assemblies, my app instantly crashes. Here is part of the log:-

Caused by: android.runtime.JavaProxyThrowable: SQLite.SQLiteException: duplicate column name: objectId
                                                 at SQLite.SQLite3.Prepare2 (SQLitePCL.sqlite3 db, System.String query) [0x0001e] in <1096ddd2a2894a619279903f1fa07799>:0 
                                                 at SQLite.SQLiteCommand.Prepare () [0x00011] in <1096ddd2a2894a619279903f1fa07799>:0  

If I set my app to use Sdk's only it works a little different. It actually starts the app, downloads half of the data. If I try to update the data by adding more it crashes. The app will then crash upon starting everytime until I delete the entire local storage for that app which it then works perfectly.

I have read about skipping linking assemblies too in which case I have skipped all of the SQL related libraries.

--linkskip=SQLite-net --linkskip=SQLite.NET --linkskip=SQLite.Net.Platform.XamarinAndroid --linkskip=SQLite.Net.Platform.XamarinAndroidN --linkskip=SQLiteNetExtensions --linkskip=SQLitePCLRaw.batteries_green --linkskip=SQLitePCLRaw.batteries_v2 --linkskip=SQLitePCLRaw.core --linkskip=SQLitePCLRaw.lib.e_sqlite3 --linkskip=SQLitePCLRaw.provider.e_sqlite3 

Has anyone got any ideas on how to fix this issue. I wanted to release an app shortly but can't get around this. Very similar things are happening with my iOS app too which run on the same DB.

Thanks in advance!

1
Can you find out which SQL language got the duplicate column error? You may selected two table with the same column name "objectId". - Mike Ma
Thanks Mike. Not too sure what happened but I removed all references to every SQLite library I had and reinstalled them. The problem soon went away without any code changes. I also removed the skiplinks too. I think it might have been me referencing 2 seperate SQLite libraries that won't work together. - Phill Wiggins
Since you solved the issue, please close the question. Thanks. - jgoldberger - MSFT
@jgoldberger I don't have enough points to close a question. - Phill Wiggins
Alternately you can answer it and accept your own answer. Just takes it out of the search results when searching for questions without answers. :-) - jgoldberger - MSFT

1 Answers

1
votes

Ok so I found out what to do and how to over come this.

If you're experiencing this issue, it's most likely due that you're creating a table based off a model. Which is a smart thing to do in many cases. But note that this is using reflection. It's worthy to note in the github's FAQ:

Because sqlite-net uses reflection, the MT linker doesn't recognize that it needs various properties. It then strips those properties off of the class.

https://github.com/praeclarum/sqlite-net/wiki/FAQ

So what now?

You got two options as I see it.

[Preserve] Attribute

I'm not very experienced when it comes to this approach. In fact, I haven't really found good documentation to walk me through it. So I can't really comment on this.

Writing Out Your Create Statements

Simply by doing a

connection.Execute("create table ....."); 

This will allow you to create the tables without duplicate columns, and thus use the linker. Hooray!