Search This Blog

07 May 2010

Multi-module android project

Sometimes we may want to build two different APKs at the same time... let's examine making a multi-module android project....

F:\work> mkdir AndroidModules
F:\work> cd AndroidModules

F:\work\AndroidModules> mvn archetype:generate -DarchetypeCatalog=http://kallisti.eoti.org:8081/content/repositories/snapshots/archetype-catalog.xml
    (choose the galatea-archetype; specify a package, groupId, version, etc...)
    In my case, I am going to do org.eoti.android.module1 and Mod1
   
Now repeat for a second module
F:\work\AndroidModules> mvn archetype:generate -DarchetypeCatalog=http://kallisti.eoti.org:8081/content/repositories/snapshots/archetype-catalog.xml
    (choose the galatea-archetype; specify a package, groupId, version, etc...)
    In my case, I am going to do org.eoti.android.module2 and Mod2

Note that the two packages are different.  In my testing, anytime there were two projects with the same package, deploying the second one (even from a different window) would undeploy the first one as "conflicting".  As such, we will just keep each one to its own subpackage.

Create a top-level pom.xml (change the module names to match your selections above):
<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>org.eoti.galatea</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>AndroidModules</artifactId>
    <packaging>pom</packaging>
    <name>AndroidModules</name>
    <description>Testing a multi-module android project</description>

    <modules>
        <module>Mod1</module>
        <module>Mod2</module>
    </modules>
</project>

Open each modules pom and add a parent to match the top-level pom...  so, in my case, I put these lines just after the 'modelVersion' line in Mod1\pom.xml and Mod2\pom.xml:
    <parent>
        <groupId>org.eoti.galatea</groupId>
        <version>1.0-SNAPSHOT</version>
        <artifactId>AndroidModules</artifactId>
    </parent>


Deploy your new project to the emulator (mvn install). You should see both your projects (Mod1 and Mod2 above) available in the emulator with slightly different Hello World text.  From the top level, doing mvn install will install both and mvn clean will remove both.

No comments:

Post a Comment