Write applications in C or C++ for Android? [closed] - c++

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm trying to develop/port a game to Android, but it's in C, and Android supports Java, but I'm sure there must be a way to get a C app on there, anyone knows of a way to accomplish this?

For anyone coming to this via Google, note that starting from SDK 1.6 Android now has an official native SDK.
You can download the Android NDK (Native Development Kit) from here:
https://developer.android.com/ndk/downloads/index.html
Also there is an blog post about the NDK:
http://android-developers.blogspot.com/2009/06/introducing-android-15-ndk-release-1.html

The Android NDK is a toolset that lets you implement parts of your app in native code, using languages such as C and C++. For certain types of apps, this can help you reuse code libraries written in those languages.
For more info on how to get started with native development, follow this link.
Sample applications can be found here.

Normally, you have to:
Install Google Android NDK. It
contains libs, headers, makfile
examples and gcc toolchain
Build an executable from your C code
for ARM, optimize and link it with
provided libs if required
Connect to a phone using provided
adb interface and test your
executable
If you are looking to sell an app:
Build a library from your C code
Create simple Java code which will
use this library
Embed this library into application
package file
Test your app
Sell it or distribute it for free

Google has released a Native Development Kit (NDK) (according to http://www.youtube.com/watch?v=Z5whfaLH1-E at 00:07:30).
Hopefully the information will be updated on the google groups page (http://groups.google.com/group/android-ndk), as it says it hasn't been released yet.
I'm not sure where to get a simple download for it, but I've heard that you can get a copy of the NDK from Google's Git repository under the donut branch.

The official position seems to be that this isn't something you'd ever "want to do". See this thread on the Android Developers list. Google envisage android running on a variety of different devices (CPUs, displays, etc). The best way to enable development is therefore to use (portable) managed code that targets the Dalvik VM. For this reason, the Android SDK doesn't support C/C++.
BUT, take a look at this page:
Android includes a set of C/C++
libraries used by various components
of the Android system. These
capabilities are exposed to developers
through the Android application
framework.
The managed application framework appears to be layered on-top of these libraries. The page goes on to list the C/C++ libs: standard C library, media, 3D, SQL lite, and others.
So all you need is a compiler chain that will compile C/C++ to the appropriate CPU (ARM, in the case of the G1). Some brief instructions on how to do this are here.
What I don't know is where to find descriptions of the APIs that these libraries provide. I'd guess there may be header files buried in the SDK somewhere, but documentation may be sketchy/missing. But I think it can be done!
Hope thats useful. For the record, I haven't written any native android apps - just a few simple managed ones.
Andy

You can use nestedvm to translate C (or other GCC languages) into Java bytecode, and use that as the basis of your port. For example, see the Android port of Simon Tathams portable puzzle collection.
I expect this method is made obsolete by the NDK, but it might not be in if some networks or something don't allow people to upgrade their phones.

Google has already launched Google I/O 2011: Bringing C and C++ Games to Android session which is available at http://www.youtube.com/watch?v=5yorhsSPFG4
which is good to understand the use of NDK for writing application in c and c++ for android.
If you just want to cross compile any console based native game and run them on android then this Article has shown 3 methods for the same.
1: Static compilation using standalone toolchain
2: Cross compilation using Android NDK’s toolchain
3: Cross compilation using AOSP source code

Maybe you are looking for this?
http://www.mosync.com/
It is a middle layer for developing for several mobile platforms using c++.

Looking at this it seems it is possible:
http://openhandsetmagazine.com/2007/11/running-c-native-applications-on-android-the-final-point/ (now only available via the WayBack Machine)
"the fact is only Java language is supported doesn’t mean that you cannot develop applications in other languages. This have been proved by many developers, hackers and experts in application development for mobile. The guys at Elements Interactive B.V., the company behind Edgelib library, succeeded to run native C++ applications on the Android platform, even that at this time there is still many issues on display and sound … etc. This include the S-Tris2 game and a 3D animation demo of Edgelib."

Since 2009 there is a development on this matter.
Necessitas - Qt(C++ framework) for Android
Getting started video.

Take a look at google ndk group it looks promising, first version of the NDK will be available in 1H2009.
Update:
And it is released http://android-developers.blogspot.com/2009/06/introducing-android-15-ndk-release-1.html

I'm not sure the NDK provides full coverage of the official Java API.
From http://developer.android.com/sdk/ndk/index.html#overview :
Please note that the NDK does not
enable you to develop native-only
applications. Android's primary
runtime remains the Dalvik virtual
machine.

Google just released the NDK which allows exactly that.
http://feedproxy.google.com/~r/blogspot/hsDu/~3/2foWz7hwFtE/introducing-android-15-ndk-release-1.html
It can be found here:
http://developer.android.com/sdk/ndk/1.5_r1/index.html

This blog post may be a good start: http://benno.id.au/blog/2007/11/13/android-native-apps
Unfortunately, lots of the important stuff is "left as an exercise to the reader".

I do not know a tutorial but a good development tool: Airplay SDK from Ideaworks Labs. (Recently rebranded "Marmelade") Using C/C++ you can build apps for Windows Mobile, iPhones, Android. The only component I didn't like was the GUI composer - a buggy one, but you always can substitute it with the Notepad.

You can download c4droid and then install the GCC plugin and install to your SD. From the shell I just traverse to the directory where the GCC binary is and then call it to make an on board executable.
find / -name gcc
/mnt/sdcard/Android/data/com.n0n3m4.droidc/files/gcc/bin/arm-linux-androideabi-gcc
cat > test.c
#include<stdio.h>
int main(){
printf("hello arm!\n");
return 0;
}
./arm-linux-androideabi-gcc test.c -o test
./test
hello arm!

This three steps are good to have and store in this post.
1) How to port native c code on android
2) http://www.integratingstuff.com/2010/12/12/calling-native-c-code-through-jni-in-android-applications/
3) http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/

Native C/c++ Files libstdc++.* from your Ubuntu are x86 (or x86_64) binaries but Android devices and emulators are ARM. Of course, this will not work anyway, even if you'll set correct soname. This is very naive way which leads nowhere. Android has very limited support of C++ meaning there is no exceptions, standard C++ library (including STL) and RTTI. If you need such functionality, use my custom NDK distribution from
http://crystax.net/android/ndk.php - it support full C++ features listed above.
Why is there error: undefined reference to '__cxa_end_cleanup' link error. Android stlport
time. Because there is no link to libstdc + +. A. So wrong.
Because it uses some static library, it is necessary to link the full libstdc + +. A. Can
http://crystax.net/android/ndk.php here to download the package
sources \ cxx-stl \ gnu-libstdc + + \ libs \ armeabi directory.
Android on its own libstdc + + support is limited, it must be linked to a complete libstdc +
+. A the job.
Add file in Android.mk LOCAL_LDFLAGS = $ (LOCAL_PATH) / libs / libcurl.a \
$ (LOCAL_PATH) / libs / liblua.a \
`$ (LOCAL_PATH) / libs / libstdc + +. A`
And LOCAL_CPPFLAGS + =-lstdc + +-fexceptions can be compiled

There is a plan to allow C/C++ libraries in the next SDK version of Android (Codename Eclair?)To date, it's not possible through the Android Java SDK. However, you can grab the HUGE open source project, roll your own libraries, and then flash your own device...but anyone who wants to use your library will have to flash your custom build as well.

Short answer: You can't.
#Backslash17: Looking through the article and the following link with installation instructions, all the company got working is to launch a self compiled executable on the emulator, bypassing the android framework. Once you have the emulator you can telnet in and have a linux shell. Running a linux program there is trivial of course.
But that's not working for phones without jailbreak(aka root access) and not deliverable on the market.
Unless Google opens other opportunities or someone writes a custom compiler that compiles Language X into Dalvik bytecode (Dalvik is the VM that runs Android programs) you won't be able to write native code.

Related

Cross compilation - V8 and Linux on Windows

I am trying to embed Google's V8 in my game engine. I'm targeting 3 operating systems: Windows, Linux and OS X.
I haven't had any problems with building for Windows - I used NuGet packages. But I'm trying to build V8 for Linux and the problem is - I'm doing this on Windows (Windows 10 if it matters).
Google doesn't exactly say how to compile V8 for Linux using Windows and now I'm really confused, as I have no idea. So far I have depot_tools, properly fetched v8 (using fetch command), Python and MinGW.
I've tried with v8gen.py, but it seems that it generates build files only for Visual Studio. As I said, I don't need VS files.
My question is: What should I do?
This is not possible out-of-the-box with the current build tools and configurations that V8 provides. As suggested in the comments, using a VM might be the quickest way to get this working for you.
If it is very important for you long-term, or for other developers as well, you could look at submitting patches to V8 to make this possible, but I don't have a good sense of how much work that would be.

Is it possible to compile and run C/C++ programme in Nokia N95?

I have a Nokia N95. Recently I found a Python interpreter for my phone. So I search for C++ compiler for my phone but in vain. Any C++ compiler is really available for my phone?
Nokia N95 runs SymbianOS. You can download the S60 3rd Edition SDK here. It can be built using a small selection of compilers; the best one for you will probably be GCCE - an ARM cross compiler you can use on Windows.
The build process is simple enough but non-standard. This page should help you get started.

How to run run C++ apps in android?

How to run c++ applications in android using cygwin. Any tutorial in this regard is appreciated..
You cannot directly run C++ applications in Android.
Android can run only applications written using the Android SDK, but yes you can re-use your native(C/C++) libraries for Android.
You will have to recompile all the native libraries specifically for Android. And you do need the source code for all 3rd party native libs you plan to use simply because Usually when we compile and link these libraries outside Android they are linked to glibc but unfortunately Android doesn't use glibc due to liscence and performance issues. Android uses a watered down version of glibc called libc. It has matching symbol names to glibc for most of the usual functionalities. But as far as i know the libc doesn't have some functionality related to Strings and it definitely doesnt have some posix support. If your native libraries are using any of the deprecated functionality you will have to find workaround for those by using alternative functionality supported by libc and coding your libs accordingly.
Also, you will have to use the NDK to interface Java(Android app/fwk) to native world(C++). And then write a Android application on top of that.
Though this sounds pretty simple in my experience compiling native libraries on Android(Android porting) has traditionally been very time consuming with no guarantee of sucesses.
You will want the Java Native Interface, or "JNI".
See: "Java Native Interface Wiki" "Android JNI Tips" and links therein. It is some work to get this going and to get used to how it goes. I managed it from the references given here with C and it will work out after some time and faith without further help if you follow all the steps.

Can I do Android Programming in C++, C?

Can I do Android programming in C++, C? If the answer is "yes" then please tell how? And what's the procedure to set up?
I don't know Obj-C, Java, but well-versed in C, C++, Flash AS3, SDK released by Google.
Please do not tell about NVDIA SDK it's not fully developed :)
PLEASE NOTE: THE ANSWER BELOW IS HORRIBLY OUTDATED, AND MIGHT NOT BE ENTIRELY CORRECT ANYMORE.
You can program in C/C++ using the Android NDK. You'll have to wrap your c++ codebase in a static library and load that through a Java wrapper & JNI.
The standard NDK does not support RTTI and a lot of the functionality of standard c++ is also not available such as std::string, etc. To solve this you can recompile the NDK. Dmitry Moskalchuk supplies a modified version of the NDK that supports this at http://www.crystax.net/android/ndk-r3.php. This modified version works on all Android phones that run on an ARM processor.
Depending on the kind of application you should decide to use Java or C/C++. I'd use C/C++ for anything that requires above average computational power and games -- Java for the rest.
Just pick one language and write the majority of your application in that language; JNI calls can decrease your performance by a lot. Java isn't that hard though -- if you know how to program in C/C++. The advantage of Java is that the application can run on any device running Android, where as NDK applications depend on the architecture it was compiled for.
You should use Android NDK to develop performance-critical portions of your apps in native code. See Android NDK.
Anyway i don't think it is the right way to develop an entire application.
Yes, you can program Android apps in C++ (for the most part), using the Native Development Kit (NDK), although Java is the primary/preferred language for programming Android, and your C++ code will likely have to interface with Java components, and you'll likely need to read and understand the documentation for Java components, as well. Therefore, I'd advise you to use Java unless you have some existing C++ code base that you need to port and that isn't practical to rewrite in Java.
Java is very similar to C++, I don't think you will have any problems picking it up... going from C++ to Java is incredibly easy; going from Java to C++ is a little more difficult, though not terrible. Java for C++ Programmers does a pretty good job at explaining the differences. Writing your Android code in Java will be more idiomatic and will also make the development process easier for you (as the tooling for the Java Android SDK is significantly better than the corresponding NDK tooling)
In terms of setup, Google provides the Android Studio IDE for both Java and C++ Android development (with Gradle as the build system), but you are free to use whatever IDE or build system you want so long as, under the hood, you are using the Android SDK / NDK to produce the final outputs.
You should look at MoSync too, MoSync gives you standard C/C++, easy-to-use well-documented APIs, and a full-featured Eclipse-based IDE. Its now a open sourced IDE still pretty cool but not maintained anymore.
You can take a look also at C++ Builder XE6, and XE7 supports android in c++ code, and with Firemonkey library.
http://www.embarcadero.com/products/cbuilder
Pretty easy way to start, and native code. But the binaries have a big size.
You can use the Android NDK, but answers should note that the Android NDK app is not free to use and there's no clear open source route to programming Android on Android in an increasingly Android-driven market that began as open source, with Android developer support or the extensiveness of the NDK app, meaning you're looking at abandoning Android as any kind of first steps programming platform without payments.
Note: I consider subscription requests as payments under duress and this is a freemium context which continues to go undefeated by the open source community.
There is more than one library for working in C++ in Android programming:
C++ - qt (A Nokia product, also available as LGPL)
C++ - Wxwidget (Available as GPL)

Porting .NET C++ standalone to Mac

I need to give an estimate for porting a standalone program to a Mac from a .NET platform. I have all the source code which is in C++ and is both code I wrote and a modified version of GLUT/GLUI because the program uses OpenGL and GLUT/GLUI as a UI.
I don't think the C++ code will be a problem or the OpenGL environment, please tell me if you think it will be. In .NET, I use OpenGL32.DLL and deploy it with my app. I need to find out how this is done for a Mac?
I really need to know what the current deployment method is for Mac's these days and how hard it will be for me to write for it. For .NET, I use Visual Studio for the application development and deployment, I make a new VS project to build the deployable MS installer.
The deployment process also allows things like placing a desktop shortcut, associate a unique icon with the program ... What deployment options can one select on a Mac? What do you think the biggest obstacles will be?
There's no .NET framework calls within the code. The deployment phase produces a .NET assembly with all the security features. I think that is the main relationship with .NET since it is straight C++ not C#.
Development should be rather straight-forward. You'll be able to do OpenGL/GLUT/etc... through the Cocoa framework. Look at this example from Apple to see how it is done in code.
As for development tools, you will be able to use Xcode (which is free with the Mac). You can develop in C++ and compile with GCC.