具体参考如下:
[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代码
将sources.zip解压到 sdk目录下platforms/android-1.5/下即可
android-1.5下会多出一个sources文件,源文件就在里面了,重启eclipse就可以用了。
[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就可以用了。