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

There is support for building Fennec using IntelliJ or Android Studio in the tree.

IntelliJ or Android Studio with Gradle

This is the direction that IDE support is moving towards. Most Android front-end developers are using IntelliJ with Gradle today. We support building, running, and debugging Java and Android resources with IntelliJ. We support editing JavaScript (but not debugging) JavaScript as well.


The Gradle build requires the following additional Android packages:

  • Android Support Repository
  • Google Repository

Install them by navigating to the Extras section of the SDK list shown by the android tool (shipped with the Android SDK).

The gradle config files also explicitly specify the version (e.g., SDK v21 and build tools v21.1.1), in order to decrease IntelliJ problems in detecting the right version of Android tools to use. See bug 1123013 for details.

The Gradle/IDE integration requires Android-Gradle plugin version 1.0.0. This, in turn, mandates either

  • IntelliJ 14.0.3 or higher (currently Early Access Preview only!); or
  • Android Studio 1.0.0 or higher.
See bug 1120032 for details.

Installing specific versions of the Android SDK and build tools

To list all Android packages, including those marked Obsolete, use:

 android list sdk --all --extended

You should see entries like:

 id: 6 or "build-tools-21.1.1"
      Type: BuildTool
      Desc: Android SDK Build-tools, revision 21.1.1 (Obsolete)

To install a particular version, use a command like the following:

 android update sdk --all --no-ui --filter "build-tools-21.1.1"

Really quick start

Warning: this doesn't seem to work for a mach artifact build, follow the Quick Start instructions below instead.


 ./mach ide intellij


 ./mach ide androidstudio

That should build and package your tree, prepare the IDE files, and open the project in the IDE of your choice.

Unfortunately, IntelliJ (and maybe Android Studio) follows the symlink, giving the wrong path in the import dialog. Correct the path manually so that it is $OBJDIR/mobile/android/gradle, where $OBJDIR is your object directory. (The correct directory is printed by the mach ide command.) Select OK to complete the import. Try it out by choosing Build > Rebuild project!

The mach ide command always builds and packages your tree, so it can be a little slow. After you've run it once, you can usually just open the existing project in your IDE directly.

Quick start

  1. Build and package your tree:
    ./mach build && ./mach package
  2. Configure Gradle to build Fennec. Do not skip this step: it configures your object directory for Gradle.
    ./mach gradle-install
  3. Optionally, verify that Gradle can build Fennec:
    ./mach gradle build
  4. Finally, import the newly created Gradle projects into IntelliJ/Android Studio:
    • File > Import Project... and select $OBJDIR/mobile/android/gradle, where $OBJDIR is your object directory. (The correct directory is printed by the mach gradle-install command.)
    • Select Import project from external model > Gradle > Next.
    • Select Use customizable gradle wrapper > Finish.
  5. You'll need to configure your Android SDK. Go to File > Project Structure, and then
    • Select Android API 21 platform for the Project SDK (or whatever is appropriate for your configuration). You may be prompted to add a JAVA SDK first: your IDE should find a JDK 1.7 or 1.8 install automatically.
    • Select 7 - Diamonds, ARM, multi-catch etc. for the Project language level.

You should have a shiny new Gradle-based project in your IDE! Try it out by choosing Build > Rebuild project.

Trouble shooting

General build/SDK problems

Before asking in #mobile, check the following:

  • Are you running at least IntelliJ 14.0.3, the EAP/preview version. You can change your update channel in IntelliJ > Preferences > (search) Updates, and select "Early Access Program" as your update channel.
  • Do you have an Android SDK in your project structure? Make sure that in File > Project Structure > SDKs, you have a JRE as well as an Android SDK. If you don't have the latter, go back to the instructions and try Step 5 to configure your Android SDK.
  • Is the Gradle configuration working?
 ./mach gradle build
  • Do your Android SDK tools match what's required in the gradle config files? (compileSdkVersion and buildToolsVersion)
  • Is Gradle busted?
 ./mach gradle clean assembleDebug
  • If you've pulled in changes to the Gradle configuration lately, refresh Gradle: View > Tool Windows > Gradle and click the blue "sync" button in the top left.
  • If changes don't seem to be taking, make sure the cache is cleared with File > Invalidate caches. Restart.
  • Does your error look like Error: Internal error: ( $OBJDIR/mobile/android/gradle/.idea/misc.xml (No such file or directory)? Try running mach gradle-install and re-importing $OBJDIR/mboile/android/gradle.

Why aren't my JavaScript changes being noticed?

The Gradle configuration recognizes JavaScript changes (like mobile/android/chrome/content/browser.js and mobile/android/modules/Messaging.jsm) underneath the mobile/android directory. It does not recognize changes in other places in the tree, including under toolkit/. To make Gradle pick up your changes, modify a JavaScript file under mobile/android. Or, if you have a command line handy, run

mach build mobile/android/base/gradle-omnijar

Then re-run Gradle; you should find your changes are noticed.

Import problems

Due to incompatibilities between IntelliJ 14.0.2 and the Android-Gradle plugin version 1.0.0, there's a bug with importing in IntelliJ 14.0.2 that manifests as completed imports with no source directories. IntelliJ 14.0.3 with Android-Gradle plugin version 1.0.0 should not have the issue; Android Studio 1.0.0 should be fine too. See bug 1120032 for details.

Debugging problems

There's a known bug that can make debugging start but fail to stop at breakpoints when using IntelliJ 14.0.2. It's due to incompatibilities between IntelliJ 14.0.2 and the Android-Gradle plugin version 0.14.4. IntelliJ 14.0.3 with Android-Gradle plugin version 1.0.0 should not have the issue; Android Studio 1.0.0 should be fine too.


IntelliJ/Android Studio can require a good deal of memory:

  • Optionally, toggle Show Memory Indicator;
  • you might need to increase memory in $INTELLIJ/bin/idea.vmoptions. Suggested values for min and max are:
    • Xms512m
    • Xmx2048m

Additional file types

You might want to add * and other preprocessed files to Settings > File Types > Java source files. This will help you browse the few preprocessed files remaining, including

Video tutorial

nalexander has a slightly outdated blog post that describes an earlier version of this basic setup with IntelliJ. It includes a short video tutorial.


The first place to ask questions is #mobile on IRC. nalexander is the architect and implementer of most of the Eclipse integration. rnewman, mcomella, mhaigh, liuche, and margaret all run the integration as part of their daily development. bnicholson contributed significantly to earlier versions of this work.

nalexander's blog is usually the first place to find tutorials, screencasts, and previews of new features.

Additional resources

There's a blog post discussing technical details of how the Eclipse build integration works.

Historically, Fennec supported building with Eclipse. Eclipse support is now deprecated, but the documentation is archived at Mobile/Fennec/Android/IDEs/Eclipse.