Android Question Android SDK 34 not working with SqlCipher - Solved... I think.

GeoffT660

Active Member
Licensed User
Longtime User
I am troubleshooting a new REVVL Tab 5g running Android SDK 34. Data in the SqlCipher database loses all data in the database upon closing the application. I can see it populates the database when downloading the data but when I exit the app, none of the data is saved. This works on every version without issue prior to SDK 34. I tried updating to SqlCipher 1.7 but still have the same issue. All the database transactions work as expected while in the app and only when you close the app completely all the data is removed from the database. Any ideas on how I can resolve this issue. Thanks.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
This sounds very much like a permissions error. You say that your targetSdkVersion in the Tab 5g is 34. What was the targetSdkVersion previously? When you say "none of the data is saved" - where are you trying to save this data?
 
Last edited:
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
Previously my targetSdkVersion was 33. My app has worked for over 10 years without issue on every device I found so far. I download data and populate the tables in the sqlCipher database where the data is stored. Everything works great and I can perform any sql transaction on the data in the tables as I always have as long as I stay in the App. When I exit the app, all the data in the SqlCipher Db is gone. I can confirm this with dbBrowser. Never seen anything like this. The only difference that I can see is the new Android Version 34 because the app still works fine on all other devices including 33.
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
I have found a solution but don't understand all the intricacies so not sure why the change. I have always used
B4X:
Dim DBFileDir = File.DirDefaultExternal As String
to define my device db directory. On sdk version 34 I now have to use
B4X:
Dim DBFileDir = File.DirInternal As String
but this doesn't work on previous versions so I have added this code
B4X:
If phone.SdkVersion > 33 Then
    Dim DBFileDir = File.DirInternal As String
Else
    Dim DBFileDir = File.DirDefaultExternal As String
End If

Could this issue be device specific or the change in the TargetSdkVersion?

Please let me know if I should be using a different method or you see any issues with this approach.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
This was the reason for my other question, which you did not answer before . . .
When you say "none of the data is saved" - where are you trying to save this data?
Your answer is . . .
B4X:
Dim DBFileDir = File.DirDefaultExternal As String
Sdk 34 does not allow writing directly to storage outside of the app local storage without asking the User to select a location. See this thread.

Using internal storage on earlier Sdks should not be a problem, however, so your code modification should not be required. I don't know what is happening there.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
B4X:
Dim DBFileDir = File.DirDefaultExternal As String
or
B4X:
Dim DBFileDir As String = File.DirDefaultExternal
?
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
You are right
B4X:
Dim DBFileDir As String = File.DirDefaultExternal
is the correct syntax. Not sure why it never gave a warning and has always worked this way. Thanks.
 
Upvote 0

GeoffT660

Active Member
Licensed User
Longtime User
B4X:
FileDir=rp.GetSafeDirDefaultExternal("")
does not help with the original issue on TargetSdkVersion 34 but works fine on 33 and below.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
TargetSdkVersion 34 but works fine on 33 and below.
I'm pretty sure the current recommended targetSDKVersion for B4A 33. I could be mistaken and any corrections on this are welcome.
 
Upvote 1
Cookies are required to use this site. You must accept them to continue using the site. Learn more…