Archive

Archive for the ‘Android-NDK’ Category

Android- How to Create Executable

December 10, 2010 Leave a comment

1. Setup ndk project with android.mk and native sources

Android.mk file should include BUILD_EXECUTABLE, sample android.mk is below.


LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := Modulename
LOCAL_SRC_FILES := file1.c\
file2.c

LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

2. Building executable.

$ ndk-buld

3. Run executable

copy to device say /sdcard/data/Modulename
xxxx@xx:$> adb shell
$./sdcard/data/Modulename

Note:Make sure you place Android.mk file along with source(c/c++) in same folder and name it as jni. as libs and obj folders are created next to jni folder.

Categories: Android-NDK

Android: make the system partitions on the device read-write

November 11, 2010 Leave a comment

From the SDK’s tools directory, run adb shell. In the
prompt run the following:

# su
# mount -o rw,remount -t yaffs2 /dev/block/mtdblock4 /system
# chmod 777 /system (Or any subdirectory you want to push to inside system)
# exit
adb push

and eventually you should restore the original directory permissions by:
# chmod 755 /system (Or any subdirectory you modified permissions to)

Make sure you knew the mount point for system by running #
# cat /proc/mtd
dev: size erasesize name
mtd0: 00500000 00020000 "boot"
mtd1: 04000000 00020000 "cache"
mtd2: 00500000 00020000 "recovery"
mtd3: 00060000 00020000 "splash"
mtd4: 0f500000 00020000 "system"
mtd5: 002c0000 00020000 "lgdrm"
mtd6: 08b80000 00020000 "userdata"
mtd7: 00080000 00020000 "usd"
mtd8: 005a0000 00020000 "pkg"
mtd9: 1cfc0000 00020000 ""

Categories: Android-NDK

Integrate Android NDK with Eclipse

October 5, 2010 2 comments

Its assume that both NDK and cygwin are installed on same location

C:\cygwin
C:\android-ndk-r4b

we will use hello-jni project from the samples provided with NDK,
C:\android-ndk-r4b\samples\hello-jni

Import the project inside Eclipse
Click project properties.
Select “builders” from the left-hand list.
Click on button “New…” on the right side.
Select “Program” as the configuration type.
Name it as you like say “Build_JNI”
In ‘Main’ tab enter
Location as –

c:\cygwin\bin\bash.exe

Working Directory as –

c:\cygwin\bin

Arguments as

–login -c “cd /cygdrive/c/android-ndk-r4b/samples/hello-jni && ndk-build -B”

Make sure you have the two hyphens before login and the quotes after the hyphen-c

Now go to the ‘Refresh’ tab
Check “Refresh resources upon completion”
Select “Specific resources”
Click on the “Specify resources” button and select your project’s lib directory.
Check “Recursively include sub-folders”

Now go to the ‘Build Options’ tab

Check “Allocate Console”
Check “Launch in background”
Check “Run the builder After a Clean”
Check “Run the builder During manual builds”
Check “Run the builder During auto builds”
Check “Specify working set of relevant resources”
Click on “Specify Resources”
Select your project’s JNI directory and all files within.

finally click Apply n OK

Check slide show for LAF

Categories: Android-NDK

how to use Logs in Android Application and Android NDK

October 4, 2010 Leave a comment

We will first see how to use logs on Android Application side and then we look into usage of logs on Native side(NDK)

On Application side
Import log provided by Android

import android.util.Log;

then use below two lines of code where ever needed

String TAG =”ModuleName”;
Log.d(TAG,”File Name is =%s”+ testFilename );

Use following based on the priority constants

Priority Usage

DEBUG Log.d
ERROR Log.e
INFO Log.i
VERBOSE Log.v
WARN Log.w
WTF Log.wtf

WTF(What a Terrible Failure): Report an exception that should never happen.

Inside Native code
Similarly in Native code include the header and call the ‘ __android_log_print’ , ‘__android_log_write’ with appropriate priority constants, do not miss to the library in the Android.mk fail to which leads to linker issues.

Add below line in Android.mk

……
LOCAL_LDLIBS := -llog
….

Include header

#include “android/log.h”
….
then call

{..
__android_log_print(ANDROID_LOG_INFO, “ModuleName FunctionName”, “Enter”);


__android_log_print(ANDROID_LOG_INFO, “ModuleName FunctionName”, “Exit”);
}

or

{
__android_log_write(ANDROID_LOG_ERROR, “ModuleName FunctionName”, “#1”);
….
}

use below priority constants or find directly under ‘C:\android-ndk-r4b\build\platforms\android-8\arch-arm\usr\include\android’

ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT,

Categories: Android Dev, Android-NDK