Android Ant Build - Android Automated
Build
I
Setup Environment
(set
Environment variable JAVA_HOME to
c:\Program Files\Java\jdk1.6.0 )
(set
path variable for it ,if not set, to your sdk directory like c:\ adt-bundle-windows-x86-20130911\sdk\tools
)
(Installing
apache ant:
1.download
latest binary distribution zip of ant and extract it .
2 copy
the extract file in c:\Ant folder(you
have to create this folder)
3.set
ANT_HOME environment variable to c:\Ant
4. set
JAVA_HOME environment variable to c:\Program Files\Java\jdk1.6.0 (path of java directory in your pc).
5. set
path of ant to c:\Ant\bin
6.
check installation ,open cmd and type
ant
this
will show a message like:
Buildfile:
build.xml does not exist!
Build
failed
7.
this show your installation is
successful)
Now, Take your any project developed in eclipse or any other
IDE. I am taking project from eclipse.
Step 1 : Copy
your project folder from Eclipse Workspace to the Desktop
Step 2 : Create
keystore file using keytool command
1
|
keytool -genkey -v -keystore <file
name="">.keystore -alias <alias name=""> -keyalg
RSA -keysize 2048 -validity 365</alias></file>
|
Step 3 : Copy
keystore file in your project folder
Step 4 : Create "ant.properties" file
using any text editor, this file contain information about keystore file.
create your keystore file `
1
|
key.store=MyAndroidApp.keystore
|
|
2
|
key.alias=myapp
|
3
|
key.store.password=password
|
4
|
key.alias.password=password
|
Step 4 : Create
"default.properties" file,
If you have created project using eclipse, this file will available, If not
create file with following content, change api level as per your project.
01
|
# This file is automatically generated by Android Tools.
|
|
02
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
03
|
#
|
|
04
|
# This file must *NOT* be checked in Version Control
Systems,
|
05
|
# as it contains information specific to your local
configuration.
|
|
06
|
|
07
|
|
|
08
|
# location of the SDK. This is only used by Ant
|
09
|
# For customization when using a Version Control System,
please read the
|
|
10
|
# header note.
|
11
|
sdk.dir=/Users/kpbird/android-sdk-macosx
|
Step 6 : Create "build.xml" with following content, change project name "MyAndroidProject".
<project default="help"
name="MyAndroidProject">
<property
file="local.properties"></property>
<property
file="ant.properties"></property>
<loadproperties
srcfile="project.properties"></loadproperties>
<fail
message="sdk.dir is missing. Make sure to generate local.properties using
'android update project' or to inject it through an env var"
unless="sdk.dir">
</fail><import
file="${sdk.dir}/tools/ant/build.xml">
</import></project>
Step 7 : Now,
It's time to start build, open terminal, go to the project folder and execute
following command
1
|
ant release
|
Step 8 : You APK
file will be at following path.
1
|
Project Folder -> bin ->
MyAndroidProject-release.apk
|
Summary
Create following files in your Project Folder and execute "ant release" command
1. keystore
2. ant.properties
3. default.properties
4. local.properties(
it must
be in your project folder if not you have to generate it
type this
after going the root of your project folder:
C:\users\sourabh\desktop
\android update project -p \MyAndroidApp -t 1
“here
‘android update project’ is command and –p is option for path of your project
and \MyAndroidApp is my project path which is
in
C:\users\sourabh\desktop
and –t(optional if your target set ) used for target id which android-18 or 1 in my project
you can check your target id by typing
android list targets
.
)
5. build.xml
For more information you can refer following link
http://developer.android.com/guide/developing/projects/projects-cmdline.html
http://developer.android.com/guide/developing/projects/projects-cmdline.html