Mobile/Fennec/Android/IDEs: Difference between revisions

→‎Really quick start: Add warning that 'mach ide intellij' doesn't seem to work for mach artifact
(→‎Really quick start: Add warning that 'mach ide intellij' doesn't seem to work for mach artifact)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
There is support for building Fennec using Eclipse or IntelliJ in the tree.
There is support for building Fennec using IntelliJ or Android Studio in the tree.


= IntelliJ or Android Studio with Gradle =
= IntelliJ or Android Studio with Gradle =


This is the direction that IDE support is moving towards.
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.


== Pre-requisites ==
== Pre-requisites ==


The Gradle build requires the ''Android Support Repository'' and ''Google Repository'' Android packages. Install them by navigating to the ''Extras'' section of the SDK list shown by the <tt>android</tt> tool (shipped with the Android SDK).
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 <tt>android</tt> tool (shipped with the Android SDK).


The [http://mxr.mozilla.org/mozilla-central/source/mobile/android/gradle/app/build.gradle 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 [http://mxr.mozilla.org/mozilla-central/source/mobile/android/gradle/app/build.gradle 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.
Line 27: Line 32:


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


Try:
Try:
Line 100: Line 107:


nalexander has a slightly [http://www.ncalexander.net/blog/2014/10/23/building-fennec-with-gradle-and-intellij-first-steps/ outdated blog post] that describes an earlier version of this basic setup with IntelliJ.  It includes a short video tutorial.
nalexander has a slightly [http://www.ncalexander.net/blog/2014/10/23/building-fennec-with-gradle-and-intellij-first-steps/ outdated blog post] that describes an earlier version of this basic setup with IntelliJ.  It includes a short video tutorial.
= 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.
== Prerequisities ==
* [http://eclipse.org/ Eclipse] (Luna 4.4 is recommended; Kepler 4.2 should work as well)
* the most recent [https://developer.android.com/tools/sdk/eclipse-adt.html Eclipse ADT plugin]
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 [http://stackoverflow.com/a/11093228 this stack overflow answer].  If you don't, you might hit GC issues because Android’s <code>dex</code> 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 <code>mach build-backend</code> 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 <code>mach build-backend</code>.  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 <code>mach build-backend -b=AndroidEclipse</code>.  Why do the Eclipse project directories look so empty?
The answer is [http://www.ncalexander.net/blog/2014/07/08/how-the-android-eclipse-integration-works/ complicated], but it's because some of things needed for a working Eclipse project require <code>mach build && mach package</code> 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!


= Support =
= Support =


The first place to ask questions is #mobile on irc.mozilla.org.  Start there.
The first place to ask questions is [https://wiki.mozilla.org/Mobile/Get_Involved#IRC #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 is the architect and implementer of most of the Eclipse integration.  rnewman, mcomella, and liuche all run, or have run, the integration as part of their daily development.  bnicholson contributed significantly to earlier versions of this work.


nalexander's [http://www.ncalexander.net/blog/ blog] is usually the first place to find tutorials, screencasts, and previews of new features.
nalexander's [http://www.ncalexander.net/blog/ blog] is usually the first place to find tutorials, screencasts, and previews of new features.
Line 193: Line 116:
= Additional resources =
= Additional resources =


There is a [http://www.ncalexander.net/blog/2014/06/24/better-fennec-builds-with-an-eclipse-plugin/ getting started screencast].  There is also a [http://www.ncalexander.net/blog/2014/03/24/eclipse-mini-tutorials/ series of video mini-tutorials].
There's a blog post discussing [http://www.ncalexander.net/blog/2014/07/08/how-the-android-eclipse-integration-works/ technical details of how the Eclipse build integration works].


There's a blog post discussing [http://www.ncalexander.net/blog/2014/07/08/how-the-android-eclipse-integration-works/ 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]].
46

edits