Skip to main content

Overview of how to develop native code with Android NDK:

  1. Create a jni directory and place native source code under $PROJECT/jni/...
  2. Create directory and place it under $PROJECT/jni/... to describe source code to the NDK build system.
  3. Create and place it under $PROJECT/jni/ describe project in more details to the NDK build system.It is an optional.
  4. Finally need to build native source code by running '$NDK/ndk-build' from project directory or it's sub-directory.
An file is a small build script that we write to describe sources to the NDK build system. It's syntax is like this...

LOCAL_PATH:=$(call my-dir)

include $(CLEAR_VARS)



NDK groups your sources into "modules", where each module can be one of the following:
  • Static library
  • Shared library
We can write several module in a single '' or can write several '' for each module.
An file script that we write to describe project to the NDK build system.It's syntax is like this...

to support hardware FPU instructions on ARMv7 based devices
to support the IA-32 instruction set
to support the MIPS instruction set
to support all at the same time

APP_ABI:=armeabi armeabi-v7a x86 mips or

This allows us to do following:
  • The exact list of modules required by the application.
  • The CPU architecture to generate machine code for.
  • Optional information, like whether you want a release or debug build, specific C or C++ compiler flags and others that should apply to all modules being built.
This file is optional: by default the NDK provide one that simply builds all the modules listed from the (and all the makefiles it includes) and target the default CPU ABI (armeabi).
The 'ndk-build' script, located at the top of the NDK installation path can be invoked directly from your application project directory (i.e. the one where your AndroidManifest.xml is located) or any of its sub-directories. For example:
dilip@dilip-zenga:~/android-ndk-r9c/samples/hello-jni$ ~/Desktop/android-ndk-r9c/ndk-build

On success, this will copy the generated binary modules i.e. Shared library to the appropriate location in the project tree.


import android.widget.TextView;
import android.os.Bundle;

public class HelloJni extends Activity
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState)

        /* Create a TextView and set its content.
         * the text is retrieved by calling a native
         * function.
        TextView  tv = new TextView(this);
        tv.setText( stringFromJNI() );

    /* A native method that is implemented by the
     * 'hello-jni' native library, which is packaged
     * with this application.
    public native String  stringFromJNI();

    /* This is another native method declaration that is *not*
     * implemented by 'hello-jni'. This is simply to show that
     * you can declare as many native methods in your Java code
     * as you want, their implementation is searched in the
     * currently loaded native libraries only the first time
     * you call them.
     * Trying to call this function will result in a
     * java.lang.UnsatisfiedLinkError exception !
    public native String  unimplementedStringFromJNI();

    /* this is used to load the 'hello-jni' library on application
     * startup. The library has already been unpacked into
     * /data/data/com.example.hellojni/lib/ at
     * installation time by the package manager.
    static {


#include <string.h>
#include <jni.h>

/* This is a trivial JNI example where we use a native method
 * to return a new VM String. See the corresponding Java source
 * file located at:
 *   apps/samples/hello-jni/project/src/com/example/hellojni/
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
                                                  jobject thiz )
#if defined(__arm__)
  #if defined(__ARM_ARCH_7A__)
    #if defined(__ARM_NEON__)
      #define ABI "armeabi-v7a/NEON"
      #define ABI "armeabi-v7a"
   #define ABI "armeabi"
#elif defined(__i386__)
   #define ABI "x86"
#elif defined(__mips__)
   #define ABI "mips"
   #define ABI "unknown"

    return (*env)->NewStringUTF(env, "Hello from JNI !  Compiled with ABI " ABI ".");

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := hello-jni
LOCAL_SRC_FILES := hello-jni.c




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-sdk android:minSdkVersion="3" />
    <application android:label="@string/app_name"
        <activity android:name=".HelloJni"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

Previous       Next      


Popular posts from this blog

Display video from specific folder with rounded shape thumbnail

Hi friends ,This is complete post, about how to display video form specific folder and display it with rounded shape and play it on click event. For Rounded shape I have used custom ImageView.
Now have a look on code part.
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android=""
    android:stretchMode="columnWidth" >

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

Custom Android SeekBar Developement

Before starting coding for Custom SeekBar,You must have good concept of following topics. 1.Layer List 2.Animation List 3.Selector Layer List:A LayerDrawableis a drawable object that manages an array of other drawables. Each drawable in the list is drawn in the order of the list—the last drawable in the list is drawn on top.
<layer-listxmlns:android=""> <item android:id="@android:id/background" android:drawable="@drawable/seekbar_total"/> <itemandroid:id="@android:id/secondaryProgress"> <clipandroid:drawable="@drawable/seekbar_buffer"/> </item> <itemandroid:id="@android:id/progress"> <clipandroid:drawable="@drawable/seekbar_played"/> </item> </layer-list> Animation List:A AnimationDrawable is a drawable object that is used to create frame-by-frame animation.It's oneshotelement should be true if u want loop animation otherwise false.

Custom Volley-Gson request implementation

This page covers Volley-Gson integration and also Volley custom Request. We assume that, you are familiar with Volley and Gson.

Volley has some inbuilt request which you can use, if your response is a String, Image, or JSON, in that case, you don't need to implement a custom Request.  To use Gson with Volley, we need to implement a custom request.
To make a custom request, you need to perform following operation.
Extend Request<T> class, where T is the type of parsed response or expected response. Implement the abstract methods parseNetworkResponse() and deliverResponse().  parseNetworkResponse:  A response contains parse response of a given type i.e Gson.

    protected Response<T> parseNetworkResponse(NetworkResponse response) {
        try {
            String json = new String(
          , HttpHeaderParser.parseCharset(response.headers));
            if (BuildConfig.IS_DEBUG)
                Log.d(TAG, "Response :: " + …