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>




2010年7月23日星期五

Install XP/Windows 7 by command line

硬盘安装XP的实用方法:
用WINPE x86/x64启动, 运行:
winnt32.exe /syspart:c /tempdrive:c /makelocalsource

硬盘安装windows7:
1、imagex /apply d:\sources\install.wim 5 c: (注意,这里5是指ultimate版,要装其它版本把这个数字换成其它)
2、bcdboot c:\windows /s e: /l zh-CN (一条命令搞定bootmgr和bcd,并把启动菜单设成中文的)
3、bootsect /nt60 e: (写入c:盘的bootmgr引导扇区)   
启动即可继续安装.


硬盘安装windows7的高级实用方法:
1、把镜像用虚拟光驱加载,然后拷贝到任一硬盘分区中,我的是E:\windwos7。  


2、把E:\windwos7目录下的bootmgr和boot目录(其实只要里面的boot.sdi和bcd文件)拷贝到c盘根目录下,并在C盘根目录下建个sources文件夹。(原系统是vista的话需要取得权限,覆盖相应文件,取得权限的方法参照vista区的vista优化大师的右键取得管理权限法)  

3、把E:\windwos7\sources下的boot.win复制到C盘下sourse文件夹。  

4、用管理员身份运行cmd,然后输入c:\boot\bootsect.exe /nt60 c:

(注意,此处bootsect在c:\boot目录下),然后提示successful(即成功了!)
再将系统盘的卷名称改为英文:本地磁盘--bdcp  

5、重启计算机,正在启动安装程序  

6、安装程序启动,选择你要安装的语言类型,同时选择适合自己的时间和货币显示种类及键盘和输入方式。  

7、出现“开始安装界面”,(要注意了,不点击“现在安装”)点左下角“修复计算机”(repair my computer)。  

8、进入“系统恢复选项”,选择最后一项“命令提示符”(command prompt),进入DOS窗口。

9、执行格式化命令format c:/q(注:如C盘是FAT32格式,想转NTFS格式的话,执行format c:/fs:ntfs)。
注:此步可能需要输入卷的名称bdcp  

10、安装系统,输入E:windwos7sourcessetup.exe(注意文件路径是在E盘的windwos7文件夹下的sources文件里),之后就是正常的安装了。

2010年7月13日星期二

Visual Studio 2005 Remote Debugging to Vista and Windows 7

When you run MSVSMON.EXE on Vista and Windows 7, do you get the dreaded message indicating that you need to set the firewall, but when you do, MSVSMON.EXE errors out with an Incorrect Function message? After much struggle, I finally found the trick to remote debugging working correctly. Many thanks to this post on the MSDN Forums from Sam George.

It seems that even with the Vista SP1 Update, MSVSMON.EXE does not properly set the firewall. You'll need to set it up manually with the following batch file:


netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - UDP 137" dir=in action=allow enable=yes localport=137 protocol=udp

netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - UDP 138" dir=in action=allow enable=yes localport=138 protocol=udp

netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - TCP 139" dir=in action=allow enable=yes localport=139 protocol=tcp

netsh advfirewall firewall add rule name="Microsoft Visual Studio Remote Debugger - TCP 445" dir=in action=allow enable=yes localport=445 protocol=tcp

Of course, make sure you run the batch file from an elevated command prompt.