Category Archives: NDK

How to find your Google Plus ID

This is so simple

1. Go to your Google + account (

2. Click on the Profile icon on the Left.

3. If you look at the URL in the address bar, it should look something like this:

4. The long numerical string in the URL is your Google+ ID. Here is CoderzHeaven’s from the URL above:


Google + CoderzHeaven

How to include multiple c files to compile in android NDK?

I ran into problem when I had multiple C files in my project. Single C file was OK for me.
I was getting undefined reference error while doing this.
Then I found out the solution after a lot of search in google.

You can check this post before going through this post.
This is about setting up NDK in MAC.
Starting with NDK for Android – A Simple example. OR How to run a C code in android?

I have to make the change in the file to include other files to compile.

This is the content of my file

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := ndksetup
LOCAL_SRC_FILES := native.c test.c test_2.c

Here is my native.c code in which I am including those two files test.c and test2.c

#include <jni.h>
#include <string.h>
#include <android/log.h>

// my test file 
#include "test.h"
#include "test_2.h"

#define DEBUG_TAG "NDKSetupActivity"
void Java_com_ndksetup_NDKSetupActivity_printLog(JNIEnv * env, jobject this, jstring logString)
    jboolean isCopy;
    const char * szLogString = (*env)->GetStringUTFChars(env, logString, &isCopy);
    __android_log_print(ANDROID_LOG_DEBUG, "TAGGGGG", "NDK: %s", szLogString);
    (*env)->ReleaseStringUTFChars(env, logString, szLogString);
int Java_com_ndksetup_NDKSetupActivity_fibonacci(int value)
	int p = 8;
	return p;

Starting with NDK for Android – A Simple example. OR How to run a C code in android?

Hello Friends….

Today I am going to talk about how to use ndk in android to run c code.

Note : These steps are for Mac and Linux Users not for Windows users.

Follow these step exactly to set up and run ndk in android.

1. I think that you are having your eclipse and android uptodate.
2. Go to this place “” and download the ndk for your operating system.

3. After downloading the zip, extract it and save it in your own location.

4. Now we are going to create the android Project.
I am naming it “NDKDemo” and the activity is named “NDKDemoActivity”.

Now create a folder named “jni” in the project.

5. Click on jni folder-> then go to “Run Menu” > external tools > external tools configuration.

6. Click on Program and click on the new icon (first icon) on the top. On the right side Give the NDK a name.

In the Next Location textbox Click on “Browse File System” and located the ndk-build that you just downloaded from “

7. Now in the Workspace location > Click on Browse Workspace and select your “jni” folder in the “NDKDemo” project directory.

This dialog comes when you click the Browse Workspace button and select the jni folder in your project and click OK.

8. Now create a file named “” file inside the “jni” folder.

copy this code to “” file.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)


LOCAL_MODULE    := ndkdemo
LOCAL_SRC_FILES := native.c


9. Now create another file named “native.c” inside the jni folder and copy this code into it.
This is our c code.
This don’t look purely like a c code because it has some java elements inside it.

#include <jni.h>
#include <string.h>
#include <android/log.h>

#define DEBUG_TAG "NDKDemoActivity"

void Java_com_coderzheaven_pack__NDKDemoActivity_printLog(JNIEnv * env, jobject this, jstring logString)
    jboolean isCopy;
    const char * szLogString = (*env)->GetStringUTFChars(env, logString, &isCopy);

    __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK: %s", szLogString);

    (*env)->ReleaseStringUTFChars(env, logString, szLogString);

Note :
Please take a look the function name


This naming should be in this format

Also one more thing the “dots” (.) in the package name should be replaced by underscore in the function name”. This is important.

OK Everything needed for NDK is done.
10. Now what we have to do is to compile the c code. For that go to “Run” > external tools > select NDK you created and run.

Now the c code has been compiled.

11. Now in the java Activity copy this code

package com.coderzheaven.pack;

import android.os.Bundle;

public class NDKDemoActivity extends Activity {
	  static {

	    public void onCreate(Bundle savedInstanceState) {
	        printLog("Hello Coderzheaven");

	    private native void printLog(String logThis);

12. Now run this project and check the Logcat for the message after calling the C function from android.

You can any number of c functions inside the native.c code and run it.
Make sure to put a declaration on top of the activity before calling.

Please leave your comments if this post was useful.