Build Android Applications

Maven for Android

In Codenvy, Android apps are build using dependency-based Maven, and Maven Android Plugin in particular. You can find more information on the plugin at code.google.com. Basically, pom.xml file should contain some obligatory elements, such as dependency on Android version, Maven Android Plugin itself and any other public/private Android libs used in the project. Below is an example of pom.xml of a simple Android app you can create from a template in Codenvy:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.devcolibri</groupId>
    <artifactId>my-android-application</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>my-android-application</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <platform.version>4.1.1.4</platform.version>
        <android.plugin.version>3.8.0</android.plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>${android.plugin.version}</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <platform>16</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Any configuration and ‘fine-tuning’ of a project is mainly performed by introducing changes to pom.xml file (See:  Change Android OS Version)

Add Own Android Library

Use of own libraries in Android projects does not differ from using libs in any other Maven based project. A new dependency should be added to pom.xml file, for examplle:

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>example</artifactId>
        <version>1.1</version>
    </dependency>

If you want to use your own Android lib, please see: Add a Local Library

Download apk File

It is possible to download apk file to test your application on a real Android device. Go to  Project > Build and Publish and wait for the project to be built. After it’s done, you will see a URL to download artifacts where you will find akp file. Download it and push to your Android device.