views:

165

answers:

1

Hi everyone,

I'm moving away from strict Android development and wanting to create iPhone applications. My understanding is that I can code the backend of iOS applications in C/C++ and also that I can use the NDK to include C/C++ code in Android apps. My question however is how? I've googled quite a bit and I can't find any clear and concise answers. When looking at sample code for the NDK, it seems that all the function names etc. are Android (or at least Java) specific and so I would not be able to use this C/C++ backend to develop an iPhone frontend? I'd appreciate some clarification on this issue and if at all available some code to help me out? (even just a simple Hello World that reads a string from a C/C++ file and displays it in an iOS and Android app).

Thanks guys Chris

A: 

While the sentiment is sound (you are following the policy of Don't Repeat Yourself), it's only pragmatic if what you can share that code in an efficient manner. In this case, it's not really possible to have a "write once" approach to cross-platform development where the code for two platforms needs to be written in different languages (C/C++/Obj-C on iPhone, Java for Android).

You'll be better off writing two different codebases in this case (in two different languages). Word of advice: don't write your Java code like it's C++, or your C++ code like it's Java. I worked at a company a number of years ago who had a product they "ported" from Java to C++, and they didn't write the C++ code like it was C++, and it caused all sorts of problems, not to mention being hard to read.

Shaggy Frog
Thanks for the response! I was just hoping that I would be able to code a Viterbi or Baum Welch restimation algorithm in C++ and just access if from Android. It just seems such a shame to have to write something as time-critical (it's for a real-time application) not only in Java, but repeat the same algorithm twice. In any case, thanks for the advice.
Chris Robinson
Actually, time-critical/performance-critical components are exactly the kinds of things you *should* be writing natively for each device. (It sounds like you're writing code to implement a Hidden Markov Model)
Shaggy Frog
Correct :p I guess I was just trying to be lazy and save myself writing code twice. Obviously I'll be writing the code natively for the iPhone but it's just a bit of a pain to have to write code for each Android device I want to support rather than just be able to invoke code from the VM. If I was writing a game for instance, (which I am also doing) that implements GAs to control AI, it's also a bit of a pain to have to implement this twice, so this is why I was hoping for an easy solution.
Chris Robinson
Laziness is a good quality for a programmer (it's one of the Three Virtues), but you have to be pragmatic about when you apply it. Not wanting to write code twice is a good attitude. However, when that makes you jump through huge hoops because you're trying to write one set of code for two completely different languages, then the effort is not worth the gain.
Shaggy Frog