[Entry 7] How to Use eclipse to develop Android source code

Source: Internet
Author: User
Using eclipse + ADT as the android development tool can be said to be very convenient, In the helloactivity small Program We feel the power of Eclipse. So can we use eclipse to develop the android source code? If we directly import a project in the android source code to eclipse, errors will occur in general. Many class libraries (packages) cannot be found. Today, I found the official documentation on how to use eclipse to develop Android source code:
Https://sites.google.com/a/android.com/opensource/using-eclipse
From this document and practice, we can summarize the following points:
1. You can use eclipse to edit Java programs and check for errors (mainly including class library inclusion and syntax). However, you cannot compile and run the android source code on Eclipse, still make (or mm or MMM) in Shell)
2. Some eclipse configuration files are provided in the android source code folder,
. Claapath: the configuration file of the eclipse project, so that we can directly import the file and Java package corresponding to the android source code to the project.
Android-formatting.xml and Android. importorder: This is very important, mainly used to regulate our encoding style, it is easier to make our Code Consistent Style
3. When importing the android source code as a project into eclipse, pay attention to the following two points:
1) the newly created project must be javaproject and cannot be androidproject. Otherwise, the android source code will be damaged (generally multiple files/folders are added)
2) check whether the file in. classpath has a corresponding file (folder) in the android source code before import. Otherwise, the android source code will be damaged (generally add more files/folders)
In general:
1. Use eclipse to edit code and check for errors
2. If you do not compile or run the android source code program on Eclipse, you can only compile the android source code through make (or mm or MMM) on the command line.
3. You can debug the android source code program on Eclipse (Principle: Eclipse uses the ddms server to debug on emulator), and can debug and breakpoint in one step.
Next, we will summarize from the official documents how to use eclipse to develop the android source code.
1. Establish a basic Android Development Environment
Please refer to the official documentation or <Android simulator installation in ubuntu8.10>
2. Compile the android source code
Use make to compile the android source code in the root directory. Pay attention to some configurations. For more information, see <Android source code compilation>
3. Copy the Eclipse project configuration file to the root directory of the android source code.
CP development/IDE/Eclipse/. classpath ./
Chmod U + W. classpath # Make the copy writable
4. modify the configuration of the eclipse Program
1) modify the eclipse cache settings
Change the three values of eclipse. ini (under the eclipse installation directory) to the following values:
-Xms128m
-Xmx512m
-XX: maxpermsize = 256 m
2), the android-formatting.xml and Android. importorder import eclipse
The android-formatting.xml,. classpath, and Android. importorder are all placed in the development/IDE/Eclipse/
Android-formatting.xml is used to configure the code style of the eclipse editor; Android. importorder is used to configure the order and structure of the eclipse import.
Import android-formatting.xml in window-> preferences-> JAVA-> codestyle-> formatter
Import Android. importorder to WINDOW> preferences> JAVA> codestyle> organizeimports.
3) install the anyedit plug-in (optional)
In Http://andrei.gmxhome.de/anyedit/ Download and import eclipse
5. Import the android source code as a project into eclipse
Check Before importing. whether the files in classpath have corresponding files (folders) in the android source code; otherwise, the android source code will be damaged (usually multiple files/folders are added ),. the redundant paths in classpath can be deleted.
Create a new javaproject (not an androidproject; otherwise, the android source code will be damaged) and select import from an existing project. The project name is arbitrary and complete.
It is slow to build a project in eclipse during import. After the import, there are generally no errors.
6. debug the android program on Eclipse.
Run the following command first:
CD Android source code directory
. Build/envsetup. Sh
Lunch 1 # To build the emulator
Emulator & # You shocould see a GUI picture of a phone
Ddms & # You shocould get a splufty debugging Console
Configure the debugging type and port in Eclipse:
Double-click Run-> debug configurations-> remotejavaapplication and set "Host:" to localhost, "port:" To 8700, and "connectiontype" to standard (socketattach)
Then "Apply"
Note: When "debug" is clicked, an error occurs. If Port 8700 is occupied, disable the ddms program and restart the ddms. If the VM cannot be connected, note that you must select a process (corresponding to an application) in ddms before executing debug in eclipse.
During eclipse debugging, you can set breakpoints and perform one-step debugging. It is estimated that the Google team developed and debugged Android applications in this way.
7. Compile the android source code
Run:
CD Android source code directory
. Build/envsetup. Sh
Then there will be more commands such as mm/Mmm, which are used to compile modules (including C, C ++, and Java programs ). You can also run the "make Module name" command in the root directory of the android source code to compile the module.

This article is transferred fromWww.35java.com

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.