Android Question B4A And B4X

bocker77

Active Member
Licensed User
Longtime User
I hope this isn't a redundant question but I have been coding in B4A for a couple of years now and am looking into graduating to B4X. I may want to make an app that I wrote to be able to run on IOS as well as Android. After looking at Erel's tutorials I am a little confused. So I have a couple of questions.

I assume that I can create B4X code with only having B4A installed. Is this correct? I assume yes by creating a project with B4XPages.

Is there a way to convert my B4A code over to B4X with not too much effort or do I have to cut and paste my B4A code into my new project where appropriate?

Also I believe I would need to redo my Views as B4X Views in the Designer which would only make sense.

I read somewhere in the forum that around 90% of my code is portable. I would assume that the compiler will inform me of the code that will not port over when B4X is installed.

Are all of the libraries that I am using in my B4A program compatible with B4X when compiling for IOS or are there different B4I libraries?
 

LucaMs

Expert
Licensed User
Longtime User
I assume that I can create B4X code with only having B4A installed. Is this correct? I assume yes by creating a project with B4XPages.

Is there a way to convert my B4A code over to B4X with not too much effort or do I have to cut and paste my B4A code into my new project where appropriate?
B4X code does not exist. It's a bit like a "programming style"; it means using objects and functions common to both B4A, B4J and B4i as much as possible, that is the B4XView, the XUI library, B4XPages and more.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Let me give my point of view from my understanding.
I hope this isn't a redundant question but I have been coding in B4A for a couple of years now and am looking into graduating to B4X. I may want to make an app that I wrote to be able to run on IOS as well as Android. After looking at Erel's tutorials I am a little confused. So I have a couple of questions.
Good move. You may also want to use B4J to create a windows desktop version. You will see the magic at no time.

I assume that I can create B4X code with only having B4A installed. Is this correct? I assume yes by creating a project with B4XPages.
Yes when you choose to start from B4XPages template, you automatically have 3 folders for B4A, B4i and B4J projects.

Is there a way to convert my B4A code over to B4X with not too much effort or do I have to cut and paste my B4A code into my new project where appropriate?
Yes. One of the techniques that commonly use is to use Module or Class that can be shared between the 3 platforms.

Also I believe I would need to redo my Views as B4X Views in the Designer which would only make sense.
My experience is I usually rename panels and pane (B4J) as B4XView when I am using xCustomListView to create List Items. I still can use Labels which exists in all the 3 platforms. I would also choose to use B4XFloatTextField instead of EditText or TextField.

I read somewhere in the forum that around 90% of my code is portable. I would assume that the compiler will inform me of the code that will not port over when B4X is installed.
Yes. If you open B4i project which contains B4A specific code, the IDE will show red colour error in the Logs. If you use conditional compile tags like #If B4A, then the code will appear grayed in B4i IDE.

Are all of the libraries that I am using in my B4A program compatible with B4X when compiling for IOS or are there different B4I libraries?
Not all but almost all. There may exist however an alternative workaround for few very uncommon library which I very seldom come across. Most of the apps I developed are using SQL and OkHttpUtils2 which have libraries for both B4A and B4i. Example: OkHttpUtils2 (B4A) equivalent to iOkHttpUtils2 (B4i) and also jOkHttpUtils2 (B4J). Other example like B4XGifView for all 3 platforms. Just copy the same B4XGifView.b4xlib to all locations of these 3 IDEs additional libraries folders to use it.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Just copy the same B4XGifView.b4xlib to all locations of these 3 IDEs additional libraries folders to use it.
No !
You should setup this structure for additional libraries.
Only one folder for b4xlib libraries. The IDEs know where to look for.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
My concern is platform specific libraries and inside one same folder contains 3 equivalent libraries would make me confused.
Platform specific libraries must be in their platform folder, only libraries valid for all three platforms, B4A, B4i and B4J, should be in the B4X folder.

1622531191204.png


In my structure I added another folder for xml files for b4xlib libraries.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
So if I wanted to make my app available on iPhone's I would need to purchase a B4I license and do all the wonderful advice above. Thanks to all who responded in clearing this up for me.
 
Upvote 0

Kevin Hartin

Active Member
Licensed User
I hope this isn't a redundant question but I have been coding in B4A for a couple of years now and am looking into graduating to B4X. I may want to make an app that I wrote to be able to run on IOS as well as Android. After looking at Erel's tutorials I am a little confused. So I have a couple of questions.

I assume that I can create B4X code with only having B4A installed. Is this correct? I assume yes by creating a project with B4XPages.

Is there a way to convert my B4A code over to B4X with not too much effort or do I have to cut and paste my B4A code into my new project where appropriate?

Also I believe I would need to redo my Views as B4X Views in the Designer which would only make sense.

I read somewhere in the forum that around 90% of my code is portable. I would assume that the compiler will inform me of the code that will not port over when B4X is installed.

Are all of the libraries that I am using in my B4A program compatible with B4X when compiling for IOS or are there different B4I libraries?
I recently made the exact same transition and still have some confusion between the way I did my first apps in B4A and porting over to B4I. B4X Pages has certainly made this much easier but I still have some confusion between the Android and Apple ways of working.

Kev
 
Upvote 0

Dave G

Active Member
Licensed User
I ported a C# Xamarin app to B4X XUIviews for B4A, B4I and B4J. 90% code sharing. Conditional compilation was easy and effective to handle the few platform specific issues e.g. soft keyboard handling, system directory names. It's called Winch Calc and can be found on Google Play and Apple Store.

It handles orientation changes and screen scaling in the respective Designer scripts. Code and design turned out much cleaner than Xamarin C#. iOS is still a pain to work with, but B4X addresses much of the issues I had with Xamarin with the B4X Build Server (don't need a Mac to develop).

Best of luck
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
All of the above advice is good. Just wade in and go for it. You may be able to cut and paste your existing layouts into B4X pages.

Key to remember:

Always Dim your variables as BXView if it is not already a B4X control.
1624884378055.png

Some things are just different. Between Devices.
You will need to use conditional compilation ie:
1624884580200.png

Personally, when not working on the UI I prefer to develop in B4J. It is just easier. Even if I am not going to release a B4J version. I will put large chunks of code that don't work in B4J behind
#IF NOT(B4J)
just so I can work in B4J.

Regardless of which you dev in, make sure you get your layouts the way you want in ONE app before copying them to another app. Remember if you change the layout you have to change it in each program separately.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Why? I have always wondered why that option was there.
To have cross-platform objects !
B4XView is a superset above standard platform specific objects.
This allows you to use a same code for different platforms, with same properties, which might be different in the specific platform.
When you place an object in the Designer and use Generate you have the choice between the platform specific object or B4XView.
My advice, use where ever you can B4XView !
It will simplify your work for now and in the future !
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
So in your graphic, you place a button then dim as a b4xView?

Kev
Exactly! Then that button will have the same properties across all three platvforms.
And remember - not always the same in each one A Panel in one is a Pane in another but both can be a B4XView.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
I recently made the exact same transition and still have some confusion between the way I did my first apps in B4A and porting over to B4I. B4X Pages has certainly made this much easier but I still have some confusion between the Android and Apple ways of working.

Kev
You can probably cut and past your layouts in to the new app. even any designer code should work. Most Standard views are NOT b4x. They are standard views. As mentioned above just DIM the standard views as B4XViews. If can't pay for B4i right now I suggest you install B4J and you can experiment a little with getting things working between Android and Windows.
Spend an hour or two experimenting, you can always throw it away. Create a B4XPages project, copy and paste a layout from your old app, right click and create the appropriate B4XViews and events, then Past your code and see what happens. Then open the B4J version, past the layout again and save it, then run it and see what happens.
This of course is assuming it is not too phone specific. While many are the same you may find that some properties of a B4XViews are different and need to be modified.

You can also do different layouts for different programs, my current app, for example uses a hand scanner in Windows (B4J so the scan page just has a Text Box to accept the scan data. The Android and IOS version uses the camera for scanning so completely different layout. Completely different events, That is all handled with conditional compilation (#IF),

But the code that handles the data is the same
 
Upvote 0
Top