自制android1.5源码包

具体参考如下:
[url]http://www.williamhua.com/2009/04/29/git-and-repo-for-dummies/[/url]
[url]http://blog.michael-forster.de/2008/12/view-android-source-code-in-eclipse.html [/url]

注意:在做sources.zip的时候不能是用主干来做,要切换到origin/android-sdk-1.5_r3分支下,我是这么做的

$ git checkout origin/android-sdk-1.5_r3 -b sdk1.5r3

否则在debug的时候会定位错误; 今天刚接触这东西,不熟瞎试的,好像还要在.repo/manifest/目录下能执行上面的命令

另外用mike's blog里的python抽取java源文件好像太多了,我稍微修改一下,把android.jar包里面没有的java类都去了。

在自己建的源代码根目录建get_source.py这么个文件:

Python代码
from __future__ import with_statement  # for Python < 2.6   

import os
import re
import zipfile

# open a zip file
DST_FILE = 'sources.zip'
CLASS_FILE_PATH = '/home/don/desktop/android/'
if os.path.exists(DST_FILE):
print DST_FILE, "already exists"
exit(1)
zip = zipfile.ZipFile(DST_FILE, 'w', zipfile.ZIP_DEFLATED)

# some files are duplicated, copy them only once
written = {}

# iterate over all Java files
for dir, subdirs, files in os.walk('.'):
for file in files:
if file.endswith('.java'):
# search package name
path = os.path.join(dir, file)
with open(path) as f:
for line in f:
match = re.match(r'\s*package\s+([a-zA-Z0-9\._]+);', line)
if match and os.path.exists(CLASS_FILE_PATH + match.group(1).replace('.', '/') + '/' + file[0:-4] + 'class'):
# copy source into the zip file using the package as path
zippath = match.group(1).replace('.', '/') + '/' + file
if zippath not in written:
written[zippath] = 1
zip.write(path, zippath)
break;
zip.close()

from __future__ import with_statement # for Python < 2.6

import os
import re
import zipfile

# open a zip file
DST_FILE = 'sources.zip'
CLASS_FILE_PATH = '/home/don/desktop/android/'
if os.path.exists(DST_FILE):
print DST_FILE, "already exists"
exit(1)
zip = zipfile.ZipFile(DST_FILE, 'w', zipfile.ZIP_DEFLATED)

# some files are duplicated, copy them only once
written = {}

# iterate over all Java files
for dir, subdirs, files in os.walk('.'):
for file in files:
if file.endswith('.java'):
# search package name
path = os.path.join(dir, file)
with open(path) as f:
for line in f:
match = re.match(r'\s*package\s+([a-zA-Z0-9\._]+);', line)
if match and os.path.exists(CLASS_FILE_PATH + match.group(1).replace('.', '/') + '/' + file[0:-4] + 'class'):
# copy source into the zip file using the package as path
zippath = match.group(1).replace('.', '/') + '/' + file
if zippath not in written:
written[zippath] = 1
zip.write(path, zippath)
break;
zip.close()对python不熟,不知道怎么读jar文件,我把android.jar解压到了桌面。运行上面代码就能生成干净的sources.zip了。

将sources.zip解压到 sdk目录下platforms/android-1.5/下即可

android-1.5下会多出一个sources文件,源文件就在里面了,重启eclipse就可以用了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值