Pages

Get it free, Try now

Free Cell Phones

Wednesday, October 13, 2010

Porting Android to beagle broad for Noob

Primarily I would suggesst to take a look at

http://labs.embinux.org/index.php/Main_Page

then

http://www.codeshogun.com/blog/2009/04/15/porting-android-to-beagle-board/

Thursday, October 7, 2010

Android NDK Error Reference for noob

Android NDK Error Reference

Error 1:
$ ndk-build
/cygdrive/c/andy/abc/obj/local/armeabi-v7a/objs/abc//hellow.o.d:1: *** multiple target patterns. Stop.

quick fix: Delete Obj folder from "C:\andy\prjM\obj\local\armeabi-v7a" then run ndk-build
or refer this

Error 2:
Android.mk:44: *** commands commence before first target. Stop.
fix: Check there are no comments,no space ,no empty line in the src includes of Android.mk

For example:
wrong:
LOCAL_SRC_FILES :=file1.cpp\
file1al.cpp\
#file1atures.cpp\
file1r.cpp\

file1le.cpp\
Satfile1.cpp\
Sfile1l.cpp\
file1e.cpp\
Sfile1face.cpp\

3rd line has #, 4th line has space(check with cursor),5th line is empty line

Right:
LOCAL_SRC_FILES :=file1.cpp\
file1al.cpp\
file1atures.cp\
file1r.cpp\
file1le.cpp\
Satfile1.cpp\
Sfile1l.cpp\
file1e.cpp\
Sfile1face.cpp\

Error 3:
$ ndk-build clean
Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/cygdrive/c/android-ndk-r4b/build/core/build-local.mk:85: *** Android NDK: Aborting . Stop.

Fix: include Android.mk location inside global application.mk and Android.mk
Run the command from the parent directory with app.mk and and.mk resides

Error 4:

Please define ANDROID_NDK_ROOT to point to the root of your
Android NDK installation.

Use case while executing shell script

xxx-desktop:~/bin/u/android-ndk-r5/build/tools$ ./rebuild-all-prebuilt.sh
Please define ANDROID_NDK_ROOT to point to the root of your
Android NDK installation.

// Run the script inside NDK root directory like shown below
xxx-desktop:~/bin/u/android-ndk-r5/build/tools$ cd ..
xxx-desktop:~/bin/u/android-ndk-r5/build$ cd ..
xxxx-desktop:~/bin/u/android-ndk-r5$ ./build/tools/rebuild-all-prebuilt.sh

Error 5: NDK r5 app(native-activity,native-audio,native-plasma) build problem

Compiling native-activity,native-audio,native-plasma on ndk-r5 give compile errors stating

header not found and  so on ......

Quick fix:  Rebuild all prebuilt

i;e execute shell script rebuild-all-prebuilt.sh to build on latest toolchain provided by android which will take for a while (atleast on my pc)

xxx-desktop:~/bin/u/android-ndk-r5$ ./build/tools/rebuild-all-prebuilt.sh
To follow build in another terminal, please use: tail -F /tmp/ndk-toolchain/build-CtAG7s/log.txt
Download sources from android.git.kernel.org
Using git clone prefix: git://android.git.kernel.org/toolchain
downloading sources for toolchain/binutils
downloading sources for toolchain/build
downloading sources for toolchain/gcc
downloading sources for toolchain/gdb
downloading sources for toolchain/gmp
downloading sources for toolchain/gold
downloading sources for toolchain/mpfr
Patching toolchain sources
Toolchain sources downloaded and copied to /tmp/ndk-toolchain/build-CtAG7s/src
Cleaning up...
Done.
Building arm-eabi-4.4.0 toolchain... (this can be long)
ERROR: Could bot build arm-eabi-4.4.0 toolchain!
xxxx-desktop:~/bin/u/android-ndk-r5$

Now change to native-activity folder and call ndk-build for successful libnative-activity.so

xxx-desktop:~/bin/u/android-ndk-r5/samples/native-activity$ ndk-build
Compile thumb  : native-activity <= main.c
Compile thumb  : android_native_app_glue <= android_native_app_glue.c
StaticLibrary  : libandroid_native_app_glue.a
SharedLibrary  : libnative-activity.so
Install        : libnative-activity.so => libs/armeabi/libnative-activity.so

*** multiple target patterns issue in Cygwin

follow the discussion in the 2nd reply from the board message here

http://www.eclipse.org/forums/index.php?t=msg&goto=188883&


*EDIT* seem the updated eclipse forum moved the board message, a quick fix is try to update make with latest version shall fix *** multiple target patterns issuee

Tuesday, October 5, 2010

Integrate Android NDK with Eclipse

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
[slideshow]

Monday, October 4, 2010

how to use Logs in Android Application and Android NDK

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,