• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Porting C++ to Android

3 posts in this topic

I am coding a game engine and I'm trying to port it to Android to check for errors and tests.

But I still haven't even been able to get a simple function working...


I'm following a few tutorials and I think I know what I am supposed to do:


- Put my C sources in my android project's JNI folder.

- Build it with the Android NDK, after setting everything up.

- Link the lib on my Activity class, call a method, crash.


My C source looks like this:

#include <jni.h>

jint Java_my_engine_test_MainActivity_MyFunctionName(JNIEnv* env, jobject obj)
    return 0;

My Android.mk is:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := EngineTest
LOCAL_SRC_FILES := EngineTest.c


And my Java file is:

package my.engine.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {

        //If I uncomment this line, the app crashes, else it's ok
        //int a = MyFunctionName();

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;

    private native int MyFunctionName();
    static {

So I've made certain that the function name is according to the specification (Java, package name, class name, then function name) and that I'm using JNI types, and it's a really really really simple function.


Also, for some reason, none of the examples that came with the NDK build for me when using the Eclipse NDK support. I get syntax errors (syntax!). So I'm guessing they must've changed it somewhere along the way...


I'm at a loss, I've been looking all over for what could be causing this and how I can get a simple C function to work in the Android Emulator, but found nothing so far. I'm still checking other tutorials and following them but they're all the same thing and have the same errors, so I'm guessing it must be something else.


I've also set up the NDK folder in Eclipse and now it's auto-building my C sources every time, and it builds, but the app simply crashes when I try to access a function from the lib.


Does anyone know what could be causing this?


Also, a question, the engine's nearly finished for a first project and I made it with certain rules that I'd like to ask about when porting to Android.

I've made it a single class containing everything to run a game, and a few classes available to the game code such as Image, Models, Animations, etc.

There's only one rule that the game code must abide to and that is to inherit the "GameState" class (abstract) so it forces implementations of the methods required for the engine to run (Start, Pause, Resume, Update, Exit functions).


I was thinking in having the engine and making the game elsewhere, like Java (when I get the engine working) for faster coding, but then there's the problems of the C++ classes (Image, Models etc) that probably won't be available on Java (although this I can fix with a wrapper), and the GameState class that a state must inherit to set it to the engine. I don't think I can wrap this last one and I'm don't know how to proceed with this.


If there's no way, I'll probably try coding the entire game in C++ and trying to port it all at once... if only I can get this NDK to work...


Thank you in advance.


Share this post

Link to post
Share on other sites

I cannot see anything wrong in the code as such.

have you checked if the library was built?

it should show up in the console window. And the .so library file should be in the libs folder.

what are the messages in the logcat window?

Edited by steven katic

Share this post

Link to post
Share on other sites

you may need to put the following line in your Android.mk  file to see the log output:




Sorry, no you don't , you only need to do this to use the logging library: i.e to log your own native messages to the LogCat window.

Edited by steven katic

Share this post

Link to post
Share on other sites

Wow, thanks alot!


I'm new to Java and Eclipse so I don't know my way around and I didn't even knew how to look for errors... after learning where the log is I found it was an UnstatisfiedLink - Native Method not found, and a simple google taught me that JNI doesn't work with C++ naming, so I have to use extern "C" before the functions and now it's not crashing anymore!


Really, thank you!


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0