bauerb | 04c4e1fd | 2016-10-03 15:17:56 | [diff] [blame] | 1 | # Eclipse Configuration for Android |
| 2 | [TOC] |
| 3 | |
| 4 | Instructions on using **Android Studio** are [here](android_studio.md). |
| 5 | |
| 6 | *** note |
| 7 | This documentation was written for Eclipse 4.5 though other versions of Eclipse |
| 8 | should work similarly. |
| 9 | *** |
| 10 | |
| 11 | ## One time Eclipse Configuration |
| 12 | This section contains set up steps for the very first time you start Eclipse. |
| 13 | You should only need to go through these once, even if you switch workspaces. |
| 14 | |
| 15 | * Starting Eclipse. It can be started a couple of ways: |
| 16 | * From Ubuntu main menu, select Applications > Programming > Eclipse 4.5 |
| 17 | * From the command line, type eclipse45 |
| 18 | * Pick a workspace somewhere in your hard drive. |
| 19 | * Install CDT - C/C++ Development Tools |
| 20 | * Select Help > Install New Software... from the main menu |
| 21 | * For Work with, select mars - http://download.eclipse.org/releases/mars |
| 22 | (or any other mirror that seems appropriate) |
| 23 | * Check Mobile and Device Development > C/C++ Remote Launch |
| 24 | * Check Programming Languages > C/C++ Development Tools |
| 25 | * Click through Next, Finish, etc to complete the wizard. |
| 26 | * If you get errors about a missing dependency on org.eclipse.rse.ui for the |
| 27 | "C++ Remote Launch" install, add an available update path of |
| 28 | http://download.eclipse.org/dsdp/tm/updates/3.2 |
| 29 | * Click Restart Now when prompted to restart Eclipse |
| 30 | * Memory |
| 31 | * Close Eclipse |
| 32 | * Add the following lines to `~/.eclipse/init.sh`: |
| 33 | |
| 34 | ```shell |
| 35 | ECLIPSE_MEM_START=1024m |
| 36 | ECLIPSE_MEM_MAX=8192m |
| 37 | ``` |
| 38 | |
| 39 | ## General Workspace Configuration |
| 40 | These are settings that apply to all projects in your workspace. All the |
| 41 | settings below are inside Window > Preferences. |
| 42 | |
| 43 | * Android formatting |
| 44 | * Download [android-formatting.xml](https://raw.githubusercontent.com/android/platform_development/master/ide/eclipse/android-formatting.xml) |
| 45 | * Select Java > Code Style > Formatter from the tree on the left |
| 46 | * Click Import... |
| 47 | * Select the android-formatting.xml file |
| 48 | * Make sure Android is set as the Active Profile |
| 49 | * Java import order |
bauerb | 04c4e1fd | 2016-10-03 15:17:56 | [diff] [blame] | 50 | * Select Java > Code Style > Organize Imports from the tree on the left |
| 51 | * Click Import... |
Ted Choc | 12215a5 | 2018-09-11 16:07:42 | [diff] [blame] | 52 | * Select the `<project root>/tools/android/eclipse/android.importorder` file |
bauerb | 04c4e1fd | 2016-10-03 15:17:56 | [diff] [blame] | 53 | * Disable automatic refresh. Otherwise, Eclipse will constantly try to refresh |
| 54 | your projects (which can be slow). |
| 55 | * Select General > Workspace from the tree on the left. |
| 56 | * Uncheck Refresh using native hooks or polling (if present) |
| 57 | * Select General > Startup and Shutdown from the tree on the left. |
| 58 | * Uncheck Refresh workspace on startup (if present) |
| 59 | * Disable build before launching |
| 60 | * Select Run/Debug > Launching |
| 61 | * Uncheck Build (if required) before launching |
bauerb | 04c4e1fd | 2016-10-03 15:17:56 | [diff] [blame] | 62 | * Tab ordering |
| 63 | * If you prefer ordering your tabs by most recently used, go to General > |
| 64 | Appearance and check Show most recently used tabs |
| 65 | * Autocomplete |
| 66 | * Select Java > Editor > Content Assist |
| 67 | * Check Enable auto activation |
| 68 | * Change Auto activation triggers for Java: to |
| 69 | `._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ` |
| 70 | * Line Length |
| 71 | * If you want to change the line length indicator, go to General > Editors > |
| 72 | Text Editors |
| 73 | * Check Show print margin and change the Print margin column: to 100. |
| 74 | |
| 75 | ## Project Configuration |
| 76 | |
| 77 | ### Create the project |
| 78 | |
| 79 | * Select File > New > Project... from the main menu. |
| 80 | * Select C/C++ > C++ from the project tree and click Next. |
| 81 | * Note: not "Makefile Project with Existing Code", even though that sounds |
| 82 | sensible). |
| 83 | * For Project name, use something meaningful to you. For example |
| 84 | "chrome-android” |
| 85 | * Uncheck Use default location. Click Browse... and select the src directory of |
| 86 | your Chromium gclient checkout |
| 87 | * For Project type, use Makefile project > Empty Project |
| 88 | * For Toolchains use -- Other Toolchain -- |
| 89 | * Click Next |
| 90 | * Disable the default CDT builder |
| 91 | * Click Advanced Settings... |
| 92 | * Select Builders from the tree on the left |
| 93 | * Uncheck CDT Builder |
| 94 | * Click OK if a dialog appears warning you that this is an |
| 95 | 'advanced feature' |
| 96 | * Click OK to close the project properties dialog and return to the project |
| 97 | creation wizard |
| 98 | * Click Finish to create the project |
| 99 | |
| 100 | ### Configure the project |
| 101 | |
| 102 | * Right click on the project and select Properties |
| 103 | * Exclude Resources (OPTIONAL). This can speed Eclipse up a bit and may make |
| 104 | the indexer happier. |
| 105 | * Select Resources > Resource Filters |
| 106 | * Click Add... |
| 107 | * Select Exclude all, Select Folders, and check All children (recursive) |
| 108 | * Enter .git as the name |
| 109 | * Click OK |
| 110 | * Click Apply to commit the changes |
| 111 | * C/C++ Indexer (deprecated, seems to be done by default)</span> |
| 112 | * Select C/C++ General > Indexer from the tree on the left |
| 113 | * Click Restore Defaults |
| 114 | * Check Enable project specific settings |
| 115 | * Uncheck Index source files not included in the build |
| 116 | * Uncheck Allow heuristic resolution of includes |
| 117 | * Click Apply to commit the changes |
bauerb | 04c4e1fd | 2016-10-03 15:17:56 | [diff] [blame] | 118 | * Java |
| 119 | * Create a link from `<project root>/.classpath` to |
| 120 | `<project root>/tools/android/eclipse/.classpath`: |
| 121 | ```shell |
| 122 | ln -s tools/android/eclipse/.classpath .classpath |
| 123 | ``` |
| 124 | |
| 125 | * Edit `<project root>/.project` as follows to make your project a |
| 126 | Java project: |
| 127 | * Add the following lines inside `<buildSpec>`: |
| 128 | ```xml |
| 129 | <buildCommand> |
| 130 | <name>org.eclipse.jdt.core.javabuilder</name> |
| 131 | <arguments></arguments> |
| 132 | </buildCommand> |
| 133 | ``` |
| 134 | * Add the following line inside `<natures>`: |
| 135 | ```xml |
| 136 | <nature>org.eclipse.jdt.core.javanature</nature> |
| 137 | ``` |
| 138 | |
| 139 | ### Run Robolectric JUnit tests |
| 140 | |
| 141 | * Prerequisite: Install a Java 8 JRE and make sure it's available in Eclipse |
| 142 | * Create a new JUnit test target: |
| 143 | * Run > Run Configurations > New launch configuration > JUnit |
| 144 | * Using Android JUnit test launcher |
| 145 | * Test tab: |
| 146 | * Run a single test or all tests in the package you want |
| 147 | * Arguments tab: |
| 148 | * VM arguments: |
| 149 | |
| 150 | ``` |
| 151 | -Drobolectric.dependency.dir=out/Debug/lib.java/third_party/robolectric |
| 152 | ``` |
| 153 | |
| 154 | * Classpath tab: |
| 155 | * Bootstrap Entries: |
| 156 | * Advanced... > Add Library > JRE System Library |
| 157 | * Select a Java 8 JRE |
| 158 | * User Entries: |
| 159 | * Add JARs... |
Brian Ryner | 0e81e84a | 2024-08-28 21:15:52 | [diff] [blame] | 160 | * Select the following JAR file from `third_party/robolectric/cipd/lib`: |
bauerb | 04c4e1fd | 2016-10-03 15:17:56 | [diff] [blame] | 161 | * `android-all-5.0.0_r2-robolectric-1.jar` |
| 162 | * JRE tab: |
| 163 | * Execution environment: Select the Java 8 JRE |
| 164 | * Run or Debug the launch configuration |
| 165 | |