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 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 :: " + …

Display News and Videos through RSS and Display it in Listview

Hi friends , In this tutorial ,i'm going to describe about how to fetch data from rss feed.Here i had also problem ,when i was developing my recent project.I had also faced  many problem and at last i developed my best project.

Here is the code that describe how to fetch news headline from rss
This class describes how to parse XML data:
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParser;

import android.content.res.XmlResourceParser;
import android.util.Log;
import android.util.Xml;

public class XmlFeedParser {

    //Feed Parsing Method
    public ArrayList<Implement> parse(String url) {

        //Array of Episode Objects
        ArrayList<Implement> episodes = null;

        try {
            //Encode the URL into a URL Object
            URL episode_feed_url = new URL(url);

            //Open a Connection to the feed
            XmlPullParser parser = Xml.newPullParser();
            try {