Build existing C++ project for iOS and Android platform - android

I work for an existing C++ project. This project serves as a component of a larger software.
This project is supposed to support multi platforms. With all the source code and header files, the code can be built under windows, Linux and Mac. And I have .dll, .so and .dylib files for reuse.
But how about iOS and Android? I read pages and pages but I still have no idea. I cannot see how those SO Q&As and blogs relate to my problem.

Related

How do I create a shared library in C++ for both Android and iOS?

I am using LibGDX to write apps for both Android and iOS and I want to be able to add C++ code to my apps to optimize certain parts and to port some functions etc.
I have been searching the internet and tried to follow some tutorials, but did not find what I need.
How can I write a very basic C++ library which I can load in LibGDX? Which tools do I need to use? Visual Studio? I develop in Android Studio.
I think that I need an .so file for Android and an .a file for iOS, is that correct?
On both platforms, it's possible to include a precompiled library as well as C++ source code directly.
On Android, you'll want to look into using the Android NDK. This allows you to include native C/C++ code that can bridge over to Java. The connection between Java and C/C++ is managed with the JNI. It's a fairly tedious, awkward system for communicating between C++ and Java. You'll want to look into setting up an Android.mk makefile that specifies how to include your library (or source code) into your build.
On iOS, it's a little more tightly linked. You can have Objective-C++ files that can run both C++ and Objective-C code. If you're using Swift, it's a little different (bridging between Objective-C++ and Swift).
In some cases, when the platform (Android/iOS) provides functionality that is superior to what is possible or realistic with C++, you might find yourself architecting the code such that your C++ can reach out to the platform as needed. This means that you might have headers with separate implementation files per platform.
thing.h
thing_android.cpp
thing_ios.mm
The android app's Android.mk file will include thing_android.cpp (but not thing_ios.mm). This file could cross the JNI bridge to talk to Java as needed, whenever you need something from Android SDK.
The iOS app will include thing_ios.mm (but not thing_android.cpp). The .mm extension signifies Objective-C++, so that file could directly call powerful Cocoa libraries as needed.
Finally, on all platforms, you'll want to be sure to either scale back your usage of C++ to the lowest common denominator platform. In other words, if iOS supports a particular feature of C++, and Android doesn't, then you cannot use that particular feature.

Which is the easiest way to migrate a C++ application for Android and iOS?

I have a C++ application that uses Qt 4.8 and OpenCV 2.4.2. It is developped using Visual Studio. I have to migrate this application for Android and iOS.
Which is the plan to follow? I should make the minimal change to the existing code.
Unfortunately, there’s no easy answer to this. The fact that you’re using Qt is a great start, and using it as much as possible will go a long way towards making your code portable from Windows to other OSes.
I would look at upgrading first to Qt 5, as Qt introduced great support for both iOS and Android.
After that, the build chain is going to be your next obstacle. It looks like the Qt Visual Studio Add-in has an option to export a .pri file from the VC++ project, which would be a very handy starting point. Generate the .pri file and compare it to the project file created by QtCreator for an Android and iOS app, and try to copy the mobile-specific parts into your generated .pri file.
Other potential pitfalls are:
Visual C++ is a much more permissive compiler than gcc (Android) or Clang (iOS and Android)
Your app's dependencies must all be cross-platform as well. I’m sure OpenCV is, but it’s something to keep in mind
On iOS, all libraries must be linked statically

Can monodroid .so files be managed .NET code?

Is the .so files generated by Xamarin Monodroid (libmonodroid.so and libmonosgen-2.0.so) managed code or native code? From this SO post it appears they are actually .NET IL binaries (not native machine code). An answer even suggested the Xamarin.Android binaries is JIT'ed and can be opened in any .NET decompiler. However, this doesn't seem to work with dotPeak or ILSpy based on my investigation.
However, this other post on another SE site appears to contradict this. It should be noted that they are referring to Android NDK in general.
So, should the native library be opened on a .NET decompiler or dissembler such as Hopper and IDA Pro (giving you assembly code)?
Those files, libmonodroid.so and libmonosgen-2.0.so are native libraries and are the core libs of Mono and Xamarin.Android, these of course are based upon the ABI/ARCH types that you are supporting within your APP.
Xamarin.Android application packages have the same structure and layout as normal Android packages, with the following additions:
The application assemblies (containing IL) are stored uncompressed within the assemblies folder.
Native libraries containing the Mono runtime are also included and provide a parallel runtime to the Android Runtime (ART) and the bridge to talk from/to MONO <-> ART.
In Xamarin.Android 5.1 and above, you have the option to AOT your assemblies like Xamarin.iOS does always due to Apple's requirement of no JIT/dynimically generated code on iOS. This option for Android is defined in the Packaging Properties and by default is false. So for assemblies that have been AOT'd, machine code based on ABI/ARCH type has been generated and replaced the APPs C# IL.

How to embed jars to make them usable in Xamarin cross-platform App

I am trying to port my Android Application, developed with Google Android ADT, in Xamarin to make it cross-platform and runnable on iOS devices.
I am ready to translate the needed code from Java to C# but I don't know the best way to manage external libraries.
I am using 3 jars in my App:
android-support-v4.jar
mysql-connector-java-3.0.17-ga-bin.jar
YouTubeAndroidPlayerApi.jar
I tried to embed them following these instructions:
http://docs.xamarin.com/guides/android/advanced_topics/java_integration_overview/binding_a_java_library_%28.jar%29
but I'm getting some compilation errors. Here's one of them:
'Com.Mysql.Jdbc.Util' in '[..]\AndroidHelloWorld\JavaBindingLibrary\obj\Release\generated\src\Com.Mysql.Jdbc.Util.cs'
is in conflict with
'Com.Mysql.Jdbc.Util' in '[..]\AndroidHelloWorld\JavaBindingLibrary\obj\Release\generated\src\Com.Mysql.Jdbc.Util.BaseBugReport.cs'
I don't know if it's worth going on trying to fix the errors or it's better to use native libraries for iOS.
As you'll have separate projects for each platform, I would just use the appropriate jars, as there can be differences in the way Youtube works, for example, that would make the android jar unusable in an iOS project.
But about the errors you encountered, it's worth reading this link thoroughly.
You won't be able to use any of your Android specific code or libraries on iOS.
You have two basic options for cross platform development, to create a Xamarin Forms project or create a iOS, Android and Shared project.
If you decide to go with Xamarin Forms you will need to:
* Extract your platform independent code into a shared PCL project
* Redevelop your front end in Xamarin Forms
If you decide to go with separate projects you will need to:
* Extract your platform independent code into a shared PCL project
* Develop an iOS front end project

Deploying SWIG dependent dll's with Android Application

I would like to use a .jar file generated by SWIG in an Android application. What is the best way to deploy all of the underlying dll's with the Android application?
In a desktop environment, my PATH variable includes the folder containing these dll's.
DLL is a Windows technology. Android is not Windows. Android is based on Linux. You would be looking for .so libraries. More accurately, you will be looking for the C/C++ source code behind those libraries, so you can cross-compile them for Android chipsets (e.g., ARM). That will be accomplished via the Native Development Kit.

Categories

Resources