Skip to content
dzan edited this page Oct 22, 2013 · 32 revisions

#How to build K-9 Mail

Introduction

K-9 Mail targets Java 1.5 (but we're using Java 1.6 @Override annotations, so a Java 1.6 compiler is needed).

The current development version of K-9 Mail runs on Android 2.2 (Froyo) and newer versions. Currently, SDK 4.2.2 (API 17) is needed to build the code.

This document covers several alternatives for building K-9 Mail:

Building with ant

To build

android update project --path . --subprojects --target android-17
android update lib-project -p plugins/Android-PullToRefresh/library/ --target android-17
ant debug

To install on your simulator or local device

adb install -r bin/K9-debug.apk

To build and sign the project for upload to the marketplace (project owner)

You'll need a few new entries in your local.properties to upload to google code:

gcode-user=your-username
gcode-pass=your-secret-token
gcode-project=your project name on google code (defaults to k9mail)

You'll also need googlecode_upload.pl in your path from http://search.cpan.org/dist/Google-Code-Upload/

  1. ant bump-version or ant -Dversion-name=4.200 bump-version: this will tag and push to origin
  2. ant clean release
  3. Test on actual device hardware
  4. ant upload: this puts it on google code.
  5. Upload to the market

Building with Eclipse

Prerequisites

You will need Eclipse with the Android Development Tools plugin installed. If you have not set this up already, then here is a good place that will get you started. Make sure your Android SDK and ADT plugin are both up to date. The following instructions were based on Eclipse Juno (4.2) and ADT Version 22.

You will also need to download the K-9 Mail source repository using Git.

Set up a new workspace

As part of the setup, you will be creating 6 different K-9 Mail related projects inside Eclipse. Because it will be easier to adjust preferences for these projects if they are kept separate from any other projects, you should create a new workspace for use with K-9 Mail.

Start Eclipse. A dialog will likely pop up asking that you select a workspace. If that doesn't happen, then once Eclipse has started, use File -> Switch Workspace -> Other... to bring up the selection dialog. In the dialog, use the Browse button to navigate and make a new folder (somewhere outside of your K-9 Mail source tree) where the new workspace will reside. If Eclipse opens a Welcome window, simply close it to see the workspace windows behind it.

Adjust some workspace preferences

There are likely numerous tweaks to the workspace preferences that would be beneficial (for example, adjustments affecting code style), but for the moment, there are just a couple that should be reviewed:

  1. Text file encoding

    In the Eclipse menu, go to Window -> Preferences. In the dialog, expand the General category and select Workspace. Change the Text file encoding setting to UTF-8. Click Apply to save (the dialog remains open).

  2. Compiler compliance level

    In that same dialog, expand the Java category and select Compiler. Set the Compiler compliance level to 1.6. Click OK to save the settings and close the dialog.

Import the K-9 Mail projects

(Note that the following procedure only works cleanly for K-9 Mail versions 4.503+. To build earlier versions, you will likely need to refer to an earlier edition of this document, such as here from April 3, 2013.)

In the Eclipse menu, go to File -> Import.... In the dialog, expand the Android category and select Existing Android Code Into Workspace. Click Next.

Use the Browse button to navigate to the top folder of the K-9 Mail source tree on your system and click OK. A set of 6 projects should automatically be found and selected for import into the workspace:

  1. k9mail
  2. k9mail-ActionBarSherlock
  3. k9mail-Android-PullToRefresh
  4. k9mail-ckChangeLog
  5. k9mail-HoloColorPicker
  6. k9mail-tests

Click Finish. Eclipse will import the projects and immediately begin building them. You can go to Window -> Show View -> Progress to monitor its progress. Once everything is built, you can click on the Problems tab. You should see no errors and maybe 200+ warnings. This is typical.

Running

If you have an official version of K-9 Mail already installed from either the Play Store or from the Downloads page, you must first uninstall it before you will be able to install your own version. You might want to export and save your settings before uninstalling.

To install and run the app, click on the k9mail project folder in the Project Explorer window, and then follow these general instructions.

You can also install and run the test package. Click on the k9mail-tests project folder in the Project Explorer window, and then follow these general instructions.

Building with IntelliJ IDEA

These instructions are for IDEA 12, but K-9 has successfully compiled under IDEA 9, 10, and 11 in the past.

  1. Checkout K9's source from GitHub.
  2. Open k9mail.ipr in IntelliJ.
  3. You'll get a green dialog in the top right corner asking you to import the Maven POM for ActionBarSherlock and Android-PullToRefresh -- select auto-import.

If you've never done Android development in IntelliJ before, you'll need to add your Android SDK to IntelliJ.

  1. Go to SDKs under Platform Settings
  2. Click the + on top to add a new platform and select Android SDK.
  3. Specify the path to your SDK root. You don't need to navigate to the specific platform you want; just the root is fine.
  4. Select your preferred 1.6 or 1.7 JDK. If you're on 64bit Windows, it's still recommended you select a 32bit SDK, since some of the Android toolchain is still 32 bit.
  5. Select Android 4.1.2 or higher as your platform. This is android-16, the minimum platform we require.

To configure K-9 to use your new SDK, select Project under Project Settings, and choose your Android SDK under Project SDK. You'll need to do this even if you already have an Android SDK configured in IntelliJ since different projects can use different SDKs..

To execute the first build of your project, click on the build icon in the top menu (it looks like a 4-box square with an arrow in the top-left corner to the left of the K-9 dropdown). If it's successful, the Messages pane should pop up with only Information and Warning messages.

Running your project

Click on the Play button to the right of the K-9 entry in the drop-down box. The default is to launch in an emulator. To launch on your device, click on the K-9 drop down, then Edit Configurations. Change the Target Device to either USB Device to always run on your device or Chooser Dialog to select on each launch.

Clone this wiki locally