Archive

Archive for August, 2010

How to build shared/static library (.so file) on android.

August 17, 2010 Leave a comment

Build Environment
1. Install Cygwin
2. Have javac which is already available in JDK package.
3. Install Android NDK(Native development Kit)
4. Make sure both cygwin and NDK are in same location such as
C:\android-ndk-r4\ and C:\cygwin

Now create a android project using eclipse or use samples folder instead C:\android-ndk-r4\samples

1.now, run through cmd, javac on .java file which has definition of native method and a static system method which loads library
//speaktoc.java
public class SpeaktoC {
public  native String showstring(String astr);
static{
System.loadLibrary(“CallCodeasLIB”);
}
}
i;e in my case
C:\android-ndk-r4\samples\JnihelloJni\src\ex\jnihellojni>javac SpeaktoC.java

results in SpeaktoC.class.

2. move to bin folder and execute javah command i;e
C:\android-ndk-r4\samples\JnihelloJni\bin>javah -jni ex.jnihellojni.SpeaktoC

resutls in  ex_jnihellojni_SpeaktoC.h

3. Create jni folder in project and copy the above generated header file.

4. Create a .c file and implement the methods generated in the .h file.
5. Dont forget to write android.mk file(check out this for Android.mk structure)
6. Now launch Cywgin and change the current directory to project folder i,e
type the following commands
$ cd /cygwin/c/android-ndk-r4/samples/JnihelloJni
and issue Build command
$ ../../ndk-build.
resuls
SharedLibrary : libcallcodeasLib.so in JnihelloJni/libs/armeabi

7. now call the exported method in the application as shown  below
SpeaktoC c = new SpeaktoC();
String str = c.showstring(); // methos is in Library

Categories: Android Dev

Compile Static Library only using NDK

August 17, 2010 1 comment

In order to build Static library only follow the below steps

If you have multiple libs to build then make Android.mk file for each library  and call those .mk files in the root Android.mk file. On how to write Android.mk file refer Android NDK docs folder

1.    xxxxx/jni/lib1/Android.mk

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

LOCAL_MODULE    :=lib1

LOCAL_SRC_FILES :=aaa.c \
bb.c \
include $(BUILD_STATIC_LIBRARY)

2. xxxxx/jni/lib2/Android.mk

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

LOCAL_MODULE    :=lib2

LOCAL_SRC_FILES :=asdf.c \
qwert.c \

include $(BUILD_STATIC_LIBRARY)

3. /jni/Android.mk

MY_JNI_FOLDER := $(call my-dir)
include $(MY_JNI_FOLDER)/lib1/Android.mk
include $(MY_JNI_FOLDER)/lib2/Android.mk

Now create another file Application.mk

APP_MODULES        := lib1 lib2 // Note that each module  specified here will perform a force build, which yields lib1.a and lib2.a
APP_OPTIM        := release
APP_ABI          := armeabi armeabi-v7a

Now, type build using ndk-build script

xxxxx@NHPC /cygdrive/c/android-ndk-r4b/samples/hello-jni/jni
$ ../../ndk-build

Categories: Android Dev

Phone, Battery, Usage Info/Statistics

August 16, 2010 Leave a comment

As a Android mobile developer type *#*#4636#*#* on any Android deivce/ Emulator to read basic test applications such as

Phone Information,

Battery Inforamtion

Battery History,

Usage statistics

Categories: Android Dev

Recording with Android MediaRecorder API

August 13, 2010 Leave a comment

MediaRecorder API, records in 3 file formats

1. 3gpp

2.AMR

3. Mp4

All there formats uses AMR encoder, code snippet given below recods for any audio source(as) such as:

MediaRecorder.AudioSource.DEFAULT,  MediaRecorder.AudioSource.VOICE_DOWNLINK,

MediaRecorder.AudioSource.VOICE_UPLINK, MediaRecorder.AudioSource.VOICE_CALL

mr = new MediaRecorder();
mr.setAudioSource(as); // as  = Audio Source
mr.setOutputFormat(ff); // ff = FileFormat
mr.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mr.setOutputFile(RECORDING_FILE); // filepath of the recording file
mr.prepare();
mr.start();

Note that, this API is compatible only with Android DONUT, does’nt work with Eclair and Froyo.

Tested and Verfied on LG GT 540 and guess to work with all devices based on this processor.

Microprocessor,Chipset LG GT540 SWIFT (Optimus)

CPU:Clock: 600 MHz
CPU: Qualcomm MSM7227
Browse devices based on this microprocessor
Categories: Android Dev

Getting the latest and right code

August 13, 2010 1 comment

Android website has every detail on how to grab the latest source code, this article is just considered to get the right source code right platform.

After you sync the Android repos, you’ll see output describing the available branches and tags something like this:

 * [new branch]      cupcake    -> korg/cupcake
 * [new branch]      cupcake-release -> korg/cupcake-release
 * [new branch]      donut      -> korg/donut
 * [new branch]      donut-release -> korg/donut-release
 * [new branch]      eclair     -> korg/eclair
 * [new branch]      master     -> korg/master
 * [new branch]      release-1.0 -> korg/release-1.0
 * [new tag]         android-1.0 -> android-1.0
 * [new tag]         android-1.5 -> android-1.5
 * [new tag]         android-1.5r2 -> android-1.5r2
 * [new tag]         android-1.5r3 -> android-1.5r3
 * [new tag]         android-1.5r4 -> android-1.5r4
 * [new tag]         android-1.6_r1 -> android-1.6_r1
 * [new tag]         android-1.6_r1.1 -> android-1.6_r1.1
 * [new tag]         android-1.6_r1.2 -> android-1.6_r1.2

Some time contains other random stuff  and mostly confusing for newbies.

use of the following commands with repo for specific platform souce code.

Repo takes the -b option to specify a branch however, and the cupcake / donut / eclair branches are universal, so those are what I used to make the source archives linked in this article, e.g.:

repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
repo sync

Make sure the Git port is open, the port is 9418 otherwise, timed out errors persists

Categories: Android Dev

Android build errors fix under Ubuntu 10.04

August 13, 2010 1 comment

I’m not going to tale down on how to download and set up android, this article is mainly intended to fix Android build errors while compiling on Ubuntu 10.4

Below are the issue which I personally encountered while building Android sources.

1. bison not found

Install only bison via synaptic package manager

2.  Java version miss match

sudo apt-get remove sun-java6-jre sun-java6-jdk sun-java6-plugin

or

sudo apt-get autoremove sun-java6-jre sun-java6-jdk sun-java6-plugin

To Install java5
sudo apt-get install sun-java5-jre sun-java5-jdk sun-java5-plugin

To check which version of java is enabled
java -version

To change manually the java version

sudo update-alternatives –config java

then choose accordiingly

3. Error: zlib.h no such file or directory
error while compiling android sources with zlib.h not found

cgi.c:22:18: error: zlib.h: No such file or directory
Try this to get zlib.hGenerated: (out/target/product/generic/android-info.txt)
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Installed file list: out/target/product/generic/installed-files.txt

$ sudo apt-get install zlib1g-dev

After that, you might need libncurse

$ sudo apt-get install libncurses5-dev

4: Flex command not found
Flex not found
Try installing flex through synaptic manager
or

sudo apt-get install flex

5. X11/Xlib.h: No such file or directory

Try installing libx11-dev from synaptic package manager

6. sh: gperf: not found

Try installing gperf from synaptic package manager

Finally, generated output files after successul Froyo Build

Generated: (out/target/product/generic/android-info.txt)
Target system fs image: out/target/product/generic/obj/PACKAGING/systemimage_unopt_intermediates/system.img
Install system fs image: out/target/product/generic/system.img
Target ram disk: out/target/product/generic/ramdisk.img
Target userdata fs image: out/target/product/generic/userdata.img
Installed file list: out/target/product/generic/installed-files.txt

Now how to Install self built Android images on Emulator

4. Backup the folder <android_sdk_folder>/platforms/android-8/images (android_sdk_folder is the Android SDK installation folder)

5. Replace the files ramdisk.img, system.img and userdata.img in <android_sdk_folder>/platforms/android-8/images with the files built from above steps.

6. Start the emulator and wait.

That’s it Now Enjoy Phone Emulator with Froyo update.

Categories: Android Dev

Using Safe Mode and Hard Reset on LG GT540

August 9, 2010 2 comments

Using Safe Mode

Turn off you phone and reboot. While your phone is powering  back on , press and hold the Home key during Android log is displayed. your phone will bott all the way to the main screen  and display “safe mode ” in lower left corner.

**For Google Nexus One: Restart phone and press ‘Track Ball’ Button for about 4 sec when Cross Mark icon is displayed.

Reboot phone for normal operations.

Using Hard Reset(factory reset)

If it in any case to restore to the original condition, use hard reset to initialise the target.

When your phone turns on and the lock screen displays, press and hold  the volume up+home key+Search keys all at the same time for about 5 sec. when the pop up screen is shown , choose OK  to reset the phone.

Note** All data and applications on the target(phone) will be erased and cannot be reversed.

Categories: Android Dev