C or C++ for cross-platform mobile development? - android

For a cross-platform project on iOS, Android and Windows I originally wrote some underlying classes in C++. From what I understand however, I will have to write an objective-C wrapper to allow the swift iPhone project to work in xcode. Would it make more sense then that I simply rewrite all of the original framework in C or would simply wrapping it in C be a better solution. No problem either way just attempting to determine the best way to keep the code valid.
Also telling me to use a cross-platform mobile development SDK is not helpful.

I would recommend writing in C++ 11. It's more modern, has more support online, and you can even compile everything with Cmake. There are many tools out there to help you with this. My company is using this to develop a framework that compiles on the following platforms:
iOS, Mac OS X, Android (ARM, x86, x64), Windows (x86, x64), Linux (x86, x64)
You can also find a tool here to help you with cross platform toolchains, so that code you compile is easily ready for multiple platforms: https://github.com/ruslo/polly

Related

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

Control theory implemented in C++

I am doing Android programming using Java-Eclipse Luna on Windows 8.1, also, I am using native environment (C++). As a next step in my project, I have to control a mobile robot by building an app in Android.
My question is, are there any already-implemented control theory libraries in C++ that I just import and use in my C++ code? I need PID, LQR, LQG ... etc.
Check out ROS (Robot Operating System), it contains plenty of algorithms and useful tools for robotic applications.

Call C++ executables insider Android

I am now porting a linux C++ library to Android using JNI. The library porting itself is very straightforward, and I have built a C++ library that can be invoked by Android via JNI. Now my problem is to verify that the library works well in Android environment as well. In the linux development environment, some unit-tests and regression tests are already available. So I was wondering whether I can test the library by taking advantage of all the available unit-test and regression test programs. For example, in linux I have the following binaries:
mylib.so
my_unit_test
my_regression_test
Then for Android, I will first built mylib_android.so. Then, can I build my_unit_test_android and my_regression_test_android for Android platform? If it possible, how can I invoke them in the Android simulator and the real device?I have little knowledge about Android, and any ideas will be appreciated.
Transform them to libraries with single function and write Android app that will use them.

Port .NET dll to different platforms

I have a dll based on .NET 2.0 with full source code access.
So I can build it in VS2010.
I need to port this to Android/iOS/MacOS.
As a result I expect some equivalent of dll for each platform.
So another programmer can link (doesn't matter how) this equivalent to his own project at one of that targeted platform.
For example I ran MonoDevelop on Mac and don't see how I can build my .NET project and to receive such equivalent of dll.
So I need help to find solution and understand what to do to receive requierd result.
There are CLI implementations, primarily Mono, that work on both iOS and droid. The simplest tools here are MonoTouch and Mono for Android, both available from Xamarin. With these tools, you can build and test your dll targetting the relevant frameworks. Another programmer, again using the MonoTouch or Mono for Android tools, can reference those dlls, and build their application, with all the tools necessary to package and deploy (side-loading or via, say, the device's store) an application using that library. This deployment will typically also include all the runtime/framework pieces needed by the application.
MonoTouch makes use of the MonoDevelop IDE, so will be familiar to you as a MonoDevelop user. Mono for Android can do that (i.e. be hosted inside MonoDevelop), but can also be used inside Visual Studio.
Running .NET code requires a .NET runtime to be installed. Neither Android nor iOS devices come with such a runtime preinstalled.
In theory, you could install the Mono Runtime (a open-source .NET alternative) on an Android device or a jailbroken iPhone/iPad. However, as I understand it, you're looking for a way to create a library to give developers, so this isn't a good solution.
However, what could work is creating a library with MonoTouch. MonoTouch compiles your .NET code to a binary that iOS devices can use - regardless if they're jailbroken or not, without needing a runtime installed.
If you follow best practices, you might port your library successfully, such as
http://sharpsnmplib.codeplex.com/discussions/390251
However, it purely depends on the characteristics of your library, which you does not mention yet.

gcc -x objective-c with Android SDK

Since Objective-C exists and is supported even in MinGW, by passing -x objective-c, is there a hack to achieve this with Android SDK? I've did a rudimentary test on a colleague's machine where it appears that language objective-cis not supported.
I am not interested in getting UIKit or AppKit, or even Foundation, to work; I've written most of an OpenGLES game in Objective-C, and successfully ported it to Mac OS X and Windows; I am fairly certain I could easily port it to GNU/Linux once I get time to figure out enough of GNUStep (and even without it, I could create the classes to get the game running).
I'm just interested in the base language and basic runtime (including properties, if possible); even NSObject can be easily written to the extent I need it.
In the meantime, I've managed to compile some Objective-C code, and have written a guide for this:
Developing Objective-C apps for Android using Mac OS X
There are more details in my answer below.
The Apportable platform includes a Clang compiler integration with the Android NDK. It also includes a bunch of other useful features if you want to go beyond basic Objective-C language and runtime support.
You probably have to recompile the ndk gcc's sources with that option enabled. At the extreme you might have to find the code for that option upstream and add it to the ndk gcc's sources.
Porting runtime libraries to work on top of bionic instead of glibc may be more interesting.
Note that android doesn't really handle pure-native binaries very well, you will need to either be called as a jni library from a java wrapper application which you will have to call back up through for audio or forked and exec'd off of one (not recommended, and leaving you with device-dependent hacks for audio).
There is this Google Code project: http://code.google.com/p/android-gcc-objc2-0/ however I have not tested it yet.
Also, I have inquired on the Cocotron mailing list whether or not this compiler is usable with Cocotron's Foundation and CoreFoundation; one person responded that it is not, and that he has worked on the problem: http://groups.google.com/group/cocotron-dev/browse_thread/thread/448355f2a6c9c28e#
In the meantime, I've managed to compile some Objective-C code, and have written a guide for this:
* Developing Objective-C apps for Android using Mac OS X
Clang is included in NDK nowadays if that's all you need.

Categories

Resources