Official Document link: http://source.android.com/source/using-eclipse.html
This document will help you set up the Eclipse IDE for Android platform development.
Note: If you are looking for information on how to use eclipse to develop applications that run on Android, this is not the right page for you. you probably wocould find the eclipse page on developer.android.com more useful.
Basic setup
First, it's important to make sure the regular Android development system is set up.
cd /path/to/android/root make
Important: You will still be usingmake
To build the files you will actually run (in the emulator or on a device ). you will be using eclipse to edit files and verify that they compile, but when you want to run something you will need to make sure files are saved in eclipse and runmake
In a shell. The eclipse build is just for error checking.
Eclipse needs a list of directories to search for java files. This is called the "Java build path" and can be set with.classpath
File. We have a sample version to start you off.
cd /path/to/android/root cp development/ide/eclipse/.classpath .chmod u+w .classpath
Now edit that copy.classpath
, If necessary.
Increase eclipse's memory settings
The android project is large enough that eclipse's Java VM sometimes runs out of memory while compiling it. Avoid this problem by editingeclipse.ini
File. On Apple OSX the eclipse. ini file is located
/Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.ini
Memory-related defaults (as of eclipse 3.4 ):
-Xms40m -Xmx256m -XX:MaxPermSize=256m
Recommended settings for Android development:
-Xms128m -Xmx512m -XX:MaxPermSize=256m
These settings set eclipse's minimum Java heap size to 128 MB, set the maximum Java heap size to 512 MB, and keep the maximum permanent generation size at the default of 256 MB.
Now start Eclipse:
eclipse
Now create a project for Android development:
If eclipse asks you for a workspace location, choose the default.
If you have a "welcome" screen, close it to reveal the Java perspective.
File> New> JAVA Project
Pick a project name, "android" or anything you like.
Select "Create project from existing source", enter the path to your android root directory, and click Finish.
Wait while it sets up the project. (You'll see a subtle progress meter in the lower right corner .)
Once the project workspace is created, eclipse shoshould start building. in theory, it shocould build with no errors and you shocould be set to go. if necessary, uncheck and re-check Project Build automatically to force a rebuild.
Note:Eclipse sometimes likes to addimport android.R
Statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. this will cause your make to break. look out for these erroneous import statements and delete them.
When you sync
Every time you repo sync, or otherwise change files outside of eclipse (especially the. classpath), you need to refresh eclipse's view of things:
Window> show View> Navigator
In the navigator, right-click on the project name
Click Refresh in the context menu
Adding apps to the build path
The default.classpath
Could des the source to the core system and a sample set of apps, but might not include the particle app you may want to work on. to add an app, you must add the app's source directory. to do this inside Eclipse:
Project> Properties
Select "Java build path" from the left-hand menu.
Choose the "Source" tab.
Click "add folder ..."
Add your app'ssrc
Directory.
Click OK.
When you're done, the "source folder" path in the list shold look like
android/packages/apps/YOURAPP/src
Depending on which app (s) You include, you may also need to includeothersrc/main/java
Directories underandroid/dalvik/libcore
. Do this if you find you cannot build with the default set.
Eclipse formatting
You can import files indevelopment/ide/eclipse
To make eclipse follow the android style rules.
Select WINDOW> preferences> JAVA> code style.
Use formatter> Import to importandroid-formatting.xml
.
Organize imports> Import to importandroid.importorder
.
Debugging the emulator with eclipse
You can also use eclipse to debug the emulator and step through code. First, start the emulator running:
cd /path/to/android/root . build/envsetup.sh lunch 1 make emulator
If the emulator is running, you should see a picture of a phone.
In another shell, start ddms (the Dalvik debug manager ):
cd /path/to/android/root ddms
You shoshould see a splufty debugging console.
Now, in eclipse, you can attach to the emulator:
Run> open debug dialog...
Right-click "remote Java application", select "new ".
Pick a name, I. e. "Android-Debug" or anything you like.
Set the "project" to your project name.
Keep the host set to "localhost", but switch port to 8700.
Click the "debug" button and you shoshould be all set.
Note that port 8700 is attached to whatever process is currently selected in the ddms console, so you need to sure that ddms has selected the process you want to debug.
You may need to open the debug perspective (next to the "Java" Perspective icon in the upper-right, click the small "open perspective" icon and select "debug "). once you do, You shocould see a list of threads; if you select one and break it (by clicking the "pause" icon), It shocould show the stack trace, source file, and line where execution is. breakpoints and whatnot shoshould all work.
Bonus Material
Replace CTRL with the apple key on Mac.
Shortcut |
Function |
CTRL-shift-o |
Organize imports |
CTRL-shift-T |
Load class by name |
CTRL-shift-R |
Load non-class resource by name |
Ctrl-1 |
Quick Fix |
CTRL-e |
Recently viewed files |
CTRL-space |
Auto complete |
Shift-alt-R |
Refactor: Rename |
Shift-alt-V |
Refactor: Move |
Eclipse is not working correctly, what should I do?
Make sure:
You followed the instructions on this page precisely.
Your problems view doesn' t show any errors.
Your application respects the package/directory structure.
If you're still having problems, please contact one of the android mailing lists or IRC channels.