- Home /
[Unity] Problem with SQLite on Android
Hello, I have been trying to get SQLite to work on my Android device for days now. First of all, I want to point out, that everything works fine on the computer. I can read and write to the created SQLite database with no errors.
The problem starts when I export the project to .apk and install it on my Android device. When I'm trying to do anything involving the databse, nothing is happening.
The logcat message:
What have I done to this point:
Downloaded and put sqlite3.dll to Assets/Plugins folder
Copied System.Data.dll and Mono.Data.Sqlite.dll from Unity\Editor\Data\Mono\lib\mono\2.0 folder to Assets/Plugins folder in my project
Created database using 'SQLite Administrator tool' and put it in the Assets folder
Created Assets/Plugins/Android folder and put libsqlite3.so in it
As I said before, this works perfectly fine on the computer (in the Unity Editor), but not on the Android device.
I was looking for the solution everywhere, but in most cases putting libsqlite3.so to the Assets/Plugins/Android solved the problem. Any help will be appreciated.
I've got exactly the same problem and can't find working solution anywhere ;/
So... how did you do it @grzekos ? Did you found the solution? Have similar problem...
Hello, you solved the problem, it happens to me too. This is the code I use.
try
{
string conn = "URI=file:" + Application.dataPath + "/Base de Datos/Catalogo.s3db"; //Path to database.
Debug.Log(conn);
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string CodigoCategoria = VariablesGlobales.codigoCategoria != null ? VariablesGlobales.codigoCategoria : "ninguna";
string sqlQuery = "select codigoCategoria,NombreCategoria from Categorias where codigoCategoria='" + CodigoCategoria + "' ";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
if (reader.Read())
{
string codigoCategoria = reader.GetString(0);
string NombreCategoria = reader.GetString(1);
TituloCategoria.text = NombreCategoria;
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
catch (Exception exe)
{
Debug.Log(exe.$$anonymous$$essage);
}
Answer by houseyokeswaran · Aug 30, 2017 at 06:42 PM
Try putting the database in StreamingAssets folder or use file I/O and save it to Application.PersistantDataPath
Seems like it's also not able to find the actual sqlite dll though. Could be that the dll is not supported on Android.
https://github.com/Busta117/SQLiteUnityKit
I've used this library with success for compiling on Android