通常情况下在eclipese的android SDK下新建一个工程(android4.0), 调试到framework里的函数的时候,在那里设置个断点,断点到了之后,按F5进行step into,
这时候会提示找不到framework的代码,因为工程是在android4.0下的AVD调试的,点击attach sources, 选择SDK目录下的sources\android14, 这时就可以进入framework的代码进行单步调试了,因为新的SDK没有2.3之前的代码,所以只能建4.0的。这样可以用SDK例子中的HOME来调试startActivity等的流程。
另外一种方式是用手里编译的framework代码调试,这时候需要新建工程,并把编译出来的framework的image替换点SDK中的image
建下面摘自google的说明。注意是先运行ddms的时候要选择里面要调试的进程,然后再调试framework。
如果手头有手机,就可以用手机代替模拟器,就不用每次编译模拟器了,直接编译手机版的image,用eclipse + 手机(用adb链接ddms) 就可以调试了。
http://source.android.com/source/using-eclipse.html
Using Eclipse 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
make
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 run make
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 the
.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 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
eclipse.ini
file. 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.)
Note: Eclipse sometimes likes to add an
import 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
The default
.classpath
includes 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
src
directory.
- Click OK.
android/packages/apps/YOURAPP/src
Depending on which app(s) you include, you may also need to include
othersrc/main/java
directories under android/dalvik/libcore
. Do this if you find you cannot build with the default set.Eclipse formatting You can import files in
development/ide/eclipse
to 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
.
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.
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 |
- You followed the instructions on this page precisely.
- Your Problems view doesn't show any errors.
- Your application respects the package/directory structure.
1、把eclipse工程配置文件复制到android源码根目录下
android源码文件夹里提供有一些eclipse配置文件,
.claapath:eclipse工程的配置文件,方便我们直接把android源码相应的文件和JAVA包导入工程。
配置内容如下:
。。。。。
2、修改eclipse程序的配置
1)、增大eclipse内存设置
把eclipse.ini(在eclipse软件的安装目录下)的3个值改为下面的值:
-Xms128m
-Xmx512m
【在Android SDK下调试framework】-XX:MaxPermSize=256m
2)、把android-formatting.xml和android.importorder导入eclipse(可选)
android-formatting.xml、.classpath和android.importorder都放在development/ide/eclipse/下
android-formatting.xml用来配置eclipse编辑器的代码风格;android.importorder用来配置eclipse的import的顺序和结构。
在window->preferences->java->Code style->Formatter中导入android-formatting.xml
在window->preferences->java->Code style->Organize Imports中导入android.importorder
3、eclipse上调试android里的程序
把android源码作为一个工程导入eclipse
1)、导入前先检查.classpath里的文件在android源码中是否有相应的文件(文件夹),否则也会破坏android源码(一般是多添加文件/文件夹),.classpath里多余的路径可删除
2)、新建Java Project(不是android project,否则会破坏android源码),选择从已存在的工程导入,工程名任意,完成。
导入时,eclipse要build工程,比较慢。导完后,一般都没有错误。
3)、eclipse中配置调试类型和端口:
在Run->Debug Configurations->Remote java application上双击,然后,”Host:”设为localhost,”Port:”设为8700,”Connection Type”为Standard(Socket Attach)
然后“Apply”。
图1配置调试类型和端口
4、调试程序
①打开DDMS试图,在DDMS中选择一个进程,如图2所示。
图2 选中某一进程
②然后切换到Java试图,选中项目单击右键,DebugAs->Debug Configurations,出现图1的对话框,点击Debug按钮。然后切换到DDMS试图,查看先前所选的进程的前面是否出现,这表示与调试设备已经连接上了,如图3所示。
图3 查看连接
Notes:如果出现连不到VM的错误时,请注意,要先在DDMS中选中某一进程(对应某一应用程序),才能在eclipse执行 Debug。
③在eclipse调试时,可以设断点、单步调试。程序中,首先在所需处设置断点,然后操作手机或虚拟设备,当程序运行到断点处,会出现对话框,如图4所示,询问是否要切换到调试试图,点击Yes即可切换到调试试图,如图5所示。
图4
图5
如图5所示,点击上的按钮或使用快捷键,可以对程序进行单步调试。