Link Android Source Code to Eclipse

來源:互聯網
上載者:User

Long story short: Android source code needs to be placed in a "sources" subdirectory of the Android SDK.

1. Download the code

2. Move code to "sources" subdirectory of the Android SDK.

 

Where to put the Source Code?

To find out what the default location for source code is, please refer to Eric Burke's blog (ref. 2).

Inside com.android.ide.eclipse.adt.project.internal.AndroidClassspathContainerInitializer

.java

IPath android_src = new Path(AdtPlugin.getOsAbsoluteAndroidSources());<br />

Inside com.android.ide.eclipse.adt.project.internal.AdtPlugin

.java

/** Returns the absolute android sources path in the sdk */<br />public static String getOsAbsoluteAndroidSources() {<br /> return getOsSdkFolder() + getOsRelativeAndroidSources();<br />}<br />/** Returns the android sources path relative to the sdk folder */<br />public static String getOsRelativeAndroidSources() {<br /> return AndroidConstants.FD_ANDROID_SOURCES;<br />}<br />

Inside com.android.ide.eclipse.adt.project.internal.AndroidConstants

public static final String FD_ANDROID_SOURCES = "sources";

 

So the code should be placed into:
[SDK_PATH

]/sources/

In SDK1

.5, should be:
[SDK_PATH

]/platforms/android-1.1/sources

[SDK_PATH

]/platforms/android-1.5/sources


Wh
at is the code tree structure?

SDK_PATH | android.jar  +--docs/...  +--samples/...  +--sources    +--android       |      ...accounts, annotation, app, bluetooth, etc...    +--com/android/etc...    +--dalvik/...    +--java/...    +--javax/...

How to pack the Source Code?

You can zip the source code and then unzip it into sources. You can use the Python script written by Mike (ref. 1)

from __future__ import with_statement # for Python < 2.6<br />import os<br />import re<br />import zipfile<br /># open a zip file<br />DST_FILE = 'sources.zip'<br />if os.path.exists(DST_FILE):<br /> print DST_FILE, "already exists"<br /> exit(1)<br />zip = zipfile.ZipFile(DST_FILE, 'w', zipfile.ZIP_DEFLATED)<br /># some files are duplicated, copy them only once<br />written = {}<br /># iterate over all Java files<br />for dir, subdirs, files in os.walk('.'):<br /> for file in files:<br /> if file.endswith('.java'):<br /> # search package name<br /> path = os.path.join(dir, file)<br /> with open(path) as f:<br /> for line in f:<br /> match = re.match(r'/s*package/s+([a-zA-Z0-9/._]+);', line)<br /> if match:<br /> # copy source into the zip file using the package as path<br /> zippath = match.group(1).replace('.', '/') + '/' + file<br /> if zippath not in written:<br /> written[zippath] = 1<br /> zip.write(path, zippath)<br /> break;</p><p>zip.close()

References:

1. View Android Source Code in Eclipse
http://blog.michael-forster.de/2008/12/view-android-source-code-in-eclipse.html

2. Browsing Android Source in Eclipse
http://stuffthathappens.com/blog/2008/11/01/browsing-android-source-in-eclipse/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.