Add the android source code to the SDK

Source: Internet
Author: User

The error "source not found" When debugging the android program should be crazy. goolge did not include the source code when releasing the SDK, which is a bit confusing, for many people, git is undoubtedly a raw thing, and all the Java code in the framework adds up to a package, that is, more than 20 mb. Even worse, Android eclipse plugin (ADT) does not allow us to attach the source code to Android. jar in the project properties. Fortunately, Eric Burke finds a way to add source to the SDK. By analyzing the source code of ADT, we know that ADT is under the SDK directory."Sources"Directory to find the source code corresponding to the class, so that we only need to put the source code in the sources directory ADT can automatically find the corresponding source code.

The following question is: which source code should be added to the SDK, and how can we get the source code?
I mentioned in my previous article Android scripting environment.Fix_android_sdk.pyScript, used to solve the problem that android cannot be found during ASE compilation. OS. in fact, this script does another thing, that is, traversing the entire <Android-source> directory and copying all the Java code to the sources directory of the SDK. As mentioned in compilingase of ASE wiki, compiling ASE requires the android code tree, and I told you a clever method, that is, you only need to download the snapshot of the tag Android-1.5r2 of frameworks/base, because android. OS. the exec package is in it, which solves the problem of ASE compilation.

Go back and add the source code to the SDK. With the fix_android_sdk.py script (Here we do not need to compile the Android. OS. Exec package and add it to Android. jar, So I removed this function from the script and click Download the modified script.), If you have downloaded the complete code tree through repo (Note the corresponding version), So everything is very simple. Use the following method to pass the android source code and SDK directory as parameters.
Fix_android_sdk.py <Android-source> <Android-SDK>
After the execution is complete, a sources directory is generated under the \ platforms \ Android-1.5 directory, which contains all the Java code in the android code tree, in addition, each directory is stored according to the package name. When debugging code again, the ADT can find the corresponding source code.

If there is no complete code tree in hand and you want to quickly add the source code to the SDK? After reading the code tree of Android, you will know that in addition to frameworks/base, there are also a lot of framework code in the Dalvik directory, in addition, the commonly used Apache HTTP package is located in the external/Apache-HTTP directory, so you need to obtain the complete framework source code for debugging, we need to download platform/Dalvik from the android code base at least. git, platform/frameworks/base. git, platform/external/apache-http.git. Decompress the downloaded file to the same directory. The directory structure is random. Then, you can use the fix_android_sdk.py script to extract the Java file. Using this method to extract the source code of the Framework is much faster than downloading the entire code, and the extracted results are compared with the complete code tree, only the source code of the application bundled in Android, which we cannot use during debugging, and the code of jdiff, tagsoup, clearsilver and other packages (I have never touched on these three packages, if you think it is necessary, you can download the source code and add the source code according to the method mentioned above, all of which are under platform/external ).

Finally, if you are too lazy to download the above packages and install the python execution environment, we will discuss the source code for Android on Android forum. the jar post is suitable for you. The 10th and 11 floors of the post provide the extracted Android 1.5 SDK source code (although the 100% may not match your SDK, it is always better than the eye-catching source not found), decompress it to the sources directory under your SDK.

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.