Android Question HttpJob Not Working on Android 11 (API 30) with B4A Latest Version and android.jar SDK 36

Flavio SOuza

Member
Licensed User
Longtime User
Hello,

I'm facing an issue with the HttpJob class from the OkHttpUtils2 library after updating B4A to the latest version (likely 13.40 or higher) and using android.jar from SDK 36 (C:\Android\platforms\android-36\android.jar). The code works perfectly on emulators with API 34 (Android 14) or higher but fails on a physical device running Android 11 (API 30).


Details:
  • B4A Setup: Latest B4A version, configured with android.jar from SDK 36, targetSdkVersion=35 (also tested with targetSdkVersion=30), and minSdkVersion=14.
  • Device: Android 11 (API 30), physical device.
  • Code: A simple HttpJob GET request to https://httpbin.org/get with a 60-second timeout.
  • Issue: The code stops at the log "4. Timeout configured" before the JobDone event is triggered. No errors appear in the logs, and the Wait For (ping) JobDone never completes.
  • Previous Behavior: The code worked fine before updating B4A to use SDK 35/36.
  • Logs: Added detailed logs (see below), but execution halts after ping.GetRequest.Timeout = 60000 without reaching JobDone or showing errors.
  • Manifest: Includes INTERNET and ACCESS_NETWORK_STATE permissions, <queries> for HTTPS, and usesCleartextTraffic="true" for testing.
  • Tests Tried:
    • Tested with a different endpoint (https://www.google.com) – same result.
    • Disabled battery optimizations and tested on different networks – no change.
    • Confirmed latest OkHttpUtils2 library is used.

Questions:
  1. Could the android.jar from SDK 36 cause compatibility issues with Android 11 when using OkHttpUtils2?
  2. Are there specific manifest settings or OkHttpUtils2 configurations needed for Android 11 when compiled with SDK 36?
  3. Any known issues with HttpJob on Android 11 with the latest B4A and SDK 36?

Any help or suggestions would be greatly appreciated!


Test HttpJob:
Sub pinga
    Dim ping As HttpJob
    Log("1. Initializing HttpJob")
    ping.Initialize("ping", Me)
    Log("2. HttpJob initialized")
    ping.Download("https://httpbin.org/get")
    Log("3. Download started")
    ping.GetRequest.Timeout = 60000
    Log("4. Timeout configured")
    Try
        Wait For (ping) JobDone(ping As HttpJob)
        Log("5. JobDone called: Success=" & ping.Success)
        If ping.Response <> Null Then
            Log("6. Response StatusCode: " & ping.Response.StatusCode)
            Try
                Log("7. Response String: " & ping.GetString)
            Catch
                Log("8. Error getting string: " & LastException.Message)
            End Try
        Else
            Log("6. Response is Null")
        End If
        Log("9. PING success? " & ping.Success & " code=" & IIf(ping.Response <> Null, ping.Response.StatusCode, -1))
        If ping.Success = False Then
            Log("10. PING error: " & ping.ErrorMessage)
        End If
    Catch
        Log("11. Error in Wait For: " & LastException.Message)
    End Try
    ping.Release
    Log("12. HttpJob released")
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
All these Try / Catch blocks should be removed.

  1. Could the android.jar from SDK 36 cause compatibility issues with Android 11 when using OkHttpUtils2?
  2. Are there specific manifest settings or OkHttpUtils2 configurations needed for Android 11 when compiled with SDK 36?
  3. Any known issues with HttpJob on Android 11 with the latest B4A and SDK 36?
1. No.
2. No.
3. No.

You should only access GetString if Job.Success is True.

Try the attached project.
The relevant code is:
B4X:
Private Sub Button1_Click
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("https://httpbin.org/get")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
    Else
        Log(j.ErrorMessage)
    End If
    j.Release
End Sub
 

Attachments

  • 1.zip
    13.6 KB · Views: 18
Upvote 0

Flavio SOuza

Member
Licensed User
Longtime User
Hi Erel,

Thank you so much for your help with my issue regarding the HttpJob error (sending message to waiting queue of uninitialized activity (submitjob)) on my Android 11 device.
I managed to resolve it by installing B4A from scratch on another PC and resetting my physical test device. I suspect the issue might have been related to my network or firewall settings, though I'm not entirely sure yet.

I'm very grateful for your help!
 
Upvote 0
Top