How to view the android source code in eclipse

Source: Internet
Author: User

This articleArticleThe main solution is to solve a problem. When using Android applications, we often encounter the source not find problem. Here I will solve it:

First, you must haveAndroid source codeAndAndroid SDKTo download these two copies, go to the android official website;

Next, we need to use a tool python. The 2.6.2 version I used is already relatively low. Write a script as follows. java file copy to the SDK, the specific path is as follows: android-sdk-windows-1.5_r2/platforms/Android-1.5/sources, the script is saved as fix_android_1.5sdk.py,

The content is as follows:

#! /Usr/bin/Python

# Copyright (c) 2009 Google Inc.
#
# Licensed under the Apache license, version 2.0 (the "License"); you may not
# Use this file before t in compliance with the license. You may obtain a copy
# The license
#
# Http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# Distributed under the license is distributed on an "as is" basis,
# Warranties or conditions of any kind, either express or implied. See
# License for the specific language governing permissions and limitations under
# The license.
#
# Originally written by Mike Forster.
# Http://blog.michael-forster.de/2008/12/view-android-source-code-in-eclipse.html

From _ future _ import with_statement # For python <2.6

"Modifies the android SDK to build Android scripting environment.

This script compiles Android. OS. exec from the android source and adds
Class to the android SDK Android. Jar. In addition, it copies the source files
Into the SDK so that they can be browsed from eclipse.

In order to use this script, you must have download the android source and
Installed the android SDK.
"""

_ Author _ = 'damon Kohler <damonkohler@gmail.com>'

Import OS
Import re
Import shutil
Import subprocess
Import sys
Import zipfile

Def validate_source_and_sdk_locations (src_location, sdk_location ):
If not OS. Path. exists (src_location ):
Print 'android source location is invalid .'
SYS. Exit (1)
If not OS. Path. exists (sdk_location ):
Print 'sdk location is invalid .'
SYS. Exit (1)
Return OS. Path. Join (sdk_location, 'platform', 'android-1.5 ')

Def zip_up_sources (src_location, sdk_location ):
SDK = validate_source_and_sdk_locations (src_location, sdk_location)
Sources = OS. Path. Join (SDK, 'Sources ')
If not OS. Path. exists (sources ):
OS. makedirs (sources)
Print 'copying sources from % s to % s' % (src_location, sources)
# Some files are duplicated, copy them only once.
Written = {}
# Iterate over all java files.
For Dir, subdirs, files in OS. Walk (src_location ):
For filename in [F for F in files if F. endswith ('. Java')]:
# Search package name.
Source = OS. Path. Join (Dir, filename)
With open (source) as F:
For line in F:
Match = Re. Match (R'/S * package/S + ([a-zA-Z0-9/. _] +); ', line)
If match:
Package_path = match. Group (1). Replace ('.', OS. SEP)
Try:
OS. makedirs (OS. Path. Join (sources, package_path ))
Failed t OS. Error:
Pass
Destination = OS. Path. Join (sources, package_path, filename)
If destination not in written:
Written [destination] = true
Shutil. Copy (source, destination)
Break

If _ name _ = '_ main __':
If Len (SYS. argv) = 3:
Src_location, sdk_location = SYS. argv [1: 3]
Else:
Print 'fix _ android_sdk.py <Android-source> <Android-SDK>'
SYS. Exit (1)
Try:
Zip_up_sources (src_location, sdk_location)
Except t keyboardinterrupt:
Print '/naborted .'
Else:
Print 'done! '

 

After installing python on Windows (rememberAdd the python installation path in the path of my computer system variable, for example:C:/program files/python_2.6.2 );

Third, input the script fix_android_1.5sdk.py you just saved in the Windows Command window: fix_android_1.5sdk.py <Android source code directory> <Android SDK directory> (note: <> this symbol is not used when you press it !!) Wait for about 10 minutes and you will have a folder named (android-sdk-windows-1.5_r2/platforms/Android-1.5/sources) under your SDK directory, called sources.

Fourth, restart your eclipse to see it.

Conclusion ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.