views:

832

answers:

5

I'm interested in the following features:

  1. Writing an app for Android Market that is written completely in C++ (a port of existing product actually).
  2. Use fast screen-buffer pixel pushing (or rather using OpenGL ES for this).
  3. Grab user input and direct it to C++ code.

Is it legal to write such an app for Market? Is Market policy somehow strict to such things?

A: 

http://developer.android.com/guide/basics/what-is-android.html

"The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language."

http://arstechnica.com/open-source/news/2009/06/android-goes-beyond-java-gains-native-cc-dev-kit.ars

In general, you don't. There is some limited C++ support through JNI, but it is mostly intended to supplement Java code, not replace it. There's no framework/API support (AFAIK) for C++, so doing this isn't really an option.

James
I believe that OpenGL APIs at least are exposed directly on NDK level, so e.g. for full-screen games full native is definitely an option (and probably recommended).
Pavel Minaev
+3  A: 

It is really not my cup of tea but there is something called Android NDK (Native Development Kit) to use if you want to write your program in C. Not sure how the C++ compiler support is though.

As far as I know your app can be almost 100% native code but keep in mind that by walking that way you will probably have a hard time supporting the different CPUs out there in Android hardware. If you need to bootstrap the native code so that it is started from java it is probably not a very big problem for you.

I found a few different tutorials when googling for "Android NDK". This one is a very minimalistic Hello World. Obviously you want something much more than a library that returns a string to java but it is a good first start and you will probably have to do all of the things described. Do a search using NDK and Android as keywords and you get a good selection. I see no reason to list them here as such lists tends to be outdated and broken within a year or so.

I guess the official Android Developer site from Google will stay put and be updated on new releases of the platform, it has a link to the current NDK.

Fredrik
Why the downvote?
Fredrik
If I had to guess, it's because you suggested Gooling for a string rather than providing a direct link to the project. Sometimes people want to be picky. +1 for the link you did provide, though. It's quite the thorough walkthrough to setting up a development environment, not just a short bit of code.
Conspicuous Compiler
Except that the link isn't for the NDK AFAICT. It's for writing console apps, using the cross-compiler that's part of the Android open source project. The term "NDK" doesn't even appear on the page, and the post was written before the NDK was released.
CommonsWare
@CommonsWare: Ok, my mistake to call it "hello world with NDK", it was meant more as an example of something written in C.
Fredrik
@Conspicuous Compiler: Ok, I see the point. My intention was to help him with a keyword to start searching with, not only to find the NDK docs but to find tutorials and things others have written as well. I had the impression the OP didn't know about NDK as a term. I hope no-one considered it a lmgtfy-answer.
Fredrik
Heh, now that you've changed the link, my first comment seems nonsensical. Progress!
Conspicuous Compiler
@Conspicuous Compiler: Sorry, it was because of @CommonsWare's input, that link seemed to make more sense. As I said it is not (yet) my cup of tea, I just wanted to contribute with what I have picked up so far.
Fredrik
@Fredrik Hehe, no worries. It's probably a better link for this purpose. I'm just being silly. Cheers!
Conspicuous Compiler
i'm actually aware about the NDK and is asking if it's possible to create a full-screen OpenGL app that uses java wrapper to receive input (and possibly timer) events and output the buffer to the screen. The native lib should have persistent state, so the java wrapper will only run a main loop and call 'cycle' method inside the NDK lib.The second question was: can I put the pixels array directly on the screen without using OpenGL?
Hedin
+1  A: 

There is no 100% native solution but what I think you are looking for is the Android NDK (Native Development Kit)

From their site "Please note that the NDK does not enable you to develop native-only applications. Android's primary runtime remains the Dalvik virtual machine."

I believe it lets you make calls to your own native code from an Android application

I have personally never used it for my games, but I am sure it would help on a lot of things (like being able to manage my own memory and not have "lag" do to the garbage collector)

snctln
+1  A: 

conversations in this thread can help you. http://groups.google.com/group/android-ndk/browse_thread/thread/50362904ae0574cf

essence is, It is possible to make Native only apps and Android Market doesn't restrict you either. But with limited support for native development, there is high chance of using some of the non standard functionality which might break in future releases.

FL4SOF
+5  A: 
  1. Writing an app for Android Market that is written completely in C++ (a port of existing product actually).

Nope, that's not possible. You may be able to wrap a lot of your smarts into a .so that is available to Java through NDK and JNI, but that's as close as you can get for something distributable through the Android Market.

  1. Use fast screen-buffer pixel pushing (or rather using OpenGL ES for this).

Well, there's definitely OpenGL access, to some degree, from the NDK. Whether this specific feature is available I can't say. And, this is the NDK, so you're creating a library, not an app.

  1. Grab user input and direct it to C++ code.

Well, the Java code using the JNI library can accept user input and call functions in your C++-implemented library, if that's what you mean.

CommonsWare
Will this library have persistent state? Like have all the game state inside and only receive calls to 'cycle' as fast as Java part can?
Hedin