Q:

How to use profiles with Maven and Android properly?

My target is to use two different profiles for different deployment phases (development, release), since release has for example debug flag to false while development has debug flag to true. When I build without profiles, it works without problems. But when I put the build section into a profile, Eclipse complains with the following message: "Project build error: Unknown packaging: apk", although the build itself works.
My questions are:

How can I get rid of the error message when using profiles (there are
also solutions at SO which work, but not when using profiles).
Is it possible to configure a common configuration build base for two profiles while "overriding" some configs in the profile itself? For example profile one has <debug>true</debug> and profile two has <debug>false</debug> or do I have to write the whole build section in both profiles?

Here is my pom.xml  
<?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.mydomain</groupId>
    <artifactId>myartifact</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>apk</packaging>
    <name>My App</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <platform.version>4.4.2</platform.version>
        <android.version>19</android.version>
        <android.plugin.version>3.8.2</android.plugin.version>
        <java.version>1.6</java.version>
        <android.sdk.path>/opt/android-sdk-linux</android.sdk.path>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <junit.version>4.8.2</junit.version>
        <mockito.version>1.9.5</mockito.version>
        <jackson.version>1.9.13</jackson.version>
        <hamcrest.version>1.3</hamcrest.version>
        <annotations.version>4.1.1.4</annotations.version>
        <supportv4.version>r13</supportv4.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>android</artifactId>
            <version>${platform.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v4</artifactId>
            <version>${supportv4.version}</version>
        </dependency>
        <dependency>
            <groupId>com.nineoldandroids</groupId>
            <artifactId>library</artifactId>
            <version>2.4.0</version>
        </dependency>
        <!-- LInt Annotations -->
        <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>annotations</artifactId>
            <version>${annotations.version}</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- Non Android Tests --><!-- hamcrest must be before JUnit due to build errors -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>${hamcrest.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>1.5.1</version>
        </dependency>

        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>1.5.1</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>devel</id>
                <build>
                <finalName>${project.artifactId}</finalName>

                <plugins>
                    <plugin>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.5.1</version>
                        <configuration>
                            <source>${java.version}</source>
                            <target>${java.version}</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <artifactId>maven-jarsigner-plugin</artifactId>
                        <version>1.2</version>
                    </plugin>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <version>2.5</version>
                        <configuration>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                        <artifactId>android-maven-plugin</artifactId>
                        <version>${android.plugin.version}</version>
                        <extensions>true</extensions>
                        <configuration>
                            <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                            <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                            <resourceDirectory>${project.basedir}/res</resourceDirectory>
                            <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                            <sdk>
                                <platform>${android.version}</platform>
                                <path>${android.sdk.path}</path>
                            </sdk>
                            <undeployBeforeDeploy>false</undeployBeforeDeploy>
                            <sign>
                                <debug>true</debug>
                            </sign>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
            </profile>
    </profiles>
</project>

A:

I think this is what you are looking for:
<profiles>
    <profile>
        <id>development</id>
        <properties>
            <debug>true</debug>
        </properties>
    </profile>
    <profile>
        <id>release</id>
        <properties>
            <debug>false</debug>
        </properties>
    </profile>
</profiles>

<build>
    <finalName>${project.artifactId}</finalName>

    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-jarsigner-plugin</artifactId>
            <version>1.2</version>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>${android.plugin.version}</version>
            <extensions>true</extensions>
            <configuration>
                <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                <resourceDirectory>${project.basedir}/res</resourceDirectory>
                <nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
                <sdk>
                    <platform>${android.version}</platform>
                    <path>${android.sdk.path}</path>
                </sdk>
                <undeployBeforeDeploy>false</undeployBeforeDeploy>
                <sign>
                    <debug>${debug}</debug>
                </sign>
            </configuration>
        </plugin>
    </plugins>
</build>

This way you have one common build tag and two profiles, each profile specified whether to debug or not via the properties tag. Then when building you specify your profile like this: -Pdevelopment or -Prelease. Hope it helps.

