Peter Fortuin
Peter Fortuin

Reputation: 5228

Is there a way to pass ant variables to java code (android)?

I like to include some build variables in my application. For example a buildnumber. Can I pass some variables from a ant build script to my Android application and use that variable in java?

Anybody has a link or example?

Upvotes: 1

Views: 1041

Answers (3)

Manfred Moser
Manfred Moser

Reputation: 29912

Just populate the build number into a string xml file and read it as normal. You can use the replace task to do that..

Dont use a properties file since there is not Android native way to read it. The native way are string values in the xml files. And it is better to replace it into a static strings xml file rather than java source code too.

Upvotes: 2

Scott A
Scott A

Reputation: 7834

Use an ant task (such as replaceregexp) to insert the build numbers and other variables into a class for that purpose.

<replaceregexp file="${my.version.class.file}" match="@version@" replace="@${build.number})@" />

Or something similar. Basically you want to compile the information into a class as part of the build process.

Upvotes: 2

Marcel Offermans
Marcel Offermans

Reputation: 3323

One thing you can do is to first use the "echo" task to create a properties file. That task supports variable substitution, so you can include all build variables. Then include that properties file in your application jar and use the Java Properties to read them.

See:

Upvotes: 0

Related Questions