iOS Question As of today, is a .jar library still foreign to B4i ?

Krammig

Member
Licensed User
Longtime User
I know as of some years ago it was not possible to use either a .jar library or even Java code directly in an B4i project.

Is that still the case today ? No way of using code from an existing native Android project in B4i ?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Krammig

Member
Licensed User
Longtime User
Appreciate the replies.

When saying - You can reuse Android code but it needs to be written in B4X. - does that mean taking the selected java code (mostly business logic) and actually "rewriting" it or more or less "pasting" it into B4? ? = not sure if you mean A or J or i ?

Would be happy to read / try/experiment with any docs / examples / or whatever you could point me to on the site ?

In brief, I want to duplicate my native Android app but in B4i. The UI and other bits and pieces of course I can do in B4i but there is a lot of login written in Android Java and rather rewriting it all, it's a big complex app, it would be just great if there was a way of reusing for the most part existing code.

Cheers
 
Upvote 0

Krammig

Member
Licensed User
Longtime User
Hello DonManfred,

To ensure I am fully understanding this, it sounds like the Android Java code I have for the business logic part of the program, will have to be rewritten from scratch.

Is that correct ?

So if I am wanting to build an iPhone app in that case I can either do it using Swift 4 for example in the Apple world of Xcode, or I can do it in B4i. But either way I am going to have to rewrite all that Android Java code over again in whatever platform is chosen. Correct ?

Thanks
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Hello DonManfred,

To ensure I am fully understanding this, it sounds like the Android Java code I have for the business logic part of the program, will have to be rewritten from scratch.

Is that correct ?

So if I am wanting to build an iPhone app in that case I can either do it using Swift 4 for example in the Apple world of Xcode, or I can do it in B4i. But either way I am going to have to rewrite all that Android Java code over again in whatever platform is chosen. Correct ?

Thanks
When you read that you can reuse B4X code for both android and iOs it is correct. The code (source) can be reused in all three platforms (B4A, B4I, B4J) sometimes with some minor modifications.

What is not correct is how you understood the sentence.
Jar is not source code, but is compiled in bytecode. The code already compiled cannot be shared because it has already been translated (or rather compiled) for the specific platform and will work on that platform.

Source code in java is not the same as B4X source code. Java runs on many platforms but not iOs. All the java code or the compiled jar will not work on ios.

But if you have written a code in B4X, thanks to the B4X IDE, you can compile it to run on Android, iOs and Desktop (Windows, Linux, Mac)
 
Last edited:
Upvote 0

Krammig

Member
Licensed User
Longtime User
When you read that you can reuse B4X code for both android and iOs it is correct. The code (source) can be reused in all three platforms (B4A, B4I, B4J) sometimes with some minor modifications.

What is not correct is how you understood the sentence.
Jar is not source code, but is compiled in bytecode. The code already compiled cannot be shared because it has already been translated (or rather compiled) for the specific platform and will work on that platform.

Source code in java is not the same as B4X source code. Java runs on many platforms but not iOs. All the java code or the compiled jar will not work on ios.

But if you have written a code in B4X, thanks to the B4X IDE, you can compile it to run on Android, iOs and Desktop (Windows, Linux, Mac)


Thank you for your input on this.

One last question if you all don't mind.

Lets say I am able to convert the Java code to C++ using something like this (just as an example ) and presuming I fixed any issues that fall out of this.

tangiblesoftwaresolutions.com
Java to C++

Could I then take the C++ code and either compile that to a .so and use that in B4i or use the C++ directly in a B4i project ?

Cheers
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
If you have the source in Java you can try to translate it manually into b4x.
Is it a code that binds particular to APIs, services or specific hardware?

What does this code do?
 
Upvote 0

Krammig

Member
Licensed User
Longtime User
If you have the source in Java you can try to translate it manually into b4x.
Is it a code that binds particular to APIs, services or specific hardware?

What does this code do?

It is a few things yes, hardware binding, and just a lot of logic.
Manually translating is not really an option, there is just too much.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
Manually translating is not really an option
But unfortunately it is your only option. There is no tool that can transpile java to c++/obj-c automatically preserving everything. A complete set of different APIs is used to control the hardware for example. That is the advantage of writing it in B4X, where B4X will take care of using the correct API depending on the platform on compilation for you.

If you had written the android part in B4A, you're life would've been a lot easier I'm afraid.
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
For algorithms https://developers.google.com/j2objc can be interesting.

What J2ObjC is

J2ObjC is an open-source command-line tool from Google that translates Java source code to Objective-C for the iOS (iPhone/iPad) platform. This tool enables Java source to be part of an iOS application's build, as no editing of the generated files is necessary. The goal is to write an app's non-UI code (such as application logic and data models) in Java, which is then shared by web apps (using GWT), Android apps, and iOS apps.

Get Started

J2ObjC supports most Java language and runtime features required by client-side application developers, including exceptions, inner and anonymous classes, generic types, threads and reflection. JUnit test translation and execution is also supported.

What J2ObjC isn't

J2ObjC does not provide any sort of platform-independent UI toolkit, nor are there any plans to do so in the future. We believe that iOS UI code needs to be written in Objective-C, Objective-C++ or Swift using Apple's iOS SDK (Android UIs using Android's API, web app UIs using GWT, etc.).

J2ObjC cannot convert Android binary applications. Developers must have source code for their Android app, which they either own or are licensed to use.
 
Upvote 0
Top