`
isiqi
  • 浏览: 16498144 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

android官方文档:使用Eclipse来debug android源码

阅读更多

官方文档链接: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 findthe Eclipse page on developer.android.commore 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 usingmaketo 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 runmakein 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:

  1. If Eclipse asks you for a workspace location, choose the default.

  2. If you have a "Welcome" screen, close it to reveal the Java perspective.

  3. File > New > Java Project

  4. Pick a project name, "android" or anything you like.

  5. Select "Create project from existing source", enter the path to your Android root directory, and click Finish.

  6. 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 animport 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:

  1. Window > Show View > Navigator

  2. In the Navigator, right-click on the project name

  3. 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:

  1. Project > Properties

  2. Select "Java Build Path" from the left-hand menu.

  3. Choose the "Source" tab.

  4. Click "Add Folder..."

  5. Add your app'ssrcdirectory.

  6. 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 includeothersrc/main/javadirectories underandroid/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.

  1. Select Window > Preferences > Java > Code Style.

  2. Use Formatter > Import to importandroid-formatting.xml.

  3. 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 should see a splufty debugging console.

Now, in eclipse, you can attach to the emulator:

  1. Run > Open Debug Dialog...

  2. Right-click "Remote Java Application", select "New".

  3. Pick a name, i.e. "android-debug" or anything you like.

  4. Set the "Project" to your project name.

  5. Keep the Host set to "localhost", but change Port to 8700.

  6. 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.

分享到:
评论

相关推荐

    android4.4源码 android-19源代码

    《深入剖析Android 4.4源码:基于Android-19》 Android 4.4,代号KitKat,是谷歌发布的Android操作系统的一个重要版本,它在2013年推出,带来了许多新特性和性能优化。对于开发者来说,理解其源码能够深入洞悉系统...

    Android环境搭配--myeclipse,eclipse

    使用Eclipse或MyEclipse提供的编辑器编写AndroidManifest.xml、Activity类、布局文件等,使用DDMS(Dalvik Debug Monitor Service)进行调试,最后通过Run或Debug按钮启动AVD运行应用。 9. **源码管理** 开发过程...

    android4.4源码下载

    然后,你可以用以下命令初始化并下载Android 4.4 KitKat的源码: ``` mkdir -p ~/android_src cd ~/android_src repo init -u https://android.googlesource.com/platform/manifest -b android-4.4 repo sync ...

    如何使用Eclipse来开发Android

    在IT行业中,Eclipse是一款备受开发者喜爱的集成开发...不过,随着Android Studio的普及,虽然Eclipse仍然是一个可选的开发工具,但更多的新特性和支持已经迁移到Android Studio,建议新手优先学习使用Android Studio。

    Android程序设计基础_光盘源码

    本资源"Android程序设计基础_光盘源码"提供了基于ANDROID SDK 3.1的源代码,这对于初学者和有经验的开发者来说都是宝贵的参考资料。 首先,我们来了解Android SDK 3.1中的关键组成部分: 1. **Android SDK Manager...

    Android源码编译流程.pdf

    1. 获取源码:使用`git`命令从官方仓库克隆源码到本地,例如`git clone https://android.googlesource.com/platform/frameworks/base.git`。 2. 安装Java环境:建议同时安装`sun-java6-jdk`和`sun-java5-jdk`,确保...

    TE/OK6410 Android应用程序开发指南 - 飞凌嵌入式.pdf

    - 在Ubuntu10.10系统上编译Android源码,形成文件系统和SDK开发包。 - 安装必要的开发工具,如Eclipse和Android Development Tools (ADT)。 - 设置开发环境,包括环境变量的配置和运行Android模拟器。 2. **...

    Android应用开发入门教程(经典版).pdf

    - **源码和文档**: 提供了Android系统的源码和官方文档。 ##### 2.2 Android SDK环境安装 - **步骤**: 1. **安装JDK**: 安装Java Development Kit作为基础的开发环境。 2. **安装Eclipse**: Eclipse是Android...

    Android源码编译流程借鉴.pdf

    在命令行中,使用`make`命令来编译整个Android源码,这将是一个耗时且资源密集的过程。如果只需要编译特定模块,可以使用`mmm`指令,如`mmm packages/apps/AlarmClock`来编译“AlarmClock”应用。对于部分源码的快速...

    Android应用开发入门教程(经典版)

    - **使用am工具启动Android应用程序**:使用命令行工具启动应用。 #### 六、Android的UI系统实现 - **UI的基本外形和控制**: - **事件响应方法**:处理触摸、点击等事件。 - **键盘事件的响应**:处理键盘输入。...

    android-12.zip

    3. **编写代码**:使用Java或Kotlin进行编码,利用Android SDK提供的API实现功能。 4. **构建与调试**:通过Android Studio的构建工具编译代码,并使用模拟器或实际设备进行测试。 5. **发布应用**:完成调试后,...

    Google-Android-SDK.rar_android

    《Google Android SDK——Android开发入门指南》 在移动应用开发领域,Android系统占据了主导地位,而...学习过程中,建议结合Android官方文档、开发者博客、在线课程等资源,以全方位提升自己的Android开发技能。

    Android源码导入Eclipse步骤详解

    在Android开发过程中,有时我们需要查看或修改Android的源代码,这时就需要将Android源码导入到开发环境中,Eclipse作为早期常用的Android开发IDE,是很多开发者的选择。以下将详细讲解如何将Android源码导入Eclipse...

    Android SDK + Systrace

    在使用Systrace时,开发者通常会结合Android Profiler(在Android Studio中)来分析内存泄漏、CPU使用率、线程状态等,以全方位优化应用性能。 总结来说,Android SDK和Systrace是Android开发者不可或缺的工具。...

    android pdf 国外经典书籍

    - **Java视图在Eclipse**:使用Eclipse作为集成开发环境(IDE),可以创建、编辑和构建Android应用程序。通过Eclipse的Java视图,开发者可以管理项目资源,编写代码,并查看项目的结构。 - **模拟器**:Android...

    Ubuntu10.04下配置MTK6573的Android编译运行环境

    - 最低硬件要求:足够的内存(至少2GB),足够的硬盘空间(推荐20GB以上用于Android源码和编译产物)。 2. **安装基本开发工具**: - 安装Ubuntu的开发工具包,包括GCC编译器、Git以及必要的库,通过运行以下命令...

Global site tag (gtag.js) - Google Analytics