Can't make SQLite work in the headset
Hello everyone,
I'm making a small VR game in Unity for the Quest 2 and I'm facing some problems to manage the data saved. I decided to use SQLite because this game is to try to take an exam in my country and I know one of the modules is about databases (and that the jury loves SQL).
From the link I gave, I downloaded the precompiled for Android and put it in Assets/Plugins/Android/libs but when I do "Build and Run" and try to do some of the things that are supposed to be saved and restart the game, nothing was saved.
I saw this tutorial that used ".so" files for Android so I followed the android bindings documentation written next to the link for Android in the tutorial and when I put the ".so" file like that: Assets/Plugins/Android/libs/arm64-v8a/libsqlite3.so, and added another file Assets/Plugins/Android/AndroidManifest.xml to give the read/write permission:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.sqlite.database"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="23"
android:targetSdkVersion="34" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true" >
</application>
</manifest>
And here's the Awake() of my DataManager:
private void Awake()
{
if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
Permission.RequestUserPermission(Permission.ExternalStorageWrite);
if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
Permission.RequestUserPermission(Permission.ExternalStorageRead);
_connectionString = $"URI=file:{Path.Combine(Application.persistentDataPath, "data.db")}";
_dbConnection = new SqliteConnection(_connectionString);
_dbConnection.Open();
InitializeDatabase();
if (IsUsersTableEmpty())
{
CurrentUser = new();
InsertUser(CurrentUser);
}
else
RetrieveUser();
}
When I'm in PCVR, the game works correctly and the database is created and all but when I'm in Quest standalone, I can't even start the game even though it worked before using SQLite.
Do anyone know how I can make SQLite work correctly?
Thanks in advance
