AIA file works perfectly but APK don't

Hello guys, I think I completed my app, it works using companion but if I build it, I have some errors as it can not read correctly the data from the database. I think I have problems with the paths in the apk case. I put the image of the relevant blocks if someone may understand where the problem is.
P.S. seems that I have problems managing valid paths in both modes




screen1

Thanks in advance.

Please confirm the extensions you are using, it appears you have renamed them?

Also you do not show the procedure for this:

image

Ok, you are right. SQL is an instance of: SimpleSqlite Extension V3.
Worked up by TIMAI2, a simplified fork of the SQLite extension by Thomas Bennedum

Created using Rush.
Extension Version: 3.0
Date Built: 2023-02-19

and I attached the pathToAssets bloks. It should be a release by Anke.

I am testing on a Andriid 13 POCO M3 5G smartphone.

A quick description of the app: the app and a partially empty sqlite 3 DB are installed together, the DB in the assets directory of course. At the 1st run the app detects if the language set in the smartphone is supported by the app otherwise asks to select one of the 6 languages supported. The partially empty DB contains the data to set the GUI (colors, fonts, etc.) and the strings used by the GUI in the 6 supported languages. The used data is copied in some TinyDB istances because reading directly by sqlite is quite slower and the GUI loads slowly. I already used sqlite v3 in other apps and it is slow also with the apk. Then, after checking the language, the app checks if a DB is present in the ASD directory, if present it copies its data on the TinyDB instances (the main difference is a table containing a lot of user defined texts that are the main part of the app that realizes an audio guide for a very little museum) so that they can prepare different DBs every time thay change the exhibition. Otherwise opens a screen to download the FULL DB from the internet scanning a QR code (the museum prints it at the reception and on the tickets). There is a simple mechanism to detect if the FULL DB is loaded so the TinyDB istances are written only when the DB is downloaded from internet the first time. To make possible to change the DB without uninstall and reinstall the app there is a command in the options menu to delete the FULL DB and download an updated or different FULL DB. All these complications because in the area of the museum there is no stable/good internet connection and wifi neither because the museum is inside an historical house and so there are many things they can not do as install wifi repeaters... I know it is stupid but this is the situation, there is only an hotspot just before the entrance of the museum so the signal is OK near the door and the reception.

I forgot to mention the extension used in pathToAssets:
GetASD: Get path to ASD & private data dir and the API level:

  • /storage/emulated/0/Android/data/packageName/files/
  • /data/user/0/packageName/files/.
    Extension Version: 3
    Date Built: 2022-09-07

image

This probably won't work as you expect with compiled app to return an absolute path to the database in the assets, in order to set the dbName.

You should be able to get the file path to the default database by opening it, then running an sql command SELECT * FROM pragma_database_list. Store the file path to a variable for later use.

The main problem I have is that "until now" (last implementation november 2022) pathToAssets was the solution to access a DB in the assets directory both using companion and for the apk. Using File.MakefullPath giving Assets and lang2.d as inputs, the result is /android_asset/lang2.db and this path does not exist in the Android file system. And now the situation is worst because I am not able to open the DB also using Companion and I do not know why because nothing changed since yesterday.

I found that the app developed using AI2Offline last november builds with no errors also in AI2 and also with companion. So I made the apk and tested also with companion and it works, I mean it is able to open correctly the DB from the assets directory and of course it does the same in AI2Offline. So, I made a test project taking only the part related to open the DB but unfortunately for some strange reasons it does not work as the complete app. I am repeating the process to cut and paste the project to see if I did a mistake. In the mean time I attached the blocks to open the DB from the assets directory. Unfortunately it is not a general solution for other type of files but only for sqlite v3 DBs using your fork of SimpleSqlite


It all looks horribly complicated. Perhaps some back to basics information will help you.

The default, local, on device, database: SimpleSqlite.db, is available from first run, and is an empty database.

You can then import another database, either from assets or ASD, and all that data from such a database will then be in SimpleSqlite.db

You can work with this (SimpleSqlite.db), creating, reading, updating, deleting data as you wish.

You can then export this (SimpleSqlite.db) to a new db file, or overwrite the previously imported file (except those from assets which are read only).

You should have a separate empty db file available to then import into SimpleSqlite.db so that you can start afresh.

In this way, you do not have to be concerned with working on db files in other locations, and the extension handles file paths to db files for import and export in the same way the File component handles text files (read from Assets, read and write from/to ASD)

It maybe you have this all figured out already.....

OK finally I found the solution to use a sqlite3 DB saved in the assets directory. Using simplesqlite executing OpenDatabase without specifying any DBName it the first time creates and the next time it opens the SimpleSqlite.db DB. Well, executing ImportDatabase passing the string for the assets directory (as i.e //lang2.db) the SimpleSqlite.db is updated with the contents of //lang2.db without changing its name. The update of SimpleSqlite.db is persitent so the next time only OpenDatabase will be needed to work with the //lang2.db contents. To proove how it works I made a little test aia and I tested it works with AI2 + Companion, the APK made by AI2, AI2Offline + its companion and the APK made by AI2Offline.
TestLoadMiniDBW.aia (82.4 KB)

Yes, I found usefule ImportDatabase and finally I was able to realize a solution working as APK, companion and also AI2Offline APK and its companion. It is still a little bit complicated but now at least it is a linear solution