B4A Library AppUpdating - automate apps updating from a webserver

Status
Not open for further replies.
Important note: since all the changes made to the Android OS the original code is to be considered outdated. Thanks to @Yayou49 you may find at post#290 a version of the class usable on Android 6+ versions.

Note: version 1.25 breaks existing code so, please, read changelog in post #60 below.


Hi all,

this is my first contributing lib to this great NG.
How do I dare to publish such a low-grade stuff in an area where generally you may find real masterpieces of programming? Well, to be honest, I hope in your help to upgrade my work to a status of "ready-made solution" for those who prefer to run their own webservers where to publish apps.
Secondly, I was asked (both privately and publicly) to overcome my legitimate embarassment and go on with the publication. So, here we are: AppUpdating 1.18!

Note: any valid code fragment comes from some other thread, while all the bad stuff is entirely mine ;-)

Please find attached both the library as is (yes, it works out of the box) and its source code.

On a following post I'm gonna describe the lib in greater detail and show how to use it.

Umberto

AppUpdating version history

* version 1.30 (read notes on post #228)
  • compiled with okHttp 1.01 and okHttpUtils 2.20
  • removed files for version 1.25

* version 1.26 (read notes on post #84)
  • added property WebChangeLog to read optional app's version changelog data
  • better management of versioning in the info file
  • removed files for version 1.18 to avoid confusion (still available on request)
* version 1.25
* version 1.18
  • initial release
 

Attachments

  • AppUpdating_126_ex.zip
    28.3 KB · Views: 1,104
  • AppUpdating_126.zip
    11.3 KB · Views: 1,129
  • AppUpdating_126_src.zip
    10.8 KB · Views: 893
  • AppUpdating_130.zip
    11.4 KB · Views: 1,129
  • AppUpdating_130_src.zip
    15.7 KB · Views: 1,039
  • AppUpdating_130_ex.zip
    33.4 KB · Views: 1,235
Last edited:

aidymp

Well-Known Member
Licensed User
Longtime User
Hi Aidy,

try to compile your program with the library attached to this same post.
You should first eliminate from your code any copy of modules HttpJob, HttpUtils2Service and DownloadService since I needed to enclose them in this version of AppUpdating (version 1.27LFD).
Obviously, if you altered those modules from what's attached to Erel's example I need to use your modified copies instead of the ones used. Let me know.

Umberto


Hi, Thanks for that, i have just done a quick test, My original code is working fine, apart from some problematic coding on my part! however Appupdating still fails, i use the code

apkupdt.Initialize(Me,"update")
apkupdt.Verbose = True 'this one affects the verbosity of the logs
apkupdt.PackageName = "com.aidymp.aidymatic"
apkupdt.NewVerTxt = "http://koditime.com/updates/AidyMatic.info"
apkupdt.NewVerApk = "http://koditime.com/updates/AidyMatic.apk"
apkupdt.ReadCurVN
apkupdt.ReadWebVN

label2.Text = "Visit aidymp.co.uk - v" & apkupdt.WebVN - This never displays the version number, and my app says AidyMatic! is not responding!

Do you have any idea why?

Thanks

Aidy
 

udg

Expert
Licensed User
Longtime User
Do you set label2.Text in sub update_UpdateComplete?
Command apkupdt.ReadWebVN starts an httpjob to download your .info file; when AppUpdating is in its verbose status, you should read in the log area:
B4X:
Read while in JobWebVNonly: xxxxx, where xxxx is the content of the .info file
Web version number: xyz, where xyz is the version number read from the .info file
Soon after that, the library calls a sub in your main: update_UpdateComplete (and does nothing if it doesn't find it..this should be corrected!)

udg
 
Last edited:

aidymp

Well-Known Member
Licensed User
Longtime User
Me again! sorry for this!

Right I have added the code

Sub update_UpdateComplete
label2.Text = "Visit aidymp.co.uk - v" & apkupdt.WebVN
End Sub

Still apkupdt.ReadWebVN seems to start an activity that never actually starts

and I get this on my device, AidyMatic! is not responding, Would you like to close it?

I press no, then I start my download procedure, and at the end I get an error, Sub dd_complete signature does not match expected signature.

My Log

Installing file.
PackageAdded: package:com.aidymp.aidymatic
** Service (newinst2) Start **
-- AppUpdating.NewInst2: processing service_start
** Activity (main) Create, isFirst = true **
---- AppUpdating.ReadCurVN
Current Version: 1.40
---- AppUpdating.ReadWebVN
sending message to waiting queue of uninitialized activity (submitjob)
** Service (httputils2service) Create **
** Service (httputils2service) Start **
** Activity (main) Resume **
** Service (downloadservice) Create **
** Service (downloadservice) Start **
java.lang.Exception: Sub dd_complete signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:177)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:952)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4430)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
at dalvik.system.NativeStart.main(Native Method)
java.lang.Exception: Sub dd_complete signature does not match expected signature.

Thanks

Aidy
 

udg

Expert
Licensed User
Longtime User
Edit#2: attached source code for a demo using your site/parameters. The installation step (last one) should work only when Aidy compiles the code with his signature since the demo is configured as an older copy of the app on the site and newer copy won't substitute older one if they are signed differently.

Edit: found a simpler way. Tomorrow I'll modify the remaining AppUpdating code and post here a "new" library named AppUpdatingLFD. I'll be identical to AU version 1.26 but able to use (and enclosing) Erel's modules HttpJob, HttpUtils2Service and DownloadService.

Hi Aidy,
I experimented with the LFD code and found that I can't simply substitute an http2 version for the other, so AppUpdating needs to fully embrace the new scheme.
What I mean is that AU has to go the DownloadService/DownloadData way to read files from the server, abandoning the standard Http library download way used so far.
I tried the above with the ReadWebVN function and sucessfully downloaded/read your info file and app worked as expected.
This means a bit more work to be done, but nothing too difficult.
I'll be back when I'll have something for you to test.

udg
 

Attachments

  • AidyTest.zip
    28.2 KB · Views: 223
Last edited:

udg

Expert
Licensed User
Longtime User
Hi all,

please find attached a special version of AppUpdating intented to work along Erel's LargeFileDownload modules.
It is named AppUpdatingLFD and current version is 1.27.
It is made from the same base code as AppUpdating 1.26, but it encloses modules HttpJob, HttpUtils2Service and DownloadService from cited Erel's code so you should first eliminate from your project any copy of those.
Install it and use it as any standard version of AppUpdating.

udg
 

Attachments

  • AppUpdatingLFD127.zip
    25.5 KB · Views: 282

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Hi all,

please find attached a special version of AppUpdating intented to work along Erel's LargeFileDownload modules.
It is named AppUpdatingLFD and current version is 1.27.
It is made from the same base code as AppUpdating 1.26, but it encloses modules HttpJob, HttpUtils2Service and DownloadService from cited Erel's code so you should first eliminate from your project any copy of those.
Install it and use it as any standard version of AppUpdating.

udg

Very NICE!!!!

You might want to update the first post and would love to see more source code. The last source was V1.25 ---> GREAT WORK!!!! The next beer is on me.
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi Jake,
you're always so kind.

I kept from promoting AppUpdatingLFD to post#1 only because I found it wiser to wait for Aidy to test it along with its real
code instead of relying only on my test as per post #104 above. I know from a PM message that he's actually busy in overhauling its app by a new approach, so I set myself on queue waiting for some spare time on his part.
If you have any project using Erel's LFD and would like to test my lib against it, you're welcome.

Source: you are right. I forgot to publish 1.26 source (although it's almost identical to 1.25 but a newer function to extract the changelog).
AppUpdating sports a 1.27 version number but it is built on the same code as 1.26 just differentiating on how to call Http jobs.
Anyway, keep an eye on post#1 since I'll add version 1.26 code as soon as I'm back to my dev PC.

Umberto
 

aidymp

Well-Known Member
Licensed User
Longtime User
Hi, Sorry for the delay in replying, I actually thought I had replied but now cannot find it! :-/

I have again been trying to add the AppUpdating 1.27LFD to my app! and it did not work! BUT after a bit of messing i belived the problem may be at my end! I think i was calling the commands too fast! not giving time for the library to either initialise or download the data to fill the variable before reading it!

It sort of works with my code, I have noticed that if i call commands one after the other it just hangs as it never gets the response it was expecting, i have tried various ways of delaying this, Also I have noticed that I have to reboot my device after each code change, otherwise it just refuses to work! the update_Updatecomplete doesnt seem to fire everytime!

I am certain its something in my code thats interfering as your example works flawlessly!
 
Last edited:

udg

Expert
Licensed User
Longtime User
Thank you, Aidy.
When back from my holiday I'll try to build a more complex test in order to replicate those same issues you cited and hopefully find a solution.
I will postpone until then the lib publishing in post #1 to avoid too much attention gathering.

udg
 

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

This is a very useful Lib.

Is it possible to show an animated GIF in the SetAndStartSplashScreen() ?
B4X:
ApkUpdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "Downloading.png"))

I tried using an animated gif, unfortunately the animation is not working. It is displayed only as a still pic/regular pic

I feel that, instead of showing a still image, it would be nice to show an animated GIF with some animations like Syncing or Downloading from the cloud, so that the user feels that something is happening in the background and that the app is not stuck.

As of now I used the following
B4X:
ApkUpdt.SetAndStartSplashScreen(Activity,LoadBitmap(File.DirAssets, "Downloading.png"))
ProgressDialogShow("Checking for updates.....")
...
...
Sub AppUpdateCheck_UpdateComplete
  ApkUpdt.StopSplashScreen
  ProgressDialogHide
....
.....


Anyway, the lib is really a good one.:)

Regards
Anser
 

udg

Expert
Licensed User
Longtime User
Hi Anser,

thank you for you post. I never used before animated GIFs but that sounds as a good idea.
Let me search a bit and I'll report back here about my findings.

udg
 

Tomas Petrus

Active Member
Licensed User
Longtime User
Hi,

I am trying to implement this Library into my project, but i have problem with examlpe. When App is trying to update itself then I get instalation error: "the application can not be installed. Already installed package with the same name and description of the conflict". Error is translated into english, because I have czech system.

Thaks for answer
 

udg

Expert
Licensed User
Longtime User
Hi Tomas.
Project name for the example code is "b4a.example.appupdate" and its Version Name is 1.01.
To test the upgrade cycle you should have compiled it as is and then have uploaded it to a webserver along with its corresponding text file; finally, using the same code, downgrade Version Number to 1.00 and install this one on your test device.
When running, the 1.00 version should discover a newer (1.01) one on the server and proceed with the download and installation.

Let me know if the above works.
ps: I plan to be on-line for a couple of hours more so, eventually, you can PM me if you find it useful.
 

Tomas Petrus

Active Member
Licensed User
Longtime User
Hi,

It works very well!! Thanks for answer and for library of course :)
Now I have AppUpdating implemented in my App
 
  • Like
Reactions: udg

G-ShadoW

Active Member
Licensed User
Longtime User
Why I'm getting this error now

B4X:
java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object cannot be cast to eu.dgconsulting.appupdatinglfd.downloadservice$_jobtag
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA$3.run(BA.java:332)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4963)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to eu.dgconsulting.appupdatinglfd.downloadservice$_jobtag
    at eu.dgconsulting.appupdatinglfd.httputils2service._hc_responsesuccess(httputils2service.java:144)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    ... 10 more

autoupdate was working ok and still working ok, I have only add httpUtils2 and trying to download some file and my application crash with this above info !

B4X:
Sub btnDownload_Click
      
    job2T.Initialize("job2T", Me)

     job2T.Download("https://www.myserver.com/somefile.txt")
   
     ProgressDialogShow2("Downloading...", False)

End Sub

post #7 - 10 didnt solve the problem
I use refliection library 2.40
phone lib 2.26

I have removed httpUtils2 v2.01
but I cant now download anything
how to solve this ?
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi G-ShadoW,
unfortunately these days I'm away from my dev pc so I can't take prompt action on your message.
Did you use the lfd version of my lib because of really big files or you just picked it as the most recent one? I ask that because not so much testing was done on the lfd fork so if you really don't need it maybe it would be safer to stay with the original one.
Anyway this could be the right time to do some deeper testing and some cleaning for the lfd v3rsion too.

udg
 

G-ShadoW

Active Member
Licensed User
Longtime User
Hi G-ShadoW,
unfortunately these days I'm away from my dev pc so I can't take prompt action on your message.
Did you use the lfd version of my lib because of really big files or you just picked it as the most recent one? I ask that because not so much testing was done on the lfd fork so if you really don't need it maybe it would be safer to stay with the original one.
Anyway this could be the right time to do some deeper testing and some cleaning for the lfd v3rsion too.

udg

Yes, I was used v1.27 and with that version I was unable to use httpUtils2
I have now use your 1.26 v appupdating and everything is ok
Thank you for your attention

B.R.
 

udg

Expert
Licensed User
Longtime User
Hi, glad to hear you already solved the problem.
As you discovered, it was due to different versions of the httputis service as used in version LFD (1.27) from the one used on standard (1.26) AppUpdate fork.

udg
 

ruy

Member
Licensed User
Longtime User
Is there a new version after the 1.26 available in the first post? Most of the methods in the post on how to use it are not in the library.
 

gruizelgruis

Member
Licensed User
Longtime User
Hello,
I found a little problem. I am using this great library on a second activity.
I noticed after initializing appupdate, the main activity gets loaded.

I checked the source and found that in the "newinst2" module there is the sub
B4X:
Sub MyAppReload
    If svcVerbose Then Log("-- AppUpdating.NewInst2: processing MyAppReload")
  If IsPaused("main") Then
    StartActivity("main")
  End If
    'Dim In As Intent
  'StartActivity(pkg&"/.main")
End Sub

That reloads the main-activity

I like to suggest to use the "Callback" variable in

B4X:
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(CallbackModule As Object, EventName As String)
  Callback = CallbackModule
    Event = EventName
  sPackageName = ""
    sNewVerTxt = ""
    sNewVerApk = ""
    sUserName = ""
    sUPassword = ""
    sStatusCode = OK_INIT
    curver = ""
    webver = ""
    sVerbose=False
End Sub

To substitude "main" in "Sub MyAppReload" If thats at all possible
 
Status
Not open for further replies.
Top