handmade.network » Forums » Android ndk problem
msmshazan
Shazan Shums
120 posts

Some day I will make quality software.
Programming FTW.

#11032 Android ndk problem
2 months ago

I wanted to port my pong clone to android so i downloaded the android ndk but im stuck I can't figure out how to port it and the docs says to do stuff with java and android sdk .
The pong game works like handmade hero with game code in separate DLL . How can i do it can I avoid java entirely or how to do it with minimal java.
I currently don't have the sdk also..

Just being curious on programming....
mmozeiko
Mārtiņš Možeiko
1281 posts
1 project
#11034 Android ndk problem
2 months ago Edited by Mārtiņš Možeiko on Feb. 25, 2017, 11:52 p.m.

For basic functionality like getting window up, getting input events, doing some OpenGL rendering and outputting sound you can do without Java. It will be still there, because all applications on Android starts up as Java. But there is built in class called NativeActivity that sets everything up in Java, so you can use only native code. In this case you will be writing native code in shared library which will be called by NativeActivity for various events - like applications started, input events, application closed, low memory, etc...

Here is documentation about NativeActivity: https://developer.android.com/ref...e/android/app/NativeActivity.html

NDK also comes with tiny library (just one .c and .h file, source comes with NDK) called native_app_glue that wraps NativeActivity API's with a bit nicer interface. Here is its reference documentation: https://developer.android.com/ndk...ence/group___native_activity.html

For basic example take a look at native-activity sample:
https://developer.android.com/ndk/samples/sample_na.html
https://github.com/googlesamples/...d-ndk/tree/master/native-activity

But I suggest to start with even simpler example "hello-jni" to understand how everything works together:
https://developer.android.com/ndk/samples/sample_hellojni.html
https://github.com/googlesamples/android-ndk/tree/master/hello-jni

Take a look also at other examples in android-ndk repo: https://github.com/googlesamples/android-ndk

When NativeActivity won't be enough and you'll want to access more Android API's then that must be done in Java (it's possible to do it native code with JNI, but it is huge pain, simple one line of Java code can be tens or hundreds lines of code in C). But you don't need to change your native code a lot, you can still use it, but simply extend NativeActivity class.

Btw, if you are on Windows, you can use Microsoft Visual Studio 2015 to build and debug Android NDK applications: https://blogs.msdn.microsoft.com/...-android-with-visual-studio-2015/

I've put super simple OpenGL ES 2 example on my github: https://github.com/mmozeiko/android-native-example It has only C code and uses NativeActivity so I don't need to use any Java code. And it uses handmade style bat file to build, install and run application, no IDE required.
msmshazan
Shazan Shums
120 posts

Some day I will make quality software.
Programming FTW.

#11041 Android ndk problem
2 months ago

Big thanks mmozeiko.
I will check it out ASAP.
This needs to be added to resource section if there's one.

Just being curious on programming....