Mobile/Fennec/Android/IDEs/Eclipse

From MozillaWiki
< Mobile‎ | Fennec‎ | Android‎ | IDEs
Jump to: navigation, search

Deprecation Warning

At one time, building Fennec with Eclipse was supported. That support has now been completely superseded by support for IntelliJ (or Android Studio) with Gradle. This page is archived merely for reference.

You want Mobile/Fennec/Android/IDEs.

Eclipse

Building Fennec with Eclipse requires a custom Eclipse plugin.

The preliminary Eclipse support landed in bug 853045, and further enhancements are tracked at bug 924961. bug 1029232 landed the changes that require the custom Eclipse plugin.

There is a getting started screencast. There is also a series of video mini-tutorials.

Prerequisities

You'll need a Mozilla source tree, like fx-team or mozilla-central, and your mozconfig configured to build Fennec (see [Mobile/Fennec/Android#Setup_Fennec_mozconfig]). You'll probably want to increase Eclipse's memory limits, as described in this stack overflow answer. If you don't, you might hit GC issues because Android’s dex takes a good deal of memory.

Install the custom plugin

Installing the plugin is easy. The plugin is available to install from an Eclipse update site at https://people.mozilla.org/~nalexander/eclipse/update-site/. In Eclipse, navigate to Help > Install New Software.... Add the update site with Name: fennec-eclipse and Location: https://people.mozilla.org/~nalexander/eclipse/update-site/. Select OK, and you should see the Fennec Make Build Plugin. Check the box and click Next... to install it. After you've installed, you may need to restart Eclipse.

Prepare the Mozilla source tree

First, run

 mach build && mach package

That builds all the C/C++ libraries that Fennec needs, and installs them into the correct location. Then, run

 mach build-backend -b=AndroidEclipse

That writes Eclipse project files and other support files needed to build in Eclipse. Make a note of the path that mach build-backend outputs; that path contains the Eclipse project files, and you'll need it in a moment.

Import the project files into Eclipse

In Eclipse, go to File > Import... and select General > Existing Projects into Workspace. Enter the path printed by mach build-backend. You should see many projects, including one named Fennec. We want that one, and all its dependencies; at the moment, that means

  • Fennec
  • FennecOmnijar
  • FennecResources
  • FennecResourcesBranding
  • FennecResourcesGenerated

Test your Eclipse configuration

You should be able to build in Eclipse now! Try a clean build by selecting Project > Clean.... If all goes well, you will end up with no errors and a great deal of warnings.

Try to deploy an Eclipse-built Fennec to your device. Right click the Fennec project, and select Run as... > Android Application. You should see messages about uploading APKs in the Android Console pane, and you should see Fennec start on your device.

Frequently asked questions

  • I've run mach build-backend -b=AndroidEclipse. Why do the Eclipse project directories look so empty?

The answer is complicated, but it's because some of things needed for a working Eclipse project require mach build && mach package to happen first, and (technically) a build backend happens before build and package time. The Eclipse project directories are filled during the first Eclipse build (by the custom Eclipse plugin).

  • I'm getting errors building with Eclipse. What should I do?

Your first step is to go to Eclipse > Preferences... > Android > Build and set the Build output setting to Normal. That will show logging from the custom plugin and from the Eclipse Android integration that can help.

Your second step is to try refreshing all projects (Right click projects > Refresh) and then doing a clean build (Project > Clean build ...).

  • I clobbered and now my Eclipse projects are gone!

The Mozilla build system doesn't have much support for writing to a location that's not the object directory (yet!). That means that when you clobber (delete the object directory entirely), the Eclipse projects get deleted. That's okay, though: you can reconstitute them by re-running

 mach build-backend -b=AndroidEclipse
  • I can import some projects (like FennecResources) but not the main Fennec project.

Make sure you're using General > Existing Projects into Workspace and not Android > Existing Android Code into Workspace. For reasons unknown, the latter doesn't recognize some of the generated projects.

The custom Eclipse plugin

What the plugin does

The plugin is conceptually simple: as the first step of the Eclipse build for each project, it executes a single shell command (if necessary). Indeed, it replaces a custom ANT build invocation that did exactly the same work. Some of the advantages of the plugin are

  • error markers in the Eclipse Problems pane
  • build output in the Eclipse Android Console
  • faster builds
  • it is less likely to cause the build to loop forever.

Source code

The source code for the plugin (and the related Eclipse feature and update site) is hosted at https://github.com/ncalexan/fennec-eclipse. Pull requests are always welcome!