在調試Android程序時,有時候我們希望能夠進入Android SDK的代碼中調試。但是官方並沒有提供帶源碼的android.jar包,而如果自己直接使用下載的源代碼,可能與自己的版本不同,導致不可用。
經過一番搜索,找到一外國人的解決方案,自動從代碼倉庫中生成源碼包。此處為原文(英文)鏈接。
我在使用中,發現了一個問題,它的腳本中所寫的代碼倉庫,我無法連接。於是我替換成github上的鏡像倉庫。最終的腳本在這:http://hpaste.org/53385
#!/bin/sh
SRC_DIR=/tmp/android-api
print_syntax() {
echo "Syntax:\n\t$(basename $0) [option]"
echo "\nOptions:"
echo "\t-l prints available versions"
echo "\t-v builds jar file with sources of specified version"
echo "\t-c cleans up the sources from the temp directory\n"
exit 1
}
error() {
echo "Error:" $1
exit 1
}
download_sources() {
if [[ ! -d $SRC_DIR ]]; then
git clone https://github.com/android/platform_frameworks_base.git $SRC_DIR
fi
}
if ! which git > /dev/null ; then
error "git not installed (or not in the PATH)"
fi
if ! which jar > /dev/null ; then
error "jar not installed (or not in the PATH)"
fi
if [[ "$1" == "-l" ]]; then
download_sources
cd $SRC_DIR
git tag -l
exit 0;
fi
if [[ "$1" == "-c" ]]; then
rm -rf $SRC_DIR
exit 0;
fi
if [[ "$1" == "-v" && ! -z "$2" ]]; then
JAR_FILE=$(pwd)/$2-src.jar
download_sources
cd $SRC_DIR
if ! git tag -l | grep $2 ; then
echo "Version \"$2\" not found"
exit 1;
fi
git checkout $2
touch $JAR_FILE
find . -depth 2 -name "java" -type d -exec jar uf $JAR_FILE -C {} . \;
exit 0
fi
print_syntax



