Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Ant project reference

Tags:

android

I have an Android project and it has a (Java) project folder reference . I developed with eclipse. Now I want to compile with Ant. What I want to add in build.xml to include the reference.

like image 924
Harikrishnan R Avatar asked Feb 20 '11 11:02

Harikrishnan R


1 Answers

Assuming your project was called 'HelloListview' (say) and you want all your Ant produced binaries to end up outside the Eclipse workspace, then:

Firtsly if you follow the steps here: http://developer.android.com/guide/developing/other-ide.html

under Creating a new Project

Then :

1) copy the build.xml and the build.properties and the local.properties produced in the sample project to your Eclipse project.

2) Edit the first line of the build.xml's project tag which says something like :

<project name="TestProject" default="help">

Change it to just

<project>

3) Now edit the build.properties to define some custom properties that define output locations and set the properties that the Ant main_rules.xml requires to refer to them, like:

#Start of custom properties defined by you
projectname=HelloListView

# The parent of where you want ALL your ant builds to go
outbasebase.dir=/junk/MyAntBuilds

# The binaries for this project
outbase.dir=${outbasebase.dir}/${projectname}

#End of custom properties defined by you

#Ant main_rules.xml refers to these properties
ant.project.name=${projectname}
out.dir=${outbase.dir}/bin
# end of Ant required properties

4) Now at the command line just type 'Ant debug' and your binaries will end up in \junk\MyAntBuilds\HelloListView\bin (or whatever you decide to call it in the build.properties)

You can use the same build.xml for all your projects, as there is no reference to the project in the build.xml itself, you merely have to change the projectname in the build.properties for the new project.

When you get more confident, you can adapt the build.properties to include your keystore name and password to produce release signed builds automatically, by adding lines like:

key.store=c:/users/you/my-release-key.keystore
key.alias=release_alias
key.store.password=YourPwd
key.alias.password=YourPwd

If you want to include external java source then it's best to customise the whole build.xml. Follow the instructions listed in the generated build. xml :

- Customize the whole script.
- copy/paste the content of the rules files (minus the top node)
into this file, *after* the <setup> task
- disable the import of the rules by changing the setup task
below to <setup import="false" />. 
- customize to your needs.

i.e copy the main_rules.xml into your build file and disable the import as described.

Then in the 'compile' target

.....       
.....
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<src path="${common_src}" />     <<<<<<< ADD THIS LINE (OR WHATEVER PROPERTY NAME YOU LIKE TO GIVE IT)
.....
.....

and add a reference to the common_src in your build.properties

common_src=/otherfiles/sourcefolder

.

like image 193
NickT Avatar answered Oct 01 '22 15:10

NickT