filtering resources during maven build

557 views
Skip to first unread message

H.C.

unread,
Apr 6, 2011, 3:58:59 PM4/6/11
to Maven Android Developers
I am trying to filter res/values/strings.xml with some values provided
during build. I have a server url for our REST calls from our android
app which differs between local/dev and qa environments.

I have added the maven-resources-plugin and configured 3 maven build
profiles with different values for the same variable (server_url) and
placed ${server_url} into a string item in res/values/strings.xml.
However, the filter does not seem to be applied.

Is there any reason resource filtering would not work in an android
project with the android maven plugin?

Manfred Moser

unread,
Apr 6, 2011, 4:14:23 PM4/6/11
to maven-androi...@googlegroups.com
Check out the maven android plugin samples projects. The morseflash sample
has a working setup for that.

manfred

> --
> You received this message because you are subscribed to the Google Groups
> "Maven Android Developers" group.
> To post to this group, send email to
> maven-androi...@googlegroups.com.
> To unsubscribe from this group, send email to
> maven-android-deve...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/maven-android-developers?hl=en.
>

H.C.

unread,
Apr 6, 2011, 5:38:20 PM4/6/11
to Maven Android Developers
Perfect!

Thanks a bunch.

HC

Manfred Moser

unread,
Apr 6, 2011, 5:43:15 PM4/6/11
to maven-androi...@googlegroups.com
No problem. Thats why I put it there.. to help other users ;-)

manfred
http://www.simpligility.com

Manfred Moser

unread,
Jun 1, 2012, 2:46:07 PM6/1/12
to Dror, maven-androi...@googlegroups.com, man...@mosabuam.com
Could you improve the morseflash sample app following this approach and
send a pull request and potentially document it on the wiki a bit?

manfred

On Fri, June 1, 2012 11:32 am, Dror wrote:
> there is a problem with this method when using eclipse 3.7 ee (indigo)
> android-maven-plugin 3.2.0, m2e 1.1 (the newest one, or 1.0 some build
> which i had before the update) and both maven 3.03 or 3.04 . using multi
> module, and profile properties.
>
> when you run from maven its fine,
>
> when you run from eclipse, eclipse totally ignores both:
> resourceDirectory
> and androidManifestFile
>
> and it uses the non-parsed ones.
>
> to overcome the issue, i tried some methods:
> puting the files under templates and reource filtering them using the
> maven-resource-plung (resources) to where eclipse searches for them using
> the, gets your files in the eclipse buildpath, which is bad.
> if you use the copy-resources the result is: eclipse adt changes are
> ignored, becuase they are overriden by the template folder.
>
> the solution which i found:
>
> create a src/template/res/values dir
> under it create a file config.xml
> this is the file which you are going to parse.
> all the values of it will appear in R.string (and you can use R.string in
> AndroidManifest.xml)
>
> for example (i want to put the server's host in the manifest in order to
> take over a url):
>
> <?xml version="1.0" encoding="utf-8"?>
> <resources>
> <string name="server_host">${server.host}</string>
> </resources>
>
>
> in my pom.xml:
>
> <properties>
> <server.host>${localIP}</server.host>
> </properties>
>
> <build>
> <plugins>
> <!-- fill my local ip in localIP, for development i opened the
> server on my machine -->
> <plugin>
> <groupId>org.codehaus.groovy.maven</groupId>
> <artifactId>gmaven-plugin</artifactId>
> <version>1.0</version>
> <executions>
> <execution>
> <id>get-local-ip</id>
> <phase>initialize</phase>
> <goals>
> <goal>execute</goal>
> </goals>
> <configuration>
> <classpath>
> <element>
> <groupId>commons-lang</groupId>
> <artifactId>commons-lang</artifactId>
> <version>2.4</version>
> </element>
> </classpath>
> <source>
> java.net.InetAddress
> address=java.net.InetAddress.getLocalHost();
>
> project.properties.localIP=address.getHostAddress();
> </source>
> </configuration>
> </execution>
> </executions>
> </plugin>
> <!-- copy the config.xml file-->
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-resources-plugin</artifactId>
> <version>2.5</version>
> <executions>
> <execution>
> <phase>initialize</phase>
> <goals>
> <goal>copy-resources</goal>
> </goals>
> <configuration>
>
> <outputDirectory>${project.basedir}</outputDirectory>
> <resources>
> <resource>
>
> <directory>${project.basedir}/src/templates</directory>
>
> <targetPath>${project.basedir}</targetPath>
> <filtering>true</filtering>
> </resource>
> </resources>
> </configuration>
> </execution>
> </executions>
> </plugin>
> <plugin>
>
> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
> <artifactId>android-maven-plugin</artifactId>
> </plugin>
> </plugins>
> <pluginManagement>
> <plugins>
> <plugin>
>
> <groupId>com.jayway.maven.plugins.android.generation2</groupId>
> <artifactId>android-maven-plugin</artifactId>
> <version>3.2.0</version>
> <extensions>true</extensions>
> <configuration>
> <sdk>
> <platform>10</platform> <!-- 10 = platform
> 2.3.3 -->
> </sdk>
>
> <deleteConflictingFiles>true</deleteConflictingFiles>
> <undeployBeforeDeploy>true</undeployBeforeDeploy>
> </configuration>
> </plugin>
> <!--This plugin's configuration is used to store Eclipse
> m2e settings only. It has no influence on
> the Maven build itself. but you must have but you must
> have it for m2e-->
> <plugin>
> <groupId>org.eclipse.m2e</groupId>
> <artifactId>lifecycle-mapping</artifactId>
> <version>1.0.0</version>
> <configuration>
> <lifecycleMappingMetadata>
> <pluginExecutions>
> <pluginExecution>
> <pluginExecutionFilter>
>
> <groupId>org.codehaus.groovy.maven</groupId>
>
> <artifactId>gmaven-plugin</artifactId>
> <versionRange>[1.0,)</versionRange>
> <goals>
> <goal>execute</goal>
> </goals>
> </pluginExecutionFilter>
> <action>
> <execute>
> <!-- must set to true -->
>
> <runOnIncremental>true</runOnIncremental>
> </execute>
> </action>
> </pluginExecution>
> </pluginExecutions>
> </lifecycleMappingMetadata>
> </configuration>
> </plugin>
> </plugins>
> </pluginManagement>
> </build>
>
> it will copy all the files under src/templates to your main project dir.
> and therefore you can see them in R.string, but eclipse adt still able to
> change strings.xml
> you are not allowed to put AndroidManifest.xml there. (or eclipse will get
> stuck when you try to run on android (initialize build loop))
>
> for the purpose of eclipse development, don't put strings.xml there, but
> create a new file config.xml or wheatever name you desire, this way adt
> changes will not be ignored.
>
> in the AndroidManifest.xml:
> use @string/server_host (or any other resource which you defined in
> config.xml under templates), instead of ${server.host} which comes from
> the
> property.
>
> this result is:
> all the properties which are in config.xml get filtered and shown in
> R.string properlly.
> AndroidManifest.xml takes those needed props from R.string
>
> i fought with it for more than a day, i hope it helps anyone else who is
> facing the same issue.
>
>
>
> On Thursday, April 7, 2011 12:43:15 AM UTC+3, Manfred Moser (simpligility)
> wrote:
>>
>> No problem. Thats why I put it there.. to help other users ;-)
>>
>> manfred
>> http://www.simpligility.com
>>
>> > Perfect!
>> >
>> > Thanks a bunch.
>> >
>> > HC
>> >
>> > On Apr 6, 1:14�pm, "Manfred Moser" <manf...@mosabuam.com> wrote:
>> >> Check out the maven android plugin samples projects. The morseflash
>> >> sample
>> >> has a working setup for that.
>> >>
>> >> manfred
>> >>
>> >> �> I am trying to filter res/values/strings.xml with some values

Dror

unread,
Jun 1, 2012, 5:54:31 PM6/1/12
to maven-androi...@googlegroups.com, Dror, man...@mosabuam.com
done.
since this was my 1st time with git (im regular to svn), i made a little mess, and accidently delete the default.properties from morseflash-instruments, i added back project.properties.

i also didn't pull the 3.2.1-SNAPSHOT version of android-maven-plugin, so it is set to 3.2.0 which was easier for me.

regarding the wiki, you just need to add :
filter properties for AndroidManifest.xml (take over link example)

btw: this aproach was tested on two win7(eclipse and maven on both) machines, and 1 ubuntu 10.04 (lastest jenkins and maven).
>> >> �> I am trying to filter res/values/strings.xml with some values
>> >> provided
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> > during build. I have a server url for our REST calls from our
>> android
>> >> > app which differs between local/dev and qa environments.
>> >>
>> >> > I have added the maven-resources-plugin and configured 3 maven
>> build
>> >> > profiles with different values for the same variable (server_url)
>> and
>> >> > placed ${server_url} into a string item in res/values/strings.xml.
>> >> > However, the filter does not seem to be applied.
>> >>
>> >> > Is there any reason resource filtering would not work in an android
>> >> > project with the android maven plugin?
>> >>
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> Groups
>> >> > "Maven Android Developers" group.
>> >> > To post to this group, send email to
>> >> > maven-android-developers@googlegroups.com.
>> >> > To unsubscribe from this group, send email to
>> >> > maven-android-developers+unsub...@googlegroups.com.
>> >> > For more options, visit this group at
>> >> >http://groups.google.com/group/maven-android-developers?hl=en.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "Maven Android Developers" group.
>> > To post to this group, send email to
>> > maven-android-developers@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > maven-android-developers+unsub...@googlegroups.com.

Manfred Moser

unread,
Jun 1, 2012, 6:32:56 PM6/1/12
to Dror, maven-androi...@googlegroups.com, Dror, man...@mosabuam.com
Thanks for the pull request. I will try to pull it in. In the future
please do not reformat files since it makes merging much harder since I
have to look much closer to determine what actually changed..
I hope to get it in next week ..


manfred
>> >> >> > maven-androi...@googlegroups.com.
>> >> >> > To unsubscribe from this group, send email to
>> >> >> > maven-android-deve...@googlegroups.com.
>> >> >> > For more options, visit this group at
>> >> >> >http://groups.google.com/group/maven-android-developers?hl=en.
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> Groups
>> >> > "Maven Android Developers" group.
>> >> > To post to this group, send email to
>> >> > maven-androi...@googlegroups.com.
>> >> > To unsubscribe from this group, send email to
>> >> > maven-android-deve...@googlegroups.com.

Andy Dennie

unread,
Jun 12, 2012, 11:05:40 AM6/12/12
to maven-androi...@googlegroups.com, man...@mosabuam.com
Yes, I've got things working with Dror's approach, also.  FYI, I added a couple of comments to the pull request where I noticed a few minor simplifications that could be made.  Thanks!
-AndyD

On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
Nice guys,

I'm using this for my project now !

It is very very handy !

On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
Ah, nevermind, solved it (see SO).  Curious why you didn't encounter it, though...


-Andy

--------------------------------------------- 
aFrogleap BV
Making Mobile Magic

Adres     Delflandlaan 4 
               1062EB Amsterdam
 
Tel          +31 (0)20-7542266
Web        www.afrogleap.nl
Twitter    @afrogleap 
KVK        50419706
---------------------------------------------

On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
Nice guys,

I'm using this for my project now !

It is very very handy !

On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
Ah, nevermind, solved it (see SO).  Curious why you didn't encounter it, though...


-Andy

--------------------------------------------- 
aFrogleap BV
Making Mobile Magic

Adres     Delflandlaan 4 
               1062EB Amsterdam
 
Tel          +31 (0)20-7542266
Web        www.afrogleap.nl
Twitter    @afrogleap 
KVK        50419706
---------------------------------------------

On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
Nice guys,

I'm using this for my project now !

It is very very handy !

On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
Ah, nevermind, solved it (see SO).  Curious why you didn't encounter it, though...


-Andy

--------------------------------------------- 
aFrogleap BV
Making Mobile Magic

Adres     Delflandlaan 4 
               1062EB Amsterdam
 
Tel          +31 (0)20-7542266
Web        www.afrogleap.nl
Twitter    @afrogleap 
KVK        50419706
---------------------------------------------

On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
Nice guys,

I'm using this for my project now !

It is very very handy !

On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
Ah, nevermind, solved it (see SO).  Curious why you didn't encounter it, though...


-Andy

--------------------------------------------- 
aFrogleap BV
Making Mobile Magic

Adres     Delflandlaan 4 
               1062EB Amsterdam
 
Tel          +31 (0)20-7542266
Web        www.afrogleap.nl
Twitter    @afrogleap 
KVK        50419706
---------------------------------------------

On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
Nice guys,

I'm using this for my project now !

It is very very handy !

On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
Ah, nevermind, solved it (see SO).  Curious why you didn't encounter it, though...


-Andy

--------------------------------------------- 
aFrogleap BV
Making Mobile Magic

Adres     Delflandlaan 4 
               1062EB Amsterdam
 
Tel          +31 (0)20-7542266
Web        www.afrogleap.nl
Twitter    @afrogleap 
KVK        50419706
---------------------------------------------

Manfred Moser

unread,
Jun 12, 2012, 1:41:39 PM6/12/12
to maven-androi...@googlegroups.com
Great... I will work on pulling this in today..

On Tue, June 12, 2012 8:05 am, Andy Dennie wrote:
> Yes, I've got things working with Dror's approach, also. FYI, I added a
> couple of comments to the pull request where I noticed a few minor
> simplifications that could be made. Thanks!
> -AndyD
>
> On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
>>
>> Nice guys,
>>
>> I'm using this for my project now !
>>
>> It is very very handy !
>>
>> On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
>>>
>>> Ah, nevermind, solved it (see SO). Curious why you didn't encounter
>>> it,
>>> though...
>>>>
>>>>
>>> -Andy
>>>
>>
>> ---------------------------------------------
>> *aFrogleap** **BV
>> **Making Mobile Magic**
>>
>> **Adres** *Delflandlaan 4
>> 1062EB Amsterdam
>> *Tel** *+31 (0)20-7542266
>> *****Web** **www.afrogleap.nl*
>> *Twitter** *@afrogleap
>> *KVK** * 50419706
>> ---------------------------------------------
>>
>
> On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
>>
>> Nice guys,
>>
>> I'm using this for my project now !
>>
>> It is very very handy !
>>
>> On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
>>>
>>> Ah, nevermind, solved it (see SO). Curious why you didn't encounter
>>> it,
>>> though...
>>>>
>>>>
>>> -Andy
>>>
>>
>> ---------------------------------------------
>> *aFrogleap** **BV
>> **Making Mobile Magic**
>>
>> **Adres** *Delflandlaan 4
>> 1062EB Amsterdam
>> *Tel** *+31 (0)20-7542266
>> *****Web** **www.afrogleap.nl*
>> *Twitter** *@afrogleap
>> *KVK** * 50419706
>> ---------------------------------------------
>>
>
> On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
>>
>> Nice guys,
>>
>> I'm using this for my project now !
>>
>> It is very very handy !
>>
>> On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
>>>
>>> Ah, nevermind, solved it (see SO). Curious why you didn't encounter
>>> it,
>>> though...
>>>>
>>>>
>>> -Andy
>>>
>>
>> ---------------------------------------------
>> *aFrogleap** **BV
>> **Making Mobile Magic**
>>
>> **Adres** *Delflandlaan 4
>> 1062EB Amsterdam
>> *Tel** *+31 (0)20-7542266
>> *****Web** **www.afrogleap.nl*
>> *Twitter** *@afrogleap
>> *KVK** * 50419706
>> ---------------------------------------------
>>
>
> On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
>>
>> Nice guys,
>>
>> I'm using this for my project now !
>>
>> It is very very handy !
>>
>> On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
>>>
>>> Ah, nevermind, solved it (see SO). Curious why you didn't encounter
>>> it,
>>> though...
>>>>
>>>>
>>> -Andy
>>>
>>
>> ---------------------------------------------
>> *aFrogleap** **BV
>> **Making Mobile Magic**
>>
>> **Adres** *Delflandlaan 4
>> 1062EB Amsterdam
>> *Tel** *+31 (0)20-7542266
>> *****Web** **www.afrogleap.nl*
>> *Twitter** *@afrogleap
>> *KVK** * 50419706
>> ---------------------------------------------
>>
>
> On Thursday, June 7, 2012 5:12:40 AM UTC-4, Benoit Billington wrote:
>>
>> Nice guys,
>>
>> I'm using this for my project now !
>>
>> It is very very handy !
>>
>> On Thursday, June 7, 2012 2:34:55 AM UTC+2, Andy Dennie wrote:
>>>
>>> Ah, nevermind, solved it (see SO). Curious why you didn't encounter
>>> it,
>>> though...
>>>>
>>>>
>>> -Andy
>>>
>>
>> ---------------------------------------------
>> *aFrogleap** **BV
>> **Making Mobile Magic**
>>
>> **Adres** *Delflandlaan 4
>> 1062EB Amsterdam
>> *Tel** *+31 (0)20-7542266
>> *****Web** **www.afrogleap.nl*
>> *Twitter** *@afrogleap
>> *KVK** * 50419706
>> ---------------------------------------------
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Maven Android Developers" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/maven-android-developers/-/IPk6TNP4CaMJ.

Manfred Moser (simpligility)

unread,
Jun 14, 2012, 2:09:38 AM6/14/12
to maven-androi...@googlegroups.com, man...@mosabuam.com
Finally got this merged. Sorry for the delay. It will hit the stable samples with the next release of the plugin as usual.
> maven-android-developers@googlegroups.com.
> To unsubscribe from this group, send email to
> maven-android-developers+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages