android官方文档:使用Eclipse来debug android源码
2011-05-11 13:11
337 查看
官方文档链接: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 would find the Eclipse page on developer.android.com more useful.
Important: You will still be using
Eclipse needs a list of directories to search for Java files. This is called the "Java Build Path" and can be set with the
Now edit that copy of
Memory-related defaults (as of Eclipse 3.4):
Recommended settings for Android development:
These settings set Eclipse's minimum Java heap size to 128MB, set the maximum Java heap size to 512MB, and keep the maximum permanent generation size at the default of 256MB.
Now start 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 should start building. In theory, it should build with no errors and you should be set to go. If necessary, uncheck and re-check Project Build Automatically to force a rebuild.
Note: Eclipse sometimes likes to add an
Window > Show View > Navigator
In the Navigator, right-click on the project name
Click Refresh in the context menu
Project > Properties
Select "Java Build Path" from the left-hand menu.
Choose the "Source" tab.
Click "Add Folder..."
Add your app's
Click OK.
When you're done, the "source folder" path in the list should look like
Depending on which app(s) you include, you may also need to include
Select Window > Preferences > Java > Code Style.
Use Formatter > Import to import
Organize Imports > Import to import
If the emulator is running, you should see a picture of a phone.
In another shell, start DDMS (the Dalvik debug manager):
You should 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 change Port to 8700.
Click the "Debug" button and you should 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 should see a list of threads; if you select one and break it (by clicking the "pause" icon), it should show the stack trace, source file, and line where execution is at. Breakpoints and whatnot should all work.
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.
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 would 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 using
maketo 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 run
makein 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 the
.classpathfile. 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 of
.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 editing the theeclipse.inifile. On Apple OSX the eclipse.ini file is located at
/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 128MB, set the maximum Java heap size to 512MB, and keep the maximum permanent generation size at the default of 256MB.
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 should start building. In theory, it should build with no errors and you should be set to go. If necessary, uncheck and re-check Project Build Automatically to force a rebuild.
Note: Eclipse sometimes likes to add an
import android.Rstatement 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.classpathincludes the source to the core system and a sample set of apps, but might not include the particular 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's
srcdirectory.
Click OK.
When you're done, the "source folder" path in the list should look like
android/packages/apps/YOURAPP/src
Depending on which app(s) you include, you may also need to include
othersrc/main/javadirectories under
android/dalvik/libcore. Do this if you find you cannot build with the default set.
Eclipse formatting
You can import files indevelopment/ide/eclipseto make Eclipse follow the Android style rules.
Select Window > Preferences > Java > Code Style.
Use Formatter > Import to import
android-formatting.xml.
Organize Imports > Import to import
android.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 should 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 change Port to 8700.
Click the "Debug" button and you should 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 should see a list of threads; if you select one and break it (by clicking the "pause" icon), it should show the stack trace, source file, and line where execution is at. Breakpoints and whatnot should 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.
相关文章推荐
- 使用eclipse来开发android源码的官方文档
- 解决使用EclipseDebug进入到JDK源码无法查看运行时变量的问题
- eclipse工具使用技巧&关联Android源码
- 使用eclipse来开发android源码
- Eclipse与Android源码中ProGuard工具的使用
- Android Studio官方文档之从Eclipse迁移到Android Studio开发篇
- 使用Eclipse开发Android源码
- Eclipse与Android源码中ProGuard工具的使用
- 如何在Eclipse中导入Android源码(使用的是别人的图片)
- Android Studio 使用教程(十四)之Android Studio导入Eclipse项目源码
- Eclipse与Android源码中ProGuard工具的使用
- eclipse使用git插件下载android源码
- 怎样使用Eclipse来开发Android源码
- 使用Eclipse开发Android源码
- 使用Eclipse开发Android源码
- 使用Eclipse开发Android源码
- #android-ndk-r8d 使用 独立 编译 工具链 官方文档 中文版
- Android源码学习之如何使用eclipse+NDK
- android官方文档:ubuntu10.04下编译android源码之初始化编译环境 Initializing a Build Environment
- android源码和文档查看 eclipse