Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Ezhbasheil's avatar
Ezhbasheil
Explorer
1 year ago

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

8 Replies

Replies have been turned off for this discussion
    • Ezhbasheil's avatar
      Ezhbasheil
      Explorer

      I followed the tutorial and it seems I somehow didn't have the Meta XR SDK plug in so I installed it and created a brand new manifest but when I started the application, I didn't have the popup asking for permissions like in the tutorial. So when I went to the scene that is supposed to load the data, the game crashed...

    • Ezhbasheil's avatar
      Ezhbasheil
      Explorer

      The problem is that it's just a small soft I'm making for my exam, definitely not something I can afford to spend $40 on

  • Anton111111's avatar
    Anton111111
    Expert Protege

    I think you need read logcat to check Exception. With Exception you will be able to find solution. 

    • Ezhbasheil's avatar
      Ezhbasheil
      Explorer

      That's what I tried to do (https://drive.google.com/file/d/1JTPtdkT1oxqSKiBFRqgu8r3eGgmjisTX/view?usp=sharing).

      I was wondering if it was due to OVRLibrary null cursor received for query content://com.oculus.ocms.library/apps/com.Ezhbasheil.Sports

      or 

      UnityMain type=1400 audit(0.0:3582): avc: denied { read } for name="u:object_r:vendor_board_init_prop:s0" dev="tmpfs" ino=11434 scontext=u:r:untrusted_app:s0:c108,c256,c512,c768 tcontext=u:object_r:vendor_board_init_prop:s0 tclass=file permissive=0

      or

      ClientMgrClientMgr::GetClientPermissionFlagsById: Client missing proper permissions: com.Ezhbasheil.Sports, 4

      ClientMgrClientMgr::GetClientPermissionFlagsById: Client missing proper permissions: com.Ezhbasheil.Sports, 64

      ClientMgr::GetClientPermissionFlagsById: Client missing proper permissions: com.Ezhbasheil.Sports, 2

      But I can't find anything about that online except some threads without any answers...

      The first red line is:

      runtime.cc:669] native: #10 pc 000000000001ffd0 /data/app/~~3Wp36mnmxoaOZUmG-hIrWw==/com.Ezhbasheil.Sports-jQ4rhKAO3V7jcXO8Gp2GdA==/lib/arm64/libsqlite3.so (android::register_android_database_SQLiteConnection(_JNIEnv*)+100) (BuildId: 0f10

      And I can't make any sense of it...

      Here's my manifest:

       

       

      <?xml version="1.0" encoding="utf-8" standalone="no"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:installLocation="auto">
          <application android:label="@string/app_name" android:icon="@mipmap/app_icon" android:allowBackup="false">
              <activity android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:configChanges="locale|fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" android:launchMode="singleTask" android:name="com.unity3d.player.UnityPlayerActivity" android:excludeFromRecents="true" android:exported="true">
                  <intent-filter>
                      <action android:name="android.intent.action.MAIN" />
                      <category android:name="android.intent.category.INFO" />
                      <category android:name="android.intent.category.LAUNCHER" />
                      <category android:name="com.oculus.intent.category.VR" />
                  </intent-filter>
                  <meta-data android:name="com.oculus.vr.focusaware" android:value="true" />
              </activity>
              <meta-data android:name="unityplayer.SkipPermissionsDialog" android:value="false" />
              <meta-data android:name="com.samsung.android.vr.application.mode" android:value="vr_only" />
              <meta-data android:name="com.oculus.ossplash.background" android:value="black" />
              <meta-data android:name="com.oculus.supportedDevices" android:value="quest2|questpro" />
          </application>
          <uses-permission android:name="com.oculus.permission.READ_VR_DEVICE_PARAMS" />
          <uses-permission android:name="android.permission.INTERNET" />
          <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
          <uses-feature android:name="android.hardware.vr.headtracking" android:version="1" android:required="true" />
      </manifest>

       

       

      And my method that is supposed to load the database:

       

       

          private void Awake()
          {
              #if UNITY_ANDROID
                  if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
                      Permission.RequestUserPermission(Permission.ExternalStorageWrite);
                  if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageRead))
                      Permission.RequestUserPermission(Permission.ExternalStorageRead);
              #endif
              _connectionString = $"URI=file:{Path.Combine(Application.persistentDataPath, "data.db")}";
              _dbConnection = new SqliteConnection(_connectionString);
              _dbConnection.Open();
              InitializeDatabase();
              if (IsUsersTableEmpty())
              {
                  CurrentUser = new();
                  InsertUser(CurrentUser);
              }
              else
                  RetrieveUser();
          }

       

      I went to see the permissions for the app in the settings on my Quest 2 and saw that the perm for storage was granted. I'm honestly getting really desperate, so if anyone has any idea I would love to know

    • Anton111111's avatar
      Anton111111
      Expert Protege

      i looked through several articles about sqlite in unity and i see that not all so files works correctly. And i see that advised to use .apart from official site (https://www.sqlite.org/download.html). Maybe you need try to use .aar?
      In my project i use RealmDB and it works good in quest2.