2010年8月19日星期四

How to build Android source code from source.android.com

Start from the clean Ubuntu 10.04 install, and target to build the Android Éclair.
Learn from : http://devtcg.blogspot.com/2009/03/building-running-and-debugging-android.html
and http://mmmyddd.freeshell.net/wiki/android/build.html.

1. Follow the http://source.android.com/source/download.html instruction,

a) Setup the development environment:

i. $ sudo apt-get install git-core gnupg sun-java5-jdk flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev

ii. $ sudo apt-get install valgrind

2. install and use repo

a) $ curl http://android.git.kernel.org/repo > ~/bin/repo

b) $ chmod a+x ~/bin/repo

3. get source from source.android.com

a) $ mkdir ~/android/éclair; (this folder will be the root folder for build and debug, all command invoke will be from this folder).

b) $ cd ~/android/éclair

c) $ repo init -u git://android.git.kernel.org/platform/manifest.git -b éclair

Note: -b specified the branch, code name is the branch, like éclair, cupcake, donut and froyo.

d) $ repo sync

4. Build the eclair

a) Before build the android, some commands suggest to invoke:

i. $ source ./build/envsetup.sh

ii. $ lunch 1

b) Need export JAVA_HOME and add PATH

 $ export JAVA_HOME=/usr/lib/jvm/java-1.50-sun

 $ export ANDROID_JAVA_HOME=$JAVA_HOME

c) $ make

5. After build success, invoke the ./out/host/linux-x86/bin/emulator to start the android emulator.

6. Import the Android platform source code into eclipse. (we don’t need Android SDK and ADT tool, since we are going to debug the Android build-in application and all tools has been built in the folder ./out/host/linux-x86/bin. Follow the steps from http://source.android.com/source/using-eclipse.html.

Note: create a JAVA project. Not a Android project.

7. Launch ./out/hot/linux-x86/bin/ddms to start the debugging. Once ddms starts, attach the Android process on local machine port 8700 to debug.

8. Blocks the selected application from loading until a debugger attaches. This way you can set a breakpoint in onCreate(), which is important to debug the startup process of an Activity. When you change this option, any currently running instances of the selected application will be killed. In order to check this box, you must have selected a debug application as described in the previous option. You can do the same thing by adding waitForDebugger() to your code.

9 after add android.os.Debug.waitForDebugger(); in first line of onCreate of settings.jave, use following command to rebuild the module and image, of course shutdown the emulator first
$ mmm packages/apps/Settings // rebuild the settings apk
$ make snod // rebuild the system.img
then restart the emulator, select settings, now can attach and debug the application startup.





2010年8月16日星期一

Start using Ubuntu

Install the Ubuntu 10.04 today (08/16) on an external USB disk.
- Install KVpnc and vpnc for the VPN client;
- Install Skype;
- Install Eclipse, apt-get install eclipse (it will install the eclipse platform and JDT and OpenJDK);
- Install Sun Java JDK6;
- Install Android ADT and SDK;
- Install moonlight (silverlight) to listen the music online like "www.1ting.com"; 







2010年8月13日星期五

How to install Sun Java 1.5/1.6 on Ubuntu 10.04

Ubuntu (10.04) only supports Java 1.6 (and prefers OpenJDK too). Here's how to get Sun Java 1.5 installed on Ubuntu 10.04:



Add the following to /etc/apt/sources.list:

deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse

deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse



Update the package list:

sudo apt-get update



Install Sun Java 1.5/1.6:

sudo apt-get install sun-java5-jdk
sudo apt-get install sun-java6-jdk


Depending on your setup you might need to set this as the default. Check what version is default:

java -version


And list all Java versions installed:
sudo update-java-alternatives -l

Then if necessary:
sudo update-java-alternatives -s java-1.5.0-sun
or
sudo update-java-alternatives -s java-1.6.0-sun

2010年8月6日星期五

Learn Android from APK

1. Unpack the APK file by using apktool (http://code.google.com/p/android-apktool/).

Apktool will generate the readable XML files, include the AndroidMenifest.XML and layout XML files. It also will generate the Java bytecode from java class.

2. Rename the APK to ZIP and unzip it, get the DEX file. Using dex2jar (http://code.google.com/p/dex2jar/)
Generate the JAR file.

3. Get Java file by JD (http://java.decompiler.free.fr/).
Generate the java files

4. Using Source Insight to browser the code.

Google Android secret_code for launching hidden activity

Dial *#*#<code>#*#* to launch the hidden activities.

For example:
Dial <*#*#4636#*#*> will be received by "TestingSettingsBroadcastReceiver".

--Phone.java------------------------------------------------------------------------------
static boolean handleSecretCode(Context context, String input) {


// Secret codes are in the form *#*##*#*

int len = input.length();

if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {

Intent intent = new Intent(Intents.SECRET_CODE_ACTION,

Uri.parse("android_secret_code://" + input.substring(4, len - 4)));

context.sendBroadcast(intent);

return true;

}


return false;

}
------------------------------------------------------------------------------

<receiver android:name="TestingSettingsBroadcastReceiver">

<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="4636" />
</intent-filter>
</receiver>
------------------------------------------------------------------------------

<receiver android:name="TestingSettingsBroadcastReceiver">

<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="225" />
</intent-filter>
</receiver>