android官方文档

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 useEclipse to develop applications that run on Android, this is not the rightpage 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 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:

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

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

  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's src directory.

  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 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 Eclipsefollow the Android style rules.

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

  2. Use Formatter > Import to import android-formatting.xml.

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

  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.

shortcutfunction
Ctrl-Shift-oOrganize imports
Ctrl-Shift-tload class by name
Ctrl-Shift-rload non-class resource by name
Ctrl-1quick fix
Ctrl-eRecently viewed files
Ctrl-spaceauto complete
Shift-Alt-rrefactor:rename
Shift-Alt-vrefactor: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.


世界地图矢量数据可以通过多种网站进行下载。以下是一些提供免费下载世界地图矢量数据的网站: 1. Open Street Map (https://www.openstreetmap.org/): 这个网站可以根据输入的经纬度或手动选定范围来导出目标区域的矢量图。导出的数据格式为osm格式,但只支持矩形范围的地图下载。 2. Geofabrik (http://download.geofabrik.de/): Geofabrik提供按洲际和国家快速下载全国范围的地图数据数据格式支持shape文件格式,包含多个独立图层,如道路、建筑、水域、交通、土地利用分类、自然景观等。数据每天更新一次。 3. bbbike (https://download.bbbike.org/osm/): bbbike提供全球主要的200多个城市的地图数据下载,也可以按照bbox进行下载。该网站还提供全球数据数据格式种类齐全,包括geojson、shp等。 4. GADM (https://gadm.org/index.html): GADM提供按国家或全球下载地图数据的服务。该网站提供多种格式的数据下载。 5. L7 AntV (https://l7.antv.antgroup.com/custom/tools/worldmap): L7 AntV是一个提供标准世界地图矢量数据免费下载的网站。支持多种数据格式下载,包括GeoJSON、KML、JSON、TopJSON、CSV和高清SVG格式等。可以下载中国省、市、县的矢量边界和世界各个国家的矢量边界数据。 以上这些网站都提供了世界地图矢量数据免费下载服务,你可以根据自己的需求选择合适的网站进行下载
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值