Tag Archives: aop

AOP on Android – Duplicate files at the same path inside the APK

This post won’t deal with Android/aop configuration, for more information on the subject  I would recommend reading this one.

I’ve been struggling all day to resolve an annoying issue I had with aspectJ, Android and Maven.

When compiling java class files to dex the dex compiler packs everything under the same file, classes.dex. During this process if for any reason you have files with the same name that exist under the same path then you’ll have the dreadful exception “Duplicate files at  the same path inside the APK”.

Whenever using the aspectj maven plugin a configuration file named builddef.lst is created and is placed in the project build output directory. It seems that this is the culprit for duplicate file exception. One way to solve it is to use argumentFileName parameter under the plugin configuration:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.4</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>    <!-- use this goal to weave all your main classes -->
            </goals>
        </execution>
    </executions>
    <configuration>
        <argumentFileName>trace.lst</argumentFileName> <!-- Set the name here -->
        <complianceLevel>1.6</complianceLevel>
        <verbose>true</verbose>
        <showWeaveInfo>true</showWeaveInfo>
        <aspectLibraries>
            <aspectLibrary>
                <groupId>com.blinxbox</groupId>
                <artifactId>aop</artifactId>
            </aspectLibrary>
        </aspectLibraries>
    </configuration>
</plugin>

The problem is the need to give a different name for each library that uses aop, annoying to the say the least.
If only we could remove the configuration file from the final jar/apk, guess what…you can. The jar plugin comes to the rescue:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <excludes>
            <exclude>**/trace.lst</exclude>
        </excludes>
    </configuration>
</plugin>

We are excluding trace.lst and avoiding the problem from the start. Make sure to add this plugin under the build section of your pom file for each jar/apk that uses aop and you are done.

Leave a comment

Filed under Building