Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming for Android in a 100% C++ Environment?

I've been working on a game engine runtime environment in C++ for my future games, and have started to consider android as a platform. I noticed that it was tightly bound to Java and uses Java VMs heavily.

But is it possible to sustain a full C++ runtime environment in Android NDK? I have nothing against Java and am prepared to use it if I have to, but performance is one of my prime concerns (I intend for my games to be resource-intensive), especially on phones.

And if a full C++ environment is possible, how exactly would I implement it in Eclipse Indigo CDT? Would I be able to create a compiled game executable for Android ahead of time for maximum performance? And would there be any additional plugins I'd need to install in Eclipse? Could I use MinGW for compiling my games, or would I need to use a different compiler? If I had to use Java in one way or another, would compilation of the C++ code even be required? These are all questions I'd like to answer to get a sturdy development environment going in the Eclipse IDE.

Please know that I'm still fairly new to Android development, and multiplatform programming in general. My goal is to create a game engine that'll take the most advantage of the new hardware out there, especially on phones!

Thanks for any advice you guys can give!

like image 828
AutoBotAM Avatar asked Oct 01 '11 18:10

AutoBotAM


People also ask

Can I program with C in Android?

The Android Native Development KitAndroid Native Development KitThe Native Development Kit (NDK) is a set of tools that allows you to use C and C++ code with Android, and provides platform libraries you can use to manage native activities and access physical device components, such as sensors and touch input.https://developer.android.com › ndk › guidesGet started with the NDK - Android Developers (NDK): a toolset that allows you to use C and C++ code with Android, and provides platform libraries that allow you to manage native activities and access physical device components, such as sensors and touch input.

Which compiler is best for C programming in mobile?

C4droid is a user-friendly (but powerful) C/C++ IDE + C/C++ compiler for Android. Customizable GUI, choose where to place tabs and buttons by yourself, themes are also supported.

Can Android apps be coded in C++?

C++ can be used for Android App Development using the Android Native Development Kit(NDK). However, an app cannot be created totally using C++ and the NDK is used to implement parts of the app in C++ native code. This helps in using C++ code libraries for the app as required.

Can I make app with C?

The NDK is a toolset that enables the development of Android apps using C, C++ and other native code languages, compiling code into applications that can run on Android devices.


2 Answers

NativeActivity, added in Android 2.3 (API 9) might be what you're looking for in terms of writing Android games using only C++. http://developer.android.com/reference/android/app/NativeActivity.html

However since you say you're new to this you may want to start with one of the currently available Android game engines instead of writing your own right away. Mobile devices have a very different set of constraints than other platforms. A phone isn't very useful if the battery dies mid-afternoon, so starting a project with the stated goal of being "resource-intensive" is already getting off to a bad start. Few people will want to play your games for 20 minutes here and there if it means they won't be able to make a phone call in the evening.

If what you meant is that you are shooting for high-end graphics, keep in mind that devices have a wide range of capability in this area and targeting only the high end limits your audience. Different GPUs have very different strategies and performance characteristics and all have cases where they shine or lag behind. The most successful mobile games aren't the ones with the highest polycounts or the most complex lighting shaders, they're the games that achieve a consistently smooth framerate and have a distinctive style.

Have a look at some of the existing game engines for Android and try them out. Write a couple small games to take them for a test drive and see where they do and don't mesh with what you're trying to do. If you find yourself feeling limited with what's available, take what you've learned and try to write your own engine that fits with the types of games you want to make.

Here are some links to get you started. These engines power some very popular games on Android Market and many developers have found them useful:

http://www.andengine.org/ andengine is written in Java and is open source.

http://unity3d.com/ Unity is based on C# and Mono.

http://www.madewithmarmalade.com/ Marmalade, formerly Airplay SDK is based on C++.

like image 52
adamp Avatar answered Oct 09 '22 01:10

adamp


The answer you want to pay close attention to is @adamp's. Ignore his answer at your own peril.

To address a couple of other points in your question, though:

Would I be able to create a compiled game executable for Android ahead of time for maximum performance?

No, insofar as Android does not use "compiled game executables". Your C/C++ code will be compiled into a Linux shared object (.so) file and packaged with other stuff (like your manifest) in an APK file. Compiling the .so will be ahead of time, though.

Could I use MinGW for compiling my games would I need to use a different compiler?

I get the distinct impression that you will claw your eyes out trying to do NDK development in Cygwin on Windows. I heartily encourage you to do your NDK development on OS X or Linux. At least set up a VirtualBox with Ubuntu or something in it to do your NDK compiles.

Regardless, the NDK comes with its own GCC compiler. AFAIK, MinGW is not a cross-compiler, and most Android devices are not running on x86 CPUs.

If I had to use Java in one way or another, would compilation of the C++ code even be required?

Yes. Now, for Honeycomb, you have the option of using Renderscript for OpenGL work -- that amounts to a C99 environment whose code you will not need to compile with the NDK.

like image 28
CommonsWare Avatar answered Oct 09 '22 01:10

CommonsWare