Archive for January, 2012

An exploration into how to use ProGuard for Android obfuscation


Using ProGuard with Android.
(Android) Proguard can’t find dynamically referenced class javax.swing.*
android: proguard obfuscating imported jars
Problem med space in path in Proguard parameter call
Android: What are the recommended configurations for Proguard?
android: proguard obfuscating problems
android: proguard obfuscating problem
android proguard, skip jars
Obfuscating Android app with CORBA
How to obfuscate my project using ProGuard tool?
How to suppress ‘Maybe this is program method’ warnings from ProGuard
How to prevent the Proguard obfuscation from destroying jdom.jar
Does using proguard makes the android app running slower?
Getting too many Proguard warnings
Android simplexml.jar proguard problem
Android – Proguard obfuscate not able to find android classes
Is using Proguard with Android worth the effort?
android:onClick not working with ProGuard
Using Proguard to Obfuscate Android App with Libraries
Exclude some classes from Proguard’s keep rules
How to obfuscate an Android library (.jar file) using Proguard in Eclipse
Proguard in Android
Proguard and Android 😦
Weird behaviour while obfuscating a JAR with proguard
Error when proguard Android project

Tasks for learning today: Android GUI, Graphics, Rendering etc

What is Linear Layout:

What is added advantage of GLSurfaceView over ImageView:

How to layout using Layout (XML rules):

What is the difference between Canvas and SurfaceView?

How to blur an image:

my-kid-livewallpaper – Rotating names of my children as my live wallpaper

How to compile the Android NDK examples using command line tools

Complete information is from, here is summarized just the bare minimum (but entirely self-sufficient) to get everything compiled, if you are lazy to read the more complete document.

Necessary tools needed prior to compilation:

1. “ant” (

2. Android SDK (

3. Android NDK (

And the steps are as follows:

a. Due to the “awk” utility as provided by Android NDK is a 64-bit binary, it is necessary to first rename or delete it first (

b. Then traverse to the NDK’s samples directory, and further cd to any of the samples.

c. Then issue “../../ndk-build” to execute the ndk-build as provided by Android NDK.

d. Then issue the “android update” command (here my Android SDK is installed in the /opt directory):

/opt/android-sdk-linux/tools/android update project –path . –target android-10

The target to choose should match the Android version of the your phone:

For example, my Sony Ericsson Arc S is Android 2.3.4, so the target is “android-10” as above.

e. Next compile a debug version (you can compile a release version too, but that will require you to sign the application. (Please refer to for more info).

ant debug

f. Then after connecting the phone to the computer via USB, issue the following command to install the debug apk:

/opt/android-sdk-linux/platform-tools/adb install -r bin/xxxxxxx-debug.apk

where bin/xxxxxxx-debug.apk is the name of the apk generated in the “bin” subdirectory.

The full verbose output as follow:

+ dirname ../../ndk-build
+ PROGDIR=../..
+ cd ../..
+ pwd
+ PROGDIR=/opt/android-ndk-r7
+ [ -n /opt/android-ndk-r7/prebuilt/linux-x86/bin/make ]
+ which /opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ ABS_GNUMAKE=/opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ [ 0 != 0 ]
+ GNUMAKE=/opt/android-ndk-r7/prebuilt/linux-x86/bin/make
+ [ = cygwin ]
+ /opt/android-ndk-r7/prebuilt/linux-x86/bin/make -f /opt/android-ndk-r7/build/core/
Compile thumb : sanangeles <= importgl.c
Compile thumb : sanangeles <= demo.c
Compile thumb : sanangeles libs/armeabi/

+ /opt/android-sdk-linux/tools/android update project –path . –target android-10
Updated file ./proguard.cfg
+ ant debug
Buildfile: /opt/android-ndk-r7/samples/san-angeles/build.xml





[echo] Gathering info for DemoActivity…
[setup] Android SDK Tools Revision 16
[setup] Project Target: Android 2.3.3
[setup] API level: 10
[setup] ——————
[setup] Resolving library dependencies:
[setup] No library dependencies.
[setup] ——————
[setup] WARNING: Attribute minSdkVersion in AndroidManifest.xml (4) is lower than the project target API level (10)

[echo] Creating output directories if needed…


[echo] ———-
[echo] Handling aidl files…
[aidl] No AIDL files to compile.
[echo] ———-
[echo] Handling RenderScript files…
[renderscript] No RenderScript files to compile.
[echo] ———-
[echo] Handling Resources…
[aapt] No changed resources. and untouched.





[dex] No new compiled code. No need to convert bytecode to dalvik format.

[crunch] Crunching PNG Files in source dir: /opt/android-ndk-r7/samples/san-angeles/res
[crunch] To destination dir: /opt/android-ndk-r7/samples/san-angeles/bin/res
[crunch] Crunched 0 PNG files to update cache

[aapt] No changed resources or assets. DemoActivity.ap_ remains untouched

[apkbuilder] No changes. No need to create apk.

[zipalign] No changes. No need to run zip-align on the apk.
[echo] Debug Package: /opt/android-ndk-r7/samples/san-angeles/bin/DemoActivity-debug.apk

[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop
[propertyfile] Updating property file: /opt/android-ndk-r7/samples/san-angeles/bin/build.prop

Total time: 1 second
+ /opt/android-sdk-linux/platform-tools/adb install -r bin/DemoActivity-debug.apk
453 KB/s (19858 bytes in 0.042s)
pkg: /data/local/tmp/DemoActivity-debug.apk

Where to get ramdisk, kernel source, Android OS source, and general utilities like blktrace for Xperia Arc S (Or any Xperia series from Sony Ericsson)? This is one place to get all the kernel source and ramdisk image, in addition to that from Sony Ericsson: (where I can find kernel source, Android source, and many general utilities like blktrace, but not ramdisk?) 

How I unlock the bootloader of Xperia Arc S

Following the instructions on unlocking my Xperia Arc S:

instructions as provided by SonyEricsson, I succeeded in unlocking my Xperia Arc S:

First check the version:

./fastboot-linux -i 0x0fce getvar version
version: 0.3
finished. total time: 0.001s

This is the correct version as the SonyEricsson website said.

And then following the instructions in the URL above, I got my unlock key, which is specific to each handset.

Next download the “fastboot-linux”, or whatever it is renamed as, just search here:

Continue to follow the instruction from SE website, eg, specifying in the fastboot-linux commandline (XXXXXXXX below is the unlock key):

./fastboot-linux -i 0x0fce oem unlock XXXXXXXX

(bootloader) Unlock phone requested
(bootloader) Erasing block 0x00001300
(bootloader) Erasing block 0x00001400
(bootloader) Erasing block 0x00001500
(bootloader) Erasing block 0x00001600
(bootloader) Erasing block 0x00001700
(bootloader) Erasing block 0x00001800
(bootloader) Erasing block 0x00001900
(bootloader) Erasing block 0x00001a00
(bootloader) Erasing block 0x00001b00
(bootloader) Erasing block 0x00001c00
(bootloader) Erasing block 0x00001d00
(bootloader) Erasing block 0x00001e00
(bootloader) Erasing block 0x00001f00
OKAY [ 4.629s]
finished. total time: 4.629s


CAVEAT: Not told to us in the website, is that everything on your phone is wipe out. So my contact list, all my installed and downloaded Android program, all disappeared. If it is a purchased item from Android Market, it is always possible to re-download from “My Apps” (Android Market -> Settings), which is supposedly to list all your previously purchased items from Android Market. But if it is free, then it is not listed, and you have to search and download it again.

PS: Whether unlocking the SIM is the same as unlocking the bootloader, I am not sure, more info here:

But essentially unlocking bootloader allow you to flash a new kernel image on it, which subsequently will boot up Android OS, and also implied customizing Android OS to whatever you want to do.

But unlocking the SIM is to free up the link that tied the baseband processor to communicate with a fixed telecom operator (which does not apply to phones from my country – Singapore).

CAVEAT: Not sure why, but I just discovered that the nand partitioning seemed to be missing the “recovery” and “boot” partition:

# cat /proc/mtd
dev: size erasesize name
mtd0: 19000000 00020000 "system"
mtd1: 00600000 00020000 "appslog"
mtd2: 06580000 00020000 "cache"
mtd3: 1a400000 00020000 "userdata"

# cat /proc/partitions
major minor #blocks name

7 0 35375 loop0
31 0 409600 mtdblock0
31 1 6144 mtdblock1
31 2 103936 mtdblock2
31 3 430080 mtdblock3
179 0 7772160 mmcblk0
179 1 7768064 mmcblk0p1
254 0 35374 dm-0

Well if you compare this image with other Android NAND partitioning like this:

This is definitely quite different, and so all the different instructions on how to reflash new copy of the boot.img to the NAND really puzzle me:

How to install “grep” into /system/bin directory?

My Xperia Arc S comes with toolbox, not busybox, as the wrapper utility for all the Linux command. I am not sure if toolbox has “grep” utility or not, but busybox has.

Trivial problem, but nevertheless documented here for future references:

Assuming rooted Android.

Download the busybox, one version is found in the zergRush rooting guide V3 from (

Now “su” as root and all remaining operation are executed as root.

Put it into /data/tmp directory.

chmod 455 /data/tmp/busybox
# ls -l /data/tmp/busybox
-r--r-xr-x shell shell 1075144 2012-01-02 13:17 busybox
# /data/tmp/busybox mount -o remount,rw /system

# /data/tmp/busybox grep
BusyBox v1.18.4 (2011-04-04 18:40:20 CDT) multi-call binary.

Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

-H Add 'filename:' prefix
-h Do not add 'filename:' prefix
-n Add 'line_no:' prefix
-l Show only names of files that match
-L Show only names of files that don't match
-c Show only count of matching lines
-o Show only the matching part of line
-q Quiet. Return 0 if PATTERN is found, 1 otherwise
-v Select non-matching lines
-s Suppress open and read errors
-r Recurse
-i Ignore case
-w Match whole words only
-F PATTERN is a literal (not regexp)
-E PATTERN is an extended regexp
-m N Match up to N times per file
-A N Print N lines of trailing context
-B N Print N lines of leading context
-C N Same as '-A N -B N'
-e PTRN Pattern to match
-f FILE Read pattern from file

cat /data/tmp/busybox > /system/bin/busybox
chmod 455 /system/bin/busybox
cd /system/bin
ln -s busybox grep
chmod 455 grep


%d bloggers like this: