Search code examples
androidmavenandroid-maven-plugin

Setting filtered resources with Android maven plugin


I'm using maven in an Android project and the Android Maven Plugin v4.0.0 to compile it.

Mi issue is, I have different configuration properties in the pom in case of I want to compile for develop, release...and get the proper values that I want in /target/filtered-res. For example:

pom.xml

<profile>
    <id>release</id>
    <activation>
        <property>
            <name>release</name>
        </property>
    </activation>
    <properties>
        <!-- server for release -->
        <server.host>server.release.com</server.host>
        <server.port>443</server.port>
    </properties>
</profile>
<profile>
    <id>develop</id>
    <activation>
        <property>
            <name>develop</name>
        </property>
    </activation>
    <properties>
        <!-- server for develop -->
        <server.host>server.develop.com</server.host>
        <server.port>8080</server.port>
    </properties>
</profile>

And then in mi res folder, in properties.xml:

<!-- Server -->
<string name="host">${server.host}</string>
<string name="port">${server.port}</string>

By this way I always have the proper configuration in target/filtered-res, properties.xml.

<!-- Server -->
<string name="host">server.release.com</string>
<string name="port">443</string>
<!-- Configuration if I've compiled for release -->

All of this worked with the old Android Maven Plugin (com.jayway.maven.plugins.android.generation2) v3.6.0 with the following configuration:

<plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <extensions>true</extensions>
    <version>3.6.0</version>
    <configuration>
        <manifest>
            <debuggable>true</debuggable>
        </manifest>
        <sdk>
            <platform>${android.platform}</platform>
        </sdk>
        <resourceDirectory>${project.build.directory}/filtered-res</resourceDirectory>
    </configuration>
</plugin>

Setting the resource directory as I want, the "filtered-res" with the proper configuration.

But, when upgrade to Android Maven Plugin 4.0.0, when compile it fails showing following message:

[WARNING] Non-standard location of Android res folder found, but not configured:
/Users/myUser/RepoGit/workspace/myProject/res
Move to the standard location src/main/res/
Or configure resourceDirectory.

And the configuration is the same than before...

<plugin>
    <groupId>com.simpligility.maven.plugins</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <extensions>true</extensions>
    <version>4.0.0</version>
    <configuration>
        <manifest>
            <debuggable>true</debuggable>
        </manifest>
        <sdk>
            <platform>${android.platform}</platform>
        </sdk>
        <resourceDirectory>${project.build.directory}/filtered-res</resourceDirectory>
    </configuration>
</plugin>

As you can see, the resource directory is set... but the plugin claims and the building fails.

I could move my res folder to /src/main/res as the warning message says...but that didn't solve my issue because my filtered resources with the proper values are located in /target/filtered-res.

Anyone could tell me what is wrong?

And, if nothing is wrong and that is a bug of the plugin... Is there another way to compile with different configurations from the pom file?

NOTE: Downgrade to the old Android Maven Plugin is not an option.

Any help will be appreciated.

Thanks a lot and sorry for this really big post.


Solution

  • The new plugin is following a new folder structure.

    I would encourage you to switch to that proper file structure. res & assets needs to be in src/main/ instead of directly in the root of the project.

    The second solution is to disable that error using a flag (read the error msg a bit higher to see that information and the name of the flag but I wouldn't recommend that solution)