Android Question AppUpdate

Declan

Well-Known Member
Licensed User
Longtime User
I am using an edited version of:
I am running the example in Post #243
The Example app runs great.
However, when I port it over to my main app, I get the following error:
B4X:
---- AppUpdating.UpdateApk
    Current Version: 1.00
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
---- AppUpdating.JobDone --
    JobName = JobWebVNcompare, Success = true
    -- JoWebVNcompare
    Read while in webVNcompare: ver=1.01
    Web version number: 1.01
    Newer version available. Now I try its downloading
    -- ApkUpdate
---- AppUpdating.JobDone --
    JobName = JobApkUpdate, Success = true
    -- JobApkUpdate
Error occurred on line: 331 (cl_appupdate)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.rob.leadguru/files/tmp.apk: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:452)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
    at com.rob.leadguru.cl_appupdate._jobdone(cl_appupdate.java:812)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:742)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5653)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
    at libcore.io.IoBridge.open(IoBridge.java:438)
    ... 17 more

The error is here (Marked WITH "<---------------------"):
B4X:
Private Sub JobDone (Job As HttpJob)
  Log("---- AppUpdating.JobDone --")
    If sVerbose Then Log(TAB & "JobName = " & Job.JobName & ", Success = " & Job.Success)
  If Job.Success = True Then
      Select Job.JobName
          Case "JobWebVNonly"
              If sVerbose Then Log(TAB & "Read while in JobWebVNonly: " & Job.GetString)
                webver=ExtractVN(Job.GetString)   'Job.GetString.SubString(4)
                webclog=ExtractCL(Job.GetString)  'optional changelog data
                If webver = "" Then
                  sStatusCode = ERR_TXTROW
                Else  
                  sStatusCode = OK_WEBVER                    'read apk's version number as published on webserver
                  If sVerbose Then Log(TAB & "Web version number: " & webver)
                End If  
        Finito
          Case "JobApkDownload"
                Log(TAB & "-- JobApkDownload")
        'copy from external to storage card
                Dim out As OutputStream
                out = File.OpenOutput(File.DirDefaultExternal,"tmp.apk",False)
                File.Copy2(Job.GetInputStream, out)
                out.Close
                sStatusCode = OK_DOWNLOAD
                If sVerbose Then Log(TAB & "new apk version downloaded and ready to install")
              Finito
      Case "JobWebVNcompare"
                Log(TAB & "-- JoWebVNcompare")
        If sVerbose Then Log(TAB & "Read while in webVNcompare: " & Job.GetString)
                webver=ExtractVN(Job.GetString)   'Job.GetString.SubString(4)
                webclog=ExtractCL(Job.GetString)  'optional changelog data
                If webver = "" Then
                  sStatusCode = ERR_TXTROW
                    Finito
                Else  
                  sStatusCode = OK_WEBVER                    'read apk's version number as published on webserver
                  If sVerbose Then Log(TAB & "Web version number: " & webver)
                End If  
                If curver < webver Then
                  sStatusCode = OK_NEWERAPK                'newer apk version available on webserver
                  If sVerbose Then Log(TAB & "Newer version available. Now I try its downloading")
                    ApkUpdate                                                'download and install
              Else
                    sStatusCode = NO_NEWERAPK
                  If sVerbose Then Log(TAB & "No newer version available on webserver.")
                    Finito
                End If
            Case "JobApkUpdate"
                Log(TAB & "-- JobApkUpdate")
        'copy from external to storage card
                Dim out As OutputStream
                out = File.OpenOutput(File.DirDefaultExternal,"tmp.apk",False) '<-------------------------------ERROR HERE
                File.Copy2(Job.GetInputStream, out)
                out.Close
                sStatusCode = OK_DOWNLOAD
                If sVerbose Then Log(TAB & "new apk version downloaded and ready to install")
                'intent to install
        Dim i As Intent
        i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(File.DirDefaultExternal, "tmp.apk"))
        i.SetType("application/vnd.android.package-archive")
        StartActivity(i)
                sStatusCode = OK_INSTALL
                If sVerbose Then Log(TAB & "user asked to install new apk")
                Finito
      End Select
  Else
    Log(TAB & "Error: " & Job.ErrorMessage)
        sStatusCode = ERR_HTTP
        If sVerbose Then Log(TAB & "error in httputils2")
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
        Finito
  End If
  Job.Release
End Sub

I have checked the Manifest and this is in:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
so, I don't know what is causing the erroe.
 

DonManfred

Expert
Licensed User
Longtime User
You are missing different things.

See this Tutorial:
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Declan,
any reason to prefer old AppUpdating to its 2.0 version?
Btw, if you follow post#34 of AU2.0 you find version 2.04 that proved to work with Android 8 and 9
Sorry if I am unable to give you direct links as of now because I'm using my mobile while walking..
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Hi Declan,
any reason to prefer old AppUpdating to its 2.0 version?
Btw, if you follow post#34 of AU2.0 you find version 2.04 that proved to work with Android 8 and 9
Sorry if I am unable to give you direct links as of now because I'm using my mobile while walking..
Thanks - I will look for the links
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Search for AppUpdating 2.0
Sorry, used the short-form to name it..
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
I have AU2.0 somewhat running.
I can check and download the new app from the server.
I then install:
"Google Play Protect"
Click "Allow"
"Installing"
"App Installed"
Now when I click "Open" the app crashes.
This is a small part of a bigger app.
I have attached the ZIP as I cannot fathom what is wrong
 

Attachments

  • LeadGurus.zip
    50.6 KB · Views: 217
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi, could be an interference due to Google Play Protect?
Can you temporaly disable it and verify if the updated app gets relaunched automatically? That won't solve your problem, but will tell us that AU2 is working properly.
Since I don't use GPP, is there any option to configure apps as "secure", excluding them from its inspection? I read that you allow the installation but what if GPP finds something that it doesn't like? Would it stop and crash the app, show a message or what?
BTW, looking at you code I can't spot a specific reason why the final step fails.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
@udg Many Thanks
I have made some progress and will try your above recommendation soon.
After I have downloaded the new app with AU2.0, and then reload the app (from the Home Page icon) it runs and all functionality of the app is OK.
However, if I then retry the AU, the app crashes and I get the following error on my Android device:
B4X:
android.content.pm.PackageManager$NameNotFoundException: b4a.example.appupdate
at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:137)
at anywheresoftware.b4a.phone.PackageManagerWrapper.GetVersionName(PackageManagerWrapper.java:53)
at com.rob.leadguru.cl_appupdate._isvalidcv(cl_appupdate.java:724)
at com.rob.leadguru.cl_appupdate._readcurvn(cl_appupdate.java:1047)
at com.rob.leadguru.main._getcurrentversion(main.java:646)
at com.rob.leadguru.main._mnu4_click(main.java:1299)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA$1.run(BA.java:335)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)

I cannot understand: "android.content.pm.PackageManager$NameNotFoundException: b4a.example.appupdate"
as my app name is "com.rob.leadguru" and NOT "b4a.example.appupdate"
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Really strange. It looks like it downloads and installs a "debug" copy of your app from your server.
No, it seems to refer to my demo app.
Check what's on the server. As for testing, I generally put on my server the same app I'm going to test, wher its version number is changed to look newer. Even quicker way: just configure the info file to show a newwer version is ready but keep on server an exact copy of the app under test (useful just to see that the whole process gets completed)
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Ok, found the initial problem - I had an edit version of your example on my server.
That has now been resolved, but still crashes on "Open" after Install and does not install the new downloaded version.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Did you try the "suspend Google Play Protect" hint? Did it fail?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Isn't it a separate feature/app installed from the PlayStore? If yes, probably you may find it among the "installed apps" and eventually look for an option to temporaly suspend it or to tell it to disregard your specific app.
I'm sorry to be of little help here, but as said I don't use GPP so I can just offer guesses. Hope someone knowing it better could give us more infos.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Ok, so we're back to square one: problem is with AU and/or your code.
I'm reading your Starter service. You seem to call readUser a lot of times when the app starts (and each time you initialize the DB).
Why not initialize the DB once and call readUser/Notify/Leads once? You can keep the if/then to show proper log message.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Ok, I am now using a brad new Samsung Note 10 and I have the same problem.
The APK downloads from the server and after "Installing" I get a message "Not Installed".
Maybe a guess is that the
APK is not downloaded correctly?
I have cleaned-up the app as mentioned in your previous post.
Latest app is attached.
 

Attachments

  • LeadGurus.zip
    50.3 KB · Views: 204
Upvote 0
Top