Android Question Latest OkHttpUtils working with Android 4?

udg

Expert
Licensed User
Longtime User
Hi all.
I have an old widget of mine running on an Android 4.4 device. I have to update it now, but I recall something changed in the underlying lib which causes current OkHttpUtils working from Android 5 up.
So my question is: which is the latest B4A version sporting a copy of OkHttpUtils compatible with Android 4 devices? I plan to copy it to the Additonal Libs folder (while changing its name) and select it when compiling for my old device. For newer devices I will instead select the lib included in the installed IDE.

TIA
 

udg

Expert
Licensed User
Longtime User
I tried but failed. I will spend some more time when returning from my vacation.
What failed so far was:
1. Take OkHttpUtils.b4xlib from B4 11.00 installation
2. Unzip it, modified its Manifest in order to use A4_okhttp (the renamed OkHttp version from B411 Libraries)
3. Zipped again as A4_OkHttpUtils.b4xlib

The above resulted in object httpjob unknown. Same if the code from the b4xlib is used as moduless added to the widget.

As said, I'm ready to spend a few days out, so no time to investigate further today.
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I used these from the older B4A version

OkHttp.jar
OkHttp.xml
okhttp-3.12.12.jar
OkHttpUtils2.b4xlib
okio-1.17.5.jar
 
  • Like
Reactions: udg
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you. I am not sure anymore about my exact steps..
Probably I missed the proper okio-* jar or simply messed with a few attempts based on other old installations.
Anyway, I'm ready to leave now; my widget can wait :)
 
Upvote 0

udg

Expert
Licensed User
Longtime User
One last comment before leaving.
I suspect that in some way my original plan is lacking something important. There's something ringing in my head telling me that I skipped a step or two.
I'm sure @Erel will amend the whole process I described for those lacking an old copy of B4A (firing B4A 11.0 with its OkHttpUtils2 v. 2.96, everything compiles and works ok).
My attempt was to prepare an eviroment for the latest B4A release where we could compile for our old Android 4 devices (for what concerns okhttp & friends).
 
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
My B4A 11.8 is just set with the older libs for Android 4. If I want the new libs I have to copy / delete by hand. I can see your idea of having a way to switch easily.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I used these from the older B4A version

OkHttp.jar
OkHttp.xml
okhttp-3.12.12.jar
OkHttpUtils2.b4xlib
okio-1.17.5.jar
How exactly you do it?

I tried this
1. rename these files, add prefix old-
2. copy it to additional lib
3. change manifest.txt from file OkHttpUtils2.b4xlib into like this
Version=2.96
B4A.DependsOn=old-OkHttp, StringUtils
B4J.DependsOn=jStringUtils, old-OkHttp
B4i.DependsOn=iHttp, iStringUtils

Still got the same error.

The strange thing is, my app doesn't include OKHttp Library(see attachment) but error point to that library.
 

Attachments

  • SS.png
    SS.png
    15.3 KB · Views: 39
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
I did this. Copy these original files from the 'internal' libs folder to a backup folder (B4A 11.8)
OkHttp.jar
OkHttp.xml
okhttp-4.9.0.jar
OkHttpUtils2.b4xlib
okio-2.8.0.jar

Then copy these older files to the 'internal' libs folder (B4A 11.2)
OkHttp.jar
OkHttp.xml
okhttp-3.12.12.jar
OkHttpUtils2.b4xlib
okio-1.17.5.jar

I did NOT edit any manifest files.
 
Last edited:
Upvote 0

JakeBullet70

Well-Known Member
Licensed User
Longtime User
The strange thing is, my app doesn't include OKHttp Library(see attachment) but error point to that library.

If one lib is a dependency of another lib it seems to not show up.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I did this. Copy these original files from the 'internal' libs folder to a backup folder
OkHttp.jar
OkHttp.xml
okhttp-4.9.0.jar
OkHttpUtils2.b4xlib
okio-2.8.0.jar

Then copy these older files to the 'internal' libs folder
OkHttp.jar
OkHttp.xml
okhttp-3.12.12.jar
OkHttpUtils2.b4xlib
okio-1.17.5.jar

I did NOT edit any manifest files.
That's do the trick, thanks.

Anyway, I will keep old OkHttp library from B4A 11.2 in B4A 11.8. Seem don't need new OkHttp Library.
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
I did this. Copy these original files from the 'internal' libs folder to a backup folder (B4A 11.8)
OkHttp.jar
OkHttp.xml
okhttp-4.9.0.jar
OkHttpUtils2.b4xlib
okio-2.8.0.jar

Then copy these older files to the 'internal' libs folder (B4A 11.2)
OkHttp.jar
OkHttp.xml
okhttp-3.12.12.jar
OkHttpUtils2.b4xlib
okio-1.17.5.jar

I did NOT edit any manifest files.
test solution, and work perfectly
 
Upvote 0

udg

Expert
Licensed User
Longtime User
@Erel: : can you briefly explain why it didn't suffice to copy (from an earlier version of B4A's Internal libs) the above listed files to current Additional folder?
I seem to recall that Additional supersedes Internal when it finds identical named files.

In my original attempt I avoided same-name files at all renaming OkHttp to A4OkHttp and OkHttpUtils2 to A4OkHttpUtils2 (changing its Manifest accordingly), but failed.

I ask this to have a better understanding of the inner workings of those libs and their relations.
I guess OkHttpUtils makes use of OkHttp which in turn calls okhttp-x.y.z and finally okio-x1.y1.z1
Is there anything hard-coded which prevents the simple copy into Additional folder of older libs to work?

Again, @JakeBullet70 's solution works well (as much as having installed an old copy of the B4A IDE), so this post is just to heighten my knowledge.
As a wish, you may want to make it available a lib encompassing all that is needed to compile for Android 4 devices. It will be useful for those not having an earlier B4A version handy. Yes, I know where the Wish section is in our Forum :)

TIA
 
Upvote 0

udg

Expert
Licensed User
Longtime User
My point was that, as far as I recall, when you have two version of the same lib (same name), the one in the Additional should supersedes the one in Iternal.
In my attempt I changed the name of the one put in the Additional folder so (it was my goal) the two could coexist. But something seems to prevent the correct working of the files copied in the Additional folder.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
So, is it the other way around? :)
Internal prevails on Additional? Ok, this explains the case where the name are unchanged.
But there should be more to prevent the successful coexistence of two versions of the same lib when they have different names (one in Internal and the other one in Additional).
Do you have any previous experience on it? Any hint?

TIA
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you, @Erel.
So this means that originally I messed up somehow with the libs naming

Can you please confirm that the following should work?
Applied to a copy of the old libraries in Additional folder
Rename OkHttp (jar and xml) - e.g. A4OkHttp
Modify OkHttpUtils2's Manifest in order to depend on that newly named okhttp (e.g. A4OkHttp)
Rename OkHttpUtils2 - e.g A4OkHttpUtils2
okhttp-3.12.12.jar - unchanged since its name doesn't conflict with new lib
okio-1.17.5.jar - same as above

If the above is correct, when in a need to compile for Android4 devices I will select A4OkHttpUtils otherwise the standard (and alaways updated with the IDE) OkHttpUtils.

TIA
 
Upvote 0
Top