Android Question B4A packs different db

hatzisn

Well-Known Member
Licensed User
Longtime User
I have finished creating an application but I cannot publish it since it packs wrong DB. I have a DB (local.db) which has replaced an older db in the files folder (Ctrl-C -> Ctrl-V in the files folder). When I try to create Release Version I can see in the phone that the old db is packed and installed. I tried to clean the project ---> Nope. I tried to remove the db from file (right click -> ...Delete File...) and add again the new db ---> Nope. It keeps packing and installing the wrong db. Anyone with relatives knowledge who wants to inform me why this is happening?

Edit - As I said the old db was deleted in the files folder (replaced) and I am able to see the contents of the new local.db in Files Folder which are the correct ones.
 
Last edited:

hatzisn

Well-Known Member
Licensed User
Longtime User
AND you ARE using this DB when the app runs the first time? Mean; copy the file to another place and use it from here.
Are you SURE you are copying the File before the use of it?

I am copying the DB to a RuntimePermissions.GetSafeDirDefaultExternal("") position with DBUtils.

1. Open the Files folder with Windows explorer. What do you see there?
2. Open the APK file with 7zip. You can see the files in the Files folder.

1. I have opened the Files folder and I see the file of about 500k (new one)
2. I have opened the APK with WinRar and I see in folder assets the same 500k file
3. I run the application and I see a 236k file which I copy to a windows folder and it is not the same.
4. I clear cash and I clear storage and I uninstall completely and run Release (Obfuscated) in B4A --> Nope again the old file. It has no logic.
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
I changed the code of CopyDBFromAssets into this:

New CopyDBFromAssets:
Public Sub CopyDBFromAssets (FileName As String) As String
    LogColor("CopyFromDBAssets " & FileName, Colors.Blue)
   
    Dim TargetDir As String = GetDBFolder
    If File.Exists(TargetDir, FileName) = False Then
        LogColor("CopyFromDBAssets " & FileName, Colors.Red)
        File.Copy(File.DirAssets, FileName, TargetDir, FileName)
    End If
    Return TargetDir
End Sub

I completely clear cache, clear storage and uninstall and then run the app. Nope --> the same 296k file appears. Only the blue appears so it did not copy.
I am thinking maybe it is a Samsung problem since I did not change anything in my code and it used to work perfect. So I do that. I close the app delete the file manually and start again the app. Blue and Red show. This time it is correct. If it is a code matter why does it work correctly the second time? BUT WAAAAAIIIIT!!! IT GETS EVEN BETTER!!! I am thinking maybe it was a matter of the Samsung phone and now that it copied the correct it will keep the correct. I clear the cache, clear storage, uninstall the app and do again the same thing (Install through B4A Debug). Only blue appears and the same 296k file shows up again. Can someone make out anything of this? What am I suppose to blame and why?
 
Last edited:
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
In line 5 you check, if the file exists, and so you never copy a new version! Simple remove line 5 and line 8.
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
In line 5 you check, if the file exists, and so you never copy a new version! Simple remove line 5 and line 8.

The use of it is exactly this. If you add from assets the DB (and change it maybe) then you should not add it again as it exists.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
My best guess is the old DB exist on your phone and you have not written code to update it or delete it if version changes, hence its unable to copy the new DB from assets folder to your app directory.

Remove the app from your testing device and recompile, and run the app
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that Android automatically makes a backup of installed apps. So even if you uninstall the app and then install it, previous files might be there.
You can disable auto-backups:
B4X:
SetApplicationAttribute(android:allowBackup, "false")

Better option is to change the database file name.
 
Upvote 0

hatzisn

Well-Known Member
Licensed User
Longtime User
It seems to work with the SetApplicationAttribute placed in the manifest.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Note that Android automatically makes a backup of installed apps. So even if you uninstall the app and then install it, previous files might be there.
You can disable auto-backups:
Is there documentation on this that will explain which directories might be included in android's "auto-backup".

This was I can either make sure I place files I want backed up in these areas, and other files I don't want backed up in other areas.
 
Upvote 0
Top