In this tutorial I use Ubuntu linux 13.04 distribution.
Advantages of Native Code:
1.Existing libraries in native language such as C/C++ can be used.
2.Performance of the app is increased.
3.It is almost impossible to decompile the app and to get the original code.
2.ADT (Android Developer Tools)
sudo apt-get install android-tools-adb
1.Extract the contents from the downloaded “Android NDK” and “ADT” archive to your home directory.
2.Now we are going to export the path of NDK as a variable.
i)Open the terminal
ii)Enter the code in the terminal and hit enter
iii)A text editor opens, Place the following code at the end of the file and save it.
Note:Replace with your username.
Now you have basically set up Android NDK.
Let us see some examples given with the Android NDK package. The examples are placed in the “samples” folder of “android-ndk-r8e” folder.
1.Now open “eclipse” from /home/username/adt-bundle-linux-x86_64-20130522/eclipse directory.
2.ADT will open now.Now lets see how to compile Native C/C++ program with NDK
3.Now import the sample program by selecting File->Import, then select Android->Existing Android Code Into Workspace, then select hello-jni from samples folder of NDK and then Finish.
4.The project will be imported and HelloJni will be shown in the Package Explorer of ADT.
5.In the Package Explorer expand the folder jni , You will see two files, the file hello-jni.c is the Native C written code which we are going to compile.
6.In order to compile the native code open the terminal and navigate to hello-jni folder.
7.To compile enter the following code in the terminal.
If compilation is success you will get a library file “libhello-jni.so”
8.Now refresh the project in the Package Explorer in ADT, the library file is located in libs->armeabi folder.
9.Finally we are going to test our application in the emulator. Start the emulator and run the project.
10.Our application will be installed in the emulator.
11.Lets make some changes in the native code. I have replaced the string as “Hello this is learn2crack”.
12.Now recompile using NDK and clean the project and then run in the emulator.Its working..
For any queries comment here.
Cheers, enjoy 🙂