Android Question Trying to update to older APK files

Blake K

Member
I am currently trying to make my software be able to update forwards or backwards. I have been using updates in the forward direction for quite some time, however if I download a previous version of my software from the server and try to push it back to the clients they reply with, "File can not be parsed as package is invalid".. These files are valid if installing from a previous version only. Is there some sort of signature issue with the package version? I'm not sure what is causing it. The downloading is 100% working properly. Its when SendInstallIntent is called and the apk is passed to it that it fails
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
I am currently trying to make my software be able to update forwards or backwards. I have been using updates in the forward direction for quite some time, however if I download a previous version of my software from the server and try to push it back to the clients they reply with, "File can not be parsed as package is invalid".. These files are valid if installing from a previous version only. Is there some sort of signature issue with the package version? I'm not sure what is causing it. The downloading is 100% working properly. Its when SendInstallIntent is called and the apk is passed to it that it fails
It could be that the previous package isn't signed correctly. There was an upgrade to signing key security a couple of years back, so maybe those earlier versions predate that?
 
Upvote 0

Blake K

Member
These are all updates within the last several days up to January 2025.. What exactly would render a package as signed 'incorrectly'?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
These are all updates within the last several days up to January 2025.. What exactly would render a package as signed 'incorrectly'?
Well there was a change where the upload key strength had to be 2048 bits or more. I've had apps that haven't been updated for a while, but when I've recently gone to upload an update to the developer console I've had to create a new upload key because the old one didn't meet the new requirements.
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Solution is :
  1. uninstall existing app
  2. install older app
  3. done, it will install fine.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I am currently trying to make my software be able to update forwards or backwards. I have been using updates in the forward direction for quite some time, however if I download a previous version of my software from the server and try to push it back to the clients they reply with, "File can not be parsed as package is invalid".. These files are valid if installing from a previous version only. Is there some sort of signature issue with the package version? I'm not sure what is causing it. The downloading is 100% working properly. Its when SendInstallIntent is called and the apk is passed to it that it fails
Oh - so if you're trying to install a previous version without uninstalling the later version first, then as Erel & Anand said, it will fail. I assumed (wrongly it seems) that you would know that & have uninstalled the newer version first.
 
Upvote 0

Blake K

Member
Thanks everyone. I greatly appreciate the feedback! Is there anyway to check Version Code and if so (after I prompt the user) initialize an uninstall of the current version?
 
Upvote 0

Blake K

Member
Thanks everyone. I greatly appreciate the feedback! Is there anyway to check Version Code and if so (after I prompt the user) initialize an uninstall of the current version?
Disregard -- I overlooked that I can compare the software's local date-time version code I created compared to the server date-time version code and if it is a previous date-time code then I can prompt that way.. Can anyone point me to how to automate a self-uninstall?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
Disregard -- I overlooked that I can compare the software's local date-time version code I created compared to the server date-time version code and if it is a previous date-time code then I can prompt that way.. Can anyone point me to how to automate a self-uninstall?
Or you can just use PackageManager to get the actual app version (old code so there might be a better way now):
B4X:
Public Sub Get_Version() As String
    Private pm As PackageManager
    Private r As Reflector 
    Private P As String
    
    P = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
    Return pm.GetVersionName(P)

End Sub
 
Upvote 0

Blake K

Member
This is how I resolved my issue.

Locally within the program, there is a Date/Time stamp which declares 'the version number'.
This is in the format of YYYYMMDDHHmm (ex: 202508211228 -- 08/21/2025 @ 12:28 am)

Some actual names may be filtered as this is for a company project.
The server has a XXXX_release.txt file containing the YYYYMMDDHHmm information for the current server release
The server has a XXXX_path.txt file pointing to the location of the apk file to be downloaded (ex: ****** YYYYMMDDHHmm.apk)

If the local YYYYMMDDHHmm value != the server YYYYMMDDHHmm value then assuming the server version is newer it will simply update.

If the server version is changed to a version that is a previous version to the version installed locally then the software will download a helper application.

Once the helper application is installed the current version of software is automatically uninstalled.

The helper application is then opened and references the server to download the current version of software (whether newer older no longer matters since what used to be the current version is uninstalled)

The helper application then installs the previous version of software.

Upon installation of software the installation helper then deletes itself.

You are then left with a previous version of your software.

Again thanks for the help-- I hope this might help someone as well
 
Upvote 0
Top