Archive for January, 2012

An exploration into how to use ProGuard for Android obfuscation

http://stackoverflow.com/questions/6542631/android-obfuscate-app-using-proguard-keeps-obfuscating-library-jars-or-is-it

Related

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 Dropbox.com 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

Advertisements

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

What is Linear Layout:

http://developer.android.com/resources/tutorials/views/hello-linearlayout.html

What is added advantage of GLSurfaceView over ImageView:

http://developer.android.com/resources/articles/glsurfaceview.html

How to layout using Layout (XML rules):

http://developer.android.com/resources/articles/layout-tricks-efficiency.html

http://developer.android.com/resources/articles/layout-tricks-stubs.html

http://developer.android.com/resources/articles/layout-tricks-merge.html

What is the difference between Canvas and SurfaceView?

http://developer.android.com/reference/android/view/SurfaceView.html

http://developer.android.com/reference/android/graphics/Canvas.html

How to blur an image:

http://stackoverflow.com/questions/6743969/blur-a-image-at-android

http://stackoverflow.com/questions/7115790/alpha-channel-blur

http://stackoverflow.com/questions/8997109/making-linear-layout-translucent-and-blurry/8997964#8997964

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

https://code.google.com/p/my-kid-livewallpaper/

How to compile the Android NDK examples using command line tools

Complete information is from http://developer.android.com/guide/developing/projects/projects-cmdline.html, 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” (http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html)

2. Android SDK (http://developer.android.com/sdk/index.html)

3. Android NDK (http://developer.android.com/sdk/ndk/index.html)

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 (http://stackoverflow.com/questions/8116113/problems-with-android-ndk-7-and-awk).

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: http://developer.android.com/guide/appendix/api-levels.html

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 http://developer.android.com/guide/publishing/app-signing.html 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:

../../ndk-build
+ 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/build-local.mk
Compile thumb : sanangeles <= importgl.c
Compile thumb : sanangeles <= demo.c
Compile thumb : sanangeles libs/armeabi/libsanangeles.so

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

-set-mode-check:

-set-debug-files:

-set-debug-mode:

-debug-obfuscation-check:

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

-build-setup:
[echo] Creating output directories if needed…

-pre-build:

-code-gen:
[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. R.java and Manifest.java untouched.

-pre-compile:

-compile:

-post-compile:

-obfuscate:

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

-crunch:
[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

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

-package:
[apkbuilder] No changes. No need to create apk.

-do-debug:
[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

debug:
[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

BUILD SUCCESSFUL
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
Success

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)?

https://github.com/DooMLoRD/Xperia-2011-Official-Ramdisks/tree/master/ARC-S http://forum.xda-developers.com/showthread.php?t=1312692 This is one place to get all the kernel source and ramdisk image, in addition to that from Sony Ericsson: http://developer.sonyericsson.com/wp/2011/05/06/how-to-build-a-linux-kernel/ (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:

http://unlockbootloader.sonyericsson.com/instructions

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:

http://www.google.com.sg/search?sourceid=chrome&ie=UTF-8&q=site%3Axda-developers.com+fastboot+%22xperia+arc+s%22+

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

Done.

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:

http://phoneunlockserver.com/forum/index.php?/topic/7-guide-all-xperia-bootloader-unlock-unlock-sim-enable-fastboot/

http://se-board.com/index.php/topic/2023-paid-xperia-2011-bootloader-unlock-here/page__p__8326#entry8326

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).

http://en.wikipedia.org/wiki/SIM_lock

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:

http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

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:

http://developer.sonyericsson.com/wp/2011/05/06/how-to-build-a-linux-kernel/

http://mobilecon.info/sony-ericsson-xperia-ray-root-and-unsecure-boot-img.html

http://mobilecon.info/change-the-stock-kernel-sony-ericsson-xperia-ray-with-doomkernel.html

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 xda-developers.com. (http://forum.xda-developers.com/showthread.php?t=1312859)

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)

Options:
-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

done.

%d bloggers like this: