Android and iOS are often imagined as two arena boxers, each in its own corner, with nothing in common. Yet, if you’ll probe OS’ family tree, you’ll find an often forgotten kinship. It turns out their creators faced similar challenges, and both turned their heads to the same direction. We all know Android is built on a Linux kernel, yet it’s often overlooked that iOS’ origins go back to BSD and UNIX.
Why should you care? you should if you plan on delivering a mobile piece of code that will have enough of the fuzzy term “Significant Shared Logic”.
At first glance, we sometimes tend to consider our app’s main feature as the most difficult, time and budget consuming task. However, when you dive deeper, you might spot the infrastructure-related, not too sexy, silent “Gantt Busters” components that usually include supporting services like storage, scheduling, event handling, configuration, etc. Here at Namogoo, when we first sat down to design our mobile solution and drafted the core components, we realized that many can be categorized as “Shared Logic” – components that should act the same, for Android and iOS. It also turns out that if you’ll design your code with cohesion in mind, it will bring out even more of these components.
So, can you share code between these two related cousins? The simple answer is yes. It’s true, you’ll need to get dirty with C++ and JNI but let me tell you, it’s not too often we get thrilled over simply compiling code, yet we’ll never forget the stupid smiles spreading over our faces when the Android C++ code just compiled and ran (!) under Xcode. It suddenly stroke us: we’ve just squeezed over a month and a half of work, into half an hour.
Indeed, SDKs and alike are more suitable for code sharing than GUI-centric apps and games. They have their own tools and platforms that support effective cross platform app development. Obviously, using such tools would have added yet another layer between us and the final code that actually runs. For Namogoo, as a company that feels more comfortable close to the metal, this was less appealing and we chose not to use them.
Tips? Use standard C++11. Keep in mind that Android integration with C++ is harder than iOS’. Nicely wrap your platform-specific code. And smile – you’ll probably be saving time and money for your company in development and maintenance. In addition, avoiding features forking between platforms along the way is also a big benefit as we all know – when you have more than one code base, it will happen.
Obviously, as mentioned earlier, it’s not beneficiary for all projects, but take your time, design your solution carefully and search for common logic. It’s there, waiting to be discovered.