Pages

Get it free, Try now

Free Cell Phones

Tuesday, August 17, 2010

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

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

Compile Static Library only using NDK

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

Monday, August 16, 2010

Phone, Battery, Usage Info/Statistics

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

Friday, August 13, 2010

Recording with Android MediaRecorder API

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

Getting the latest and right code


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

Android build errors fix under Ubuntu 10.04

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.

Monday, August 9, 2010

Using Safe Mode and Hard Reset on LG GT540

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.

How to root Android based LG GT540

For the GT540, LG introduced an additional level of security in the engineering application. It didn't really work out so well.

To enable Superuser access (root) on your GT540: - Turn on the device and click the icon to open the phone dialler - Enter the code '3845#*540#' - Select the option 'Module Test', then 'Stability Test' then 'Enable Root Permission' - You will now be prompted for a password - enter :SWIFT::GT540: - A toast message will briefly appear saying 'OK' - your root access is now enabled! - Reboot your device, and now when you connect via ADB, you'll see you have a root prompt (#).

Thursday, August 5, 2010

How to browse/attach android source code in Eclipse

android sources for acitivity class

Many Android developers spend more time in browsing Android sources ONLINE, But the following note is how to browse android source code offline with eclipse. below steps are confirmed to work on Win7 and Ubuntu 10.04. drop me a note if you have any issue(s).

steps:

1. create folder named "sources" in android_sdk  i,e in my case

xxx/android-sdk-linux_86/platforms/android-8/sources

2. The public SDK source is found in android_src/frameworks/base/core/java.
Under that folder you’ll find an 'android' directory, which should be copied (or symlinked) over to the sources directory in your SDK installation.
i:e /home/br/bin/U/android-sdk-linux_86/platforms/android-8/sources/android

3.Now extract all the sources of android into folder 'sources'

/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/android** copied from path "androd_src/frameworks/base/core/java"
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/bionic
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/bootable
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/build
/home/br/bin/U/android-sdk-linux_86/platforms/android-8/sources/cts
/home/br/bin/U/android-sdk-linux_86/platforms/android-8/sources/dalvik
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/development
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/device
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/external
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/frameworks
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/hardware
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/libcore
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/ndk
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/packages
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/prebuilt
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/sdk
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/system
/home/xx/bin/U/android-sdk-linux_86/platforms/android-8/sources/Makefile

4. click refresh on projct explorer or restart eclipse,and to test just open any android class file, jus open activity.class and there you go...

Next steps will follow on how to build  User defined shared (.so)and static libraries using Android NDK and SDK