tags:

views:

8936

answers:

16

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 good tutorial on the subject?

Thanks!

A: 

"Currently we are focusing our efforts on application development using the Java programming language. The SDK does not support native application development at this time" link

At the moment it seems not possible because the only language supported is Java. Any way there are good tutorials for programming in Java for Android, maybe this can help you:

http://stackoverflow.com/questions/792155/how-to-start-developing-applications-for-android

backslash17
that's not the same question...
Cogsy
I see! I change it!
backslash17
+2  A: 

Looking at this it seems it is possible:

http://openhandsetmagazine.com/2007/11/running-c-native-applications-on-android-the-final-point/

"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."

backslash17
A: 

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".

Krzysiek Goj
+8  A: 

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

Andy Johnson
A: 

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.

buster
Right, that's why I wrote "It seems...". See to believe!
backslash17
+1  A: 

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

Gordon Freeman
A: 

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.

haseman
+8  A: 

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.

Marc
+6  A: 

You can develop native applications for Android, I have done some work in that area. The best link for you is Android NDK page. In brief, the easiest way for you would be to use some JNI wrapper to start and navigate your application. For this work, you should can also be using Android compiler that is available along with Android source code. An old alternative is CodeSourcery, but it's better to use the native prebuilt compiler. You will have to use Bionic C-library, and accommodate needs of your application to the existing features in C/C++ on Android. Some Linux IPC is missing, such as System V, but your C/C++ application probably isn't using that anyway. Note that in your research you should avoid articles that refer to older versions of Android SDK. So, avoid all links from 2008. or 2007.

MannyNS
thanks for the info, its nice to hear from someone that has done some native work before!
Robert Gould
+22  A: 

For anyone coming to this via google, note that starting from SDK 1.6 Android now has an official native SDK. There doesn't seem to be a general page for the 'NDK', but the download page for the first release is here.

Andy Johnson
Thanks this is the correct answer nowadays, so you win :)
Robert Gould
OK, so now how about C# and .Net?-)
Avi
Can't see .net support ever happening
vickirk
@vickirk why not? Mono was ported to the iPhone.
Amigable Clark Kant
I was talking about the android SDK, sure there is nothing stopping third parties porting it to android phones.
vickirk
+3  A: 

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.

rjmunro
+1 for an alternative to the NDK, even though the NDK makes it obsolete.
tobsen
A: 

I was looking at the Chipmunk Physics engine which is written in C and has been used by Android developers. They use JNI binding as a previous poster mentioned and the project Snowball for Android, whose source code is available online, might be worth checking out here.

IcedDante
A: 

But the stock android browser can't possibly be written in java, so it must be possible, no?

A: 

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.

Android Eve
A: 

Maybe you are looking for this?

http://www.mosync.com/

It is a middle layer for developing for several mobile platforms using c++.

joepal