- Home /
Unity Android SQLite
have this android application that I am developing in Unity. I am using SQLite to save and access my data.
When I run my code on Unity editor it works fine. But when I tried it in my android device after some changes in the database, it did not work. So I undid those changes and use Android Device Monitor to check what was happening. I found out that, even though it looked to be working, it was throwing a Unity error: Unable to find SQLite.
I just can't understand what is going on. It works on Unity editor, and, before changes in my database, it also worked (or that was what it seemed) on android device.
This is the code I use to connect to database:
private void conecta()
{
if (Application.platform != RuntimePlatform.Android)
{
dbFile = Application.dataPath + "/StreamingAssets/" + databasefile;
}
else
{
dbFile = Application.persistentDataPath + "/" + databasefile;
if (!File.Exists(dbFile))
{
WWW load = new WWW("jar:file://" + Application.dataPath + "!/assets/" + databasefile);
while (!load.isDone)
{
}
File.WriteAllBytes(dbFile, load.bytes);
}
}
print("aaaaaaaaaaaaaaa");
connection = new SqliteConnection("URI=file:" + dbFile);
print("bbbbbbbbbbbbbb");
}
On my project, I have some dll in my Plugins folder.
Mono.Data.dll
Mono.Data.SQLite.dll
sqlite3.def
sqlite3.dll
System.Configuration.dll
System.EnterpriseServices.dll
System.Security.dll
And I have libsqlite3.so in my Android folder that can be seen in the picture. I don't understand what's going on, because when I run the app it accesses the database data and stores more data, but apparently it also throws this error. Can anyone please help me?
If this information is not enough, please let me know. I will complete my question.
UPDATE
I now know the exact line of code that is giving the error. I use the code above to establish a connection with the SQLite database in some scripts. But in this specific script, which is attached to the first screen of the application, the error is coming from this line:
connection = new SqliteConnection("URI=file:" + dbFile);
I don't know why. I use that code as a method and use it some times in this script. I have some buttons that only become interactable if I have data in my database. And when I run it on my device they became interactable. That's why I did not see the error until yesterday when I changed the database file. Below you can see the error when accessing the new column and the table structure in database.
I added one column in two tables, and when I try to access one of those columns it throws an error saying that the table does not have a column with that name. I also deleted the database file and did a new one, already with those columns, but it throws the exact same error.
Can someone please help me?
Your answer
![](https://koobas.hobune.stream/wayback/20220612192248im_/https://answers.unity.com/themes/thub/images/avi.jpg)