`

Using Ant to Automate Building Android Applications

 
阅读更多
Using Ant to Automate Building Android Applications

Step1:在命令行进入到需要打包项目目录。

Step2:android update project --path,这样在工程目录下会生成build.xml文件。
Here is an example of successful output:
>android update project --path .
Updated local.properties
Added file C:\dev\blog\antbuild\build.xml

Now you will have a working ant build script in build.xml.  You can test your setup by typing ant at the command prompt, and you should receive something similar to the following boilerplate help:

>ant
Buildfile: C:\dev\blog\antbuild\build.xml
    [setup] Android SDK Tools Revision 6
    [setup] Project Target: Android 1.5
    [setup] API level: 3
    [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.
    [setup] Importing rules file: platforms\android-3\ant\ant_rules_r2.xml

help:
     [echo] Android Ant Build. Available targets:
     [echo]    help:      Displays this help.
     [echo]    clean:     Removes output files created by other targets.
     [echo]    compile:   Compiles project's .java files into .class files.
     [echo]    debug:     Builds the application and signs it with a debug key.
     [echo]    release:   Builds the application. The generated apk file must be
     [echo]               signed before it is published.
     [echo]    install:   Installs/reinstalls the debug package onto a running
     [echo]               emulator or device.
     [echo]               If the application was previously installed, the
     [echo]               signatures must match.
     [echo]    uninstall: Uninstalls the application from a running emulator or
     [echo]               device.

BUILD SUCCESSFUL

If the ant command is not found, then you need to update your path. Like above, on Windows use set path=%PATH%;C:\dev\apache-ant-1.8.1\bin (substituting your actual Ant installation directory), or even better update your environment variables.

At this point you should be able to type ant release at the command prompt, which will build the project, placing the unsigned .apk file inside of the bin/ directory.

Note that the output from Ant will show further instructions under -release-nosign: which says to sign the apk manually and to run zipalign.  We'll get to these steps later in the signing section below.
Creating a new project with build.xml

If you've already created your project and followed the above instructions, you can skip this section. If not, you can may either create a new Android project using the regular Eclipse method (via New > Other... > Android Project), and follow the instructions in the above section, or you can use the command line as described here.

android create project --name YourProjectName --path C:\dev\YourProject --target android-3 --package com.company.testproject --activity MainActivity

Here is an example of successful output:

>android create project --name YourTestProject --path c:\temp\TestProject --target android-3 --package com.company.testproject --activity MainActivity

Created project directory: c:\temp\TestProject
Created directory C:\temp\TestProject\src\com\company\testproject
Added file c:\temp\TestProject\src\com\company\testproject\MainActivity.java
Created directory C:\temp\TestProject\res
Created directory C:\temp\TestProject\bin
Created directory C:\temp\TestProject\libs
Created directory C:\temp\TestProject\res\values
Added file c:\temp\TestProject\res\values\strings.xml
Created directory C:\temp\TestProject\res\layout
Added file c:\temp\TestProject\res\layout\main.xml
Added file c:\temp\TestProject\AndroidManifest.xml
Added file c:\temp\TestProject\build.xml

Note: To see the available targets, use android list target and you should see something like:

>android list target
id: 1 or "android-3"
     Name: Android 1.5
     Type: Platform
     API level: 3
     Revision: 4
     Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P
In the above case, you can use either 1 or android-3 as the target ID.  In the sample project, I chose android-4, which corresponds to Android 1.6.

Once the project is created, you can test if your project build is setup correctly by typing ant at the command line.  See the above section for further instructions.
Synchronizing with Eclipse

If you open the Ant build script, build.xml, in Eclipse, you will see an error on the second line of the file at this line: <project name="MainActivity" default="help">.  The problem with this line is that it is saying that the default Ant target is "help", but the actual Ant targets used in the build file are imported from another location, which the Eclipse editor does not recognize. The import is done at the line <taskdef name="setup", which imports Ant files from the Android SDK.

Unfortunately, while this error is active in your project, you cannot debug your project from Eclipse, even though the Ant build.xml is not needed. There are two solutions. You can remove default="help" from the file, which will remove the error in Eclipse. If you do this, and type ant at a command prompt without any targets (as opposed to "ant release"), you won't get the default help.  Or, you can copy the imported Ant files directly into your code, which is exactly what you must do if you would like to customize your build. If you follow this tutorial, you won't have to worry about this error. See the Customizing the build section for more information.
Automatically signing your application

Before an application can be delivered to a device, the package must be signed. When debugging using Eclipse, the package is technically signed with a debugging key. (Alternatively, you can build a debug package using ant debug) For actual applications delivered to the Android Marketplace, you need to sign them with a real key. It is useful to put this step into the build process. On top of the ease of automating the process, it allows you to build your application in one step. (One-step builds are a Good IdeaTM)

If you have not already created a key, you can do so automatically using Eclipse (Right click project > Android Tools > Export Signed Application Package...), or follow the instructions here.

Now we must tell the build script about our keystore. Create a file called build.properties in your project's base directory (in the same directory as build.xml and the other properties files), if it does not already exist. Add the following lines:
key.store=keystore
key.alias=www.androidengineer.com

Where keystore is the name of your keystore file and change the value of key.alias to your keystore's alias. Now when you run ant release, you will be prompted for your passwords, and the build will automatically sign and zipalign your package.

Of course, having to enter your password doesn't make for a one-step build process. So you could not use this for an automated build machine, for one thing. It also has the disadvantage of requiring you to type the password, which it will display clearly on the screen, which may be a security issue in some circumstances.  We can put the passwords into build.properties as well, which will solve the issue:
key.store.password=password
key.alias.password=password

Caution: There can be several issues with storing the keystore and passwords. Depending on your organization's security policies, you may not be able to store the passwords in version control, or you may not be able to give out the information to all developers who have access to the source. If you want to check in the keystore and the build.properties file, but not the passwords, you can create a separate properties file which could only be allowed on certain machines but not checked in to version control. For example, you could create a secure.properties file which goes on the build machine, but not checked in to version control so all developers wouldn't have access to it; import the extra properties file by adding <property file="secure.properties" /> to build.xml. Finally, you could always build the APKs unsigned with ant release by not adding any information to the properties files.  The package built using this method will need to be signed and aligned.
Customizing the build

Now that we've got a working Ant build script, we can create a one-step build. But if we want to customize the build further, we'll have to do a few extra steps. You can do anything with your build that you can do with Ant. There are a few things we'll have to do first.

The Ant targets are actually located in the Android SDK.  The targets are what you type after ant on the command line, such as release, clean, etc.  To customize the build further, we need to copy the imported targets into our own build file.

If you look in build.xml, you can see the instructions for how to customize your build steps:

The rules file is imported from
<SDK>/platforms/<target_platform>/templates/android_rules.xml
To customize some build steps for your project:
  - copy the content of the main node <project> from android_rules.xml
  - paste it in this build.xml below the <setup /> task.
  - disable the import by changing the setup task below to <setup import="false" />

Find the android_rules.xml file in your Android SDK. For example, mine is located at C:\dev\android-sdk-windows\platforms\android-4\templates. There, copy almost the entire file, excluding the project node (copy below <project name="MainActivity"> to above </project>), and paste it in your build.xml file. Also, change the line <setup /> to <setup import="false"/>.

Now you can change around the build as you please. Test that the build file is still working properly by running a build.  For an example of what you can do with the custom build script, see the next section.
Using a Java configuration file

This is a great way to use a build property to affect the source code of your Android application. Imagine a configuration class in your project which sets some variables, such as a debugging flag or a URL string. You probably have a different set of these values when developing than when you release your application. For example, you may turn the logging flag off, or change the URL from a debugging server to a production server.

public class Config
{
    /** Whether or not to include logging statements in the application. */
    public final static boolean LOGGING = true;
}

It would be nice to have the above LOGGING flag be set from your build. That way, you can be sure that when you create your release package, all of the code you used for debugging won't be included. For example, you may have debugging log statements like this:

if (Config.LOGGING)
{
    Log.d(TAG, "[onCreate] Success");
}

You will probably want to leave these statements on during development, but remove them at release.  In fact, it is good practice to leave logging statements in your source code. It helps with later maintenance when you, and especially others, need to know how your code works. On the other hand, it is bad practice for an application to litter the Android log with your debugging statements. Using these configuration variables allows you to turn the logging on and off, while still leaving the source code intact.

Another great advantage of using this method of logging is that the bytecode contained within the logging statement can be completely removed by a Java bytecode shrinker such as ProGuard, which can be integrated into your build script.  I'll discuss how to do this in a later blog post.

A nice way to set the Config.LOGGING flag is in your build properties.  Add the following to build.properties:
# Turn on or off logging.
config.logging=true

To have this build property be incorporated into our source code, I will use the Ant type filterset with the copy task. What we can do is create a Java template file which has tokens such as @CONFIG.LOGGING@ and copy it to our source directory, replacing the tokens with whatever the build properties values are.  For example, in the sample application I have a file called Config.java in the config/ directory.

public class Config
{
    /** Whether or not to include logging statements in the application. */
    public final static boolean LOGGING = @CONFIG.LOGGING@;
}

Please note that this is not a source file, and that config/Config.java is notthe actual file used when compiling the project. The file src/com/yourpackage/Config.java, which is the copied file destination, is what will be used as a source file.

Now I will alter the build file to copy the template file to the source path, but replace @CONFIG.LOGGING with the value of the property config.logging, which is true. I will create an Ant target called config which will copy the above template to the source directory. This will be called before the compile target.

    <!-- Copy Config.java to our source tree, replacing custom tokens with values in build.properties. The configuration depends on "clean" because otherwise the build system will not detect changes in the configuration. -->
  <target name="config">

  <property name="config-target-path" value="${source.dir}/com/androidengineer/antbuild"/>

  <!-- Copy the configuration file, replacing tokens in the file. -->
  <copy file="config/Config.java" todir="${config-target-path}"
        overwrite="true" encoding="utf-8">
   <filterset>
    <filter token="CONFIG.LOGGING" value="${config.logging}"/>
   </filterset>
  </copy>
 
  <!-- Now set it to read-only, as we don't want people accidentally
       editing the wrong one. NOTE: This step is unnecessary, but I do
       it so the developers remember that this is not the original file. -->
  <chmod file="${config-target-path}/Config.java" perm="-w"/>
  <attrib file="${config-target-path}/Config.java" readonly="true"/>

</target>

To make this Ant target execute before the compile target, we simply add config to the dependency of compile: <target name="compile" depends="config, -resource-src, -aidl". We also make the config target call clean, because otherwise the build system will not detect changes in the configuration, and may not recompile the proper classes.

Note: The above Ant task sets the target file (in your source directory) to read-only.  This is not necessary, but I add it as a precaution to remind me that it is not the original file that I need to edit.  When developing, I will change the configuration sometimes without using the build, and Eclipse will automatically change the file from read-only for me.  I also do not check in the target file into version control; only the original template and build.properties.
Version control

Do not check in the local.properties file which is generated by the Android build tools. This is noted in the file itself; it sets paths based on the local machine. Do check in the default.properties file, which is used by the Android tools, and build.properties, which is the file which you edit to customize your project's build.

I also don't check in the target Config.java in the source directory, nor anything else is configured by the build. I don't want local changes to propagate to other developers, so I only check in the original template file in the config/ directory.

In my projects, when I release a new version of a project I always check in the properties file and tag it in the source repository with a tag name such as "VERSION_2.0". That way we are certain of what properties the application was built with, and we can reproduce the application exactly as it was released, if we later need to.
Summary

1. At the command line run android create project, or android update project in your project base directory if it already exists.
2. (Optional) Add key.store and key.alias to build.properties if you want to include the signing step in your build.
3. (Optional) Add key.store.password and key.alias.password to build.properties if you want to include the keystore passwords, to make the build run without any further input needed.
4. (Optional) If you would like to further customize the build, copy the SDK Ant build code from <SDK>/platforms/<target_platform>/templates/android_rules.xmlto your local build.xml and change <setup /> to <setup import="false"/>.
5. Use ant release to build your project. It will create the package in bin/.
Sample Application

The sample application is a simple Hello World application, but it also includes the custom build script as described in this tutorial.  It also includes the Config.java which is configurable by the build. First, you must run "android update project -p ." from the command line in the project's directory to let the tools set the SDK path in local.properties. Then you can turn on and off logging by changing the value of config.logging in build.properties. Finally, run ant release to build the application, which will create the signed bin/MainActivity-release.apk file ready to be released.

Project source code - antbuild.zip (13.4 Kb)
Posted by Matt Quigley at 2:41 AM   
Email ThisBlogThis!Share to TwitterShare to Facebook

Labels: ant, build
55 comments:


Adecus said...
When I run ant release I get all kinds of errors because it can't find any of the dependencies. Is there an easy way to include the project dependencies or do I have to manually include them by modifying build.xml? (I have dependencies to jar files and other java projects)

I thought the whole point of using the eclipse project to build is because it knows about dependencies and the full project structure, otherwise I mind as well just manually make javac calls with all the dependencies included.

August 23, 2010 at 10:05 AM 

Matt Quigley said...
@Adecus

If your project builds correctly in Eclipse, and after that you create the build file using the "android update" command but the build file doesn't work, then I suppose the Android tools which create the project do not support automatically adding dependencies to the build file. You probably have to manually update it.

August 23, 2010 at 11:57 AM 
Adecus said...
I will try that.

Also, well written informative post, thank you.

August 23, 2010 at 12:16 PM 
Armen B. said...
I was having issues referencing a libaray project. I found this info helpful:

http://www.listware.net/201006/android-developers/56532-android-developers-android-library-broken.html

August 30, 2010 at 6:51 PM 

vgps said...
Thanks a lot for this useful article.

August 31, 2010 at 10:34 AM 

Armen B. said...
Does anyone know how to use ant to build an app that is link sourced to a library project? Thanks.

September 2, 2010 at 2:15 PM 

Anonymous said...
Very useful tutorial. Had to properly set the JAVA_HOME (without blanks) and PATH, but once figured out, it worked out well on Win7. Thanks!

September 20, 2010 at 6:21 PM 

Text Tool said...
Great article and great blog! Thanks for your lessons, I find them really useful.

September 24, 2010 at 1:10 PM 

Anonymous said...
After letting Eclipse update the add-on, I ended having issues building with ant (despite having no problem right before it). Based on some posts I found (from Google staff), changes that are *not* backward-compatible (thank you!) were introduced in the build process. The solution for my project was not to use android_rules.xml to modify build.xml, but rather ant_rules_r3.xml (under /tools/ant). I could apply the other tasks (e.g. config) and it worked fine.

September 24, 2010 at 5:59 PM 

alex said...
how do I specify the library .jar files that are located in the project's \lib folder ?

Is there anything I need to do for the .so files in the project's \libs\armeabi folder ?

Currently I get a lot of errors like: "package org.anddev.andengine.engine does not exist"

Eclipse built it fine, but Ant doesn't know about the \lib it seems like.

October 10, 2010 at 4:43 AM 

Alex said...
the solution was to copy the andEngine library JAR's to the \libs folder (I had them in \lib)

October 10, 2010 at 5:26 AM 

Owen said...
Hi Matt,
excellent article. I have only ever used Eclipse for developing and releasing projects for android, until the use of LVL and Progard became a must have, for security.
I am using Flurry Analytics in my code, so when I process android update and create a build.xml and local.properties file with required changes, I proceed with ant release. Problem is, I am getting "package com.flurry.android not found" error messages. Can you possibly explain why I might be having this problem and what I may be doing wrong? Should I include the Flurry.jar location in my build or properties files?. Your help would be greatly appreciated.

October 11, 2010 at 11:01 AM 

Matt Quigley said...
@Owen

I can't tell if you're getting those errors at runtime or during the build. In any case, the default folder where additional libraries go is ./libs/. You might want to try copying the library file (which I guess is a .jar file) into that folder. Or you could try changing build properties to change the default library directory, but I'd suggest getting it working by moving the .jar file first.

October 11, 2010 at 9:54 PM 

Owen said...
Hi Matt,

Sorry, I should have explained the problem was in the build. But.....

Thanks a million you are a star. Everything worked fine. I also should have noted the post previous to mine (Alex) where he had and resolved the same problem.

Google needs competent support people like you...Keep up the good work. I think it is appreciated by all.

October 13, 2010 at 7:03 AM 

Owen said...
Hi Matt,

I am having alot of problems trying to include the Licensing service in my Ant buid.

I am getting the message:
"com.android.vending.licensing does not exist."

"import com.android.vending.licensing.AESObfuscator;"

default.properties file entry in MyMainProject

android.library.reference.1=c:\\Users\\LeOwen\\LiveProject\\library
-----------------------------------
default.properties file entry in com.android.vending.licensing

android.library=true

target=android-8
--------------------------------

Altough I have read the google documentation I am still having no luck.

Can you possibly tell me what other requirements I need to take into consideration for this to work?

October 15, 2010 at 1:10 PM 

Matt Quigley said...
@Owen

Is this a build or a runtime error, "com.android.vending.licensing does not exist."?

Also, have you tried just copying the appropriate library files into the default libs folder? If you can get that to work, then the problem is how you're configuring the new library folder. If you can't, then it sounds like there may be additional problems that I could help with.

I use a library in my project at work, and it works fine, at least with the API level 7 and below build setups. But this may be something special with the craziness that the licensing library has to do, and if so, I will look into it further if you give me a little more insight into how you've setup the project. I'll try incorporating the licensing library into the sample project myself. Be sure to tell me everything I need to try to do so, such as where to download it.

October 16, 2010 at 12:16 PM 

Owen said...
Hi Matt,
I have resolved the problem with the LVL library and Proguard using the ANT build method. because Ofuscating is included, I have decided to put the full description in your Optimizing, Obfuscating and Shrinking Post.

October 29, 2010 at 6:40 AM 

Owen said...
The following process was used to Build, Optimize, Obfuscate and Shrink an android app
if using windows and eclipse. I Created a separate project from eclipse to avoid corruption that may be caused by typos or incorrect
project configuration set-up.

1.
Create a project root directory and copy the files from eclipse as follows:

AndroidMainfest.xml
CLASSPATH file
PROJECT file
default.properties
Add your my.keystore to the root directory

2.
Copy the eclipse directories into the project root directory as follows:
assets
bin
gen
res
src

3.
Create a libs directory and copy any library *.jar files to the directory.
If you are using flurry, this may be one of them.

4.
Create a proguard directory.
copy the proguard.jar file to the directory.

create and edit the proguard config.txt file according to documentaion and your project requirements.
If libs is not included in the proguard process at the bottom of build.xml file, then it should be included
in the config.txt file as follows:
-libraryjars path/to/your/libs

The LVL -keep statement must also be included:
-keep class com.android.vending.licensing.ILicensingService
Put config.txt in the proguard directory.

5.
locate the market_licensing\libary directory located in your eclipse project and copy to
your Project path.

The final Project Path setup should consist of:

PROJECTROOT
assets
bin
gen
res
src
libs (*.jars)
library (Android LVL)
proguard


6.
Ensure a path to the android.sdk-windows/tools directory has been set up or cd to the location.
enter android update project --path C:\path\to\your\project
A local.properties and build.xml file will be created in the project rood directory.

7. build.xml
You may need to edit and tailor the build.xml file for your project requirements. I copied
the ant_rules_r3.xml file located in android-sdk-windows\tools\ant into the build file, and set
setup import="false"

8. build.properties file
Any configuration changes are placed in this file.
Include the android LVL library path as follows:
android.library.reference.1=library

To automate your signing process, add the keystore and password statements (depending on your site restrictions)

key.store=your.keystore
key.alias=youralias
key.store.password=yourkeystorepassword
key.alias.password=youraliaspassword


If the above instructions are followed or the project configuration has been set up according to your
own requirements, then navigate to your Project root directory and enter.

ant release

The build should complete successfully.

I put most of the above in a batch script to automate the process. You also don't need to create
a separate project if you feel confident with what is in place from eclipse, but you will have
to include proguard and libs in your eclips project path and you won't have control of buid.xml or build properties
for external sources. It is up to you.

Good luck.

October 29, 2010 at 11:39 AM 

Owen said...
The following process was used to Build, Optimize, Obfuscate and Shrink an android app
if using windows and eclipse. I Created a separate project from eclipse to avoid corruption that may be caused by typos or incorrect
project configuration set-up.

1.
Create a project root directory and copy the files from eclipse as follows:

AndroidMainfest.xml
CLASSPATH file
PROJECT file
default.properties
Add your my.keystore to the root directory

2.
Copy the eclipse directories into the project root directory as follows:
assets
bin
gen
res
src

3.
Create a libs directory and copy any library *.jar files to the directory.
If you are using flurry, this may be one of them.

4.
Create a proguard directory.
copy the proguard.jar file to the directory.

create and edit the proguard config.txt file according to documentaion and your project requirements.
If libs is not included in the proguard process at the bottom of build.xml file, then it should be included
in the config.txt file as follows:
-libraryjars path/to/your/libs

The LVL -keep statement must also be included:
-keep class com.android.vending.licensing.ILicensingService
Put config.txt in the proguard directory.

5.
locate the market_licensing\libary directory located in your eclipse project and copy to
your Project path.

The final Project Path setup should consist of:

PROJECTROOT
assets
bin
gen
res
src
libs (*.jars)
library (Android LVL)
proguard


6.
Ensure a path to the android.sdk-windows/tools directory has been set up or cd to the location.
enter android update project --path C:\path\to\your\project
A local.properties and build.xml file will be created in the project rood directory.

7. build.xml
You may need to edit and tailor the build.xml file for your project requirements. I copied
the ant_rules_r3.xml file located in android-sdk-windows\tools\ant into the build file, and set
setup import="false"

8. build.properties file
Any configuration changes are placed in this file.
Include the android LVL library path as follows:
android.library.reference.1=library

To automate your signing process, add the keystore and password statements (depending on your site restrictions)

key.store=your.keystore
key.alias=youralias
key.store.password=yourkeystorepassword
key.alias.password=youraliaspassword


If the above instructions are followed or the project configuration has been set up according to your
own requirements, then navigate to your Project root directory and enter.

ant release

The build should complete successfully.

I put most of the above in a batch script to automate the process. You also don't need to create
a separate project if you feel confident with what is in place from eclipse, but you will have
to include proguard and libs in your eclips project path and you won't have control of buid.xml or build properties
for external sources. It is up to you.

Good luck.

October 29, 2010 at 11:41 AM 

Premier said...
Can you give me an example for ant build.xml with android library project?
Thanks

December 3, 2010 at 12:32 PM 

cisnky said...
A very useful article. Thanks!!!

February 20, 2011 at 11:11 AM 
Jay Khimani said...
Very nice and useful post. Thanks

March 6, 2011 at 3:02 PM 

Can Elmas said...
Very useful and informative. Thank you.

March 9, 2011 at 7:24 AM 

Anonymous said...
Very helpfull! Thanks!

March 15, 2011 at 8:52 AM 

Alex said...
Make sure to use the following rules file instead of the one in the platform\template folder, otherwise you will get build errors like aaptexec doesn't support the "basename" attribute:

android-sdk\tools\ant\main_rules.xml

April 22, 2011 at 11:13 AM 
Kumar Bibek said...
Thanks a lot.

April 29, 2011 at 12:10 AM 

Kamesh Kompella said...
The article is well written. However, the following must be kept in mind to avoid the baseline and other errors people have reported. I spent an hour getting this to work and finally discovered the problem as detailed here:

http://stackoverflow.com/questions/4464461/compile-error-while-trying-to-compile-android-app-with-ant

May 4, 2011 at 2:31 AM 

L`OcuS said...
You made my day.

Many thanks.

May 17, 2011 at 1:42 PM 

Ajay LD said...
Thanks a lot!

June 15, 2011 at 3:11 AM 

lambt said...
A very useful article. Thanks!

July 14, 2011 at 5:52 AM 

soft llc said...
Thanks for the great post.

Here's a tip for using the android logger when the phone is not connected.

http://www.softllc.com/archives/125

August 8, 2011 at 11:56 AM 

Anonymous said...
Awesome! Very informative.

September 14, 2011 at 1:10 AM 

Piyush Patel said...
Kudos to u, Excellent stuff !!

I was able to setup my build system in less than hour.

Thanks a million ;D

September 23, 2011 at 8:49 AM 

Kang Taro Gak Ngerti seo said...
i dont know why, so many people talking about android, and i dont know too, why steve jobs is very angry about this? can you mention to me?

October 29, 2011 at 2:35 PM 
Basavraj said...
Very helpful for all Android developers

November 17, 2011 at 8:00 AM 

apilyugina said...
Thanks a lot for your article! http://www.enterra-inc.com/techzone/ hope this coulsd be useful, too.

January 12, 2012 at 10:12 PM 

Michael Totschnig said...
Thank you for this interesting article. There is one thing I am wondering about: You show how to set the logging flag from the build, but in order to be truly useful, IMHO you would need to have the build set the logging flag dependent on if you build for debug or release, for example by defining the filter with

What do yo think?

January 29, 2012 at 1:50 AM 

Anonymous said...
Thanks for doing this article. I'm not sure why I found the official docs so intimidating--this is clear and easy!

I did find one change in the Android version I'm running.

Instead of putting the properties in build.properties, they need to be in ant.properties

(The docs say to do that now, at "Build signed and aligned" on
http://developer.android.com/guide/developing/building/building-cmdline.html#ReleaseMode )

Thanks again! This is a great timesaver!!

January 29, 2012 at 11:05 PM 

Miguel said...
Thanks for the post, very insightful!

February 14, 2012 at 4:07 AM 

Anonymous said...
Thanks for this useful post!!

March 25, 2012 at 5:25 PM 
Juhani Lehtimäki said...
Great tutorial. This was very helpful Thank you for posting it!

May 18, 2012 at 8:02 AM 

Yuval Dagan said...
That was agreat help for me

Thanks alot!!

June 26, 2012 at 2:53 AM 

Anonymous said...
Am using hudson,ant to build android apk,for normal android project the build works fine, but i created new android unified ui, where the build fails at setup, saying update android project,
but i did it, still the error is there, any help?

July 12, 2012 at 12:52 PM 

Anonymous said...
Am using hudson,ant to build android apk,for normal android project the build works fine, but i created new android unified ui, where the build fails at setup, saying update android project,
but i did it, still the error is there, any help?

July 12, 2012 at 12:54 PM 

Anonymous said...
Am using hudson,ant to build android apk,for normal android project the build works fine, but i created new android unified ui, where the build fails at setup, saying update android project,
but i did it, still the error is there, any help?

July 12, 2012 at 12:55 PM 
Gary Frederick said...
Great info. I am about to modify ant/Eclipse and this helps a lot.

July 28, 2012 at 9:12 AM 
m0skito said...
Nice tutorial but an engineer using Windows... really? XD

October 30, 2012 at 9:17 AM 

Vinoth P.s said...
could u pls elborate the same with the help pf Hudson, that would be more helpful

October 30, 2012 at 9:49 AM 

Anonymous said...
Hello, I have been trying to execute the sample project given here. But when I build the 'build.xml' file I am getting this error-"taskdef class com.android.ant.SetupTask cannot be found". All the environment variables are set accordingly.I cant figure out the problem.Could you please help me out.

January 24, 2013 at 6:35 AM 

Anonymous said...
buddy you have to setup this particular environment as path "android-home=[YOUR PATH HERE]"
until you specify the system doesn't know where the ant setup is, hope this will resolve this issue

January 24, 2013 at 11:15 PM 

Anonymous said...
also check this link
http://blog.klacansky.com/matter-code/ant-taskdef-class-com-android-ant-setuptask-cannot-be-found

January 24, 2013 at 11:18 PM 

Anonymous said...
How do you set the "config.logging" property to be true or false depending on what target you're building? (debug or release)

February 17, 2013 at 5:31 PM 

Matt Quigley said...
> How do you set the "config.logging" property to be true or false depending on what target you're building? (debug or release)

See the sample project - the ant build script does it for you, depending on whether you are running the debug or release build.

February 18, 2013 at 3:35 AM 

Unknown said...
This comment has been removed by the author.
May 3, 2013 at 5:35 PM 
Guy Nicholas said...
Thanks for the article. I still have a question though.
We have a build machine for automated building/testing and that runs through an ant build script which I have setup to do a variety of things.
We also have Eclipse setup with C/C++ configurations of debug/release (this is a Java & NDK project), but what I need to do is be able to tie the C/C++ config to the Java side such that I can get the Java and C code on the same page so to speak. Have you done this?
Regards, Guy

May 3, 2013 at 5:36 PM 
Post a Comment




Newer Post Older Post Home
Subscribe to: Post Comments (Atom)
Search This Blog

Loading...

Android Engineer

Loading...




Categories

ant (1)
build (1)
Themes (1)
UI (2)

Blog Archive

►  2011 (1)
►  June (1)
▼  2010 (4)
►  August (1)
►  July (1)
▼  June (2)
Using Ant to Automate Building Android Application...
Using Themes in Android Applications

About Me

MATT QUIGLEY
I am a software developer who has been working in the field of mobile software for 10 years now. Currently I'm involved in many exciting new Android projects.
VIEW MY COMPLETE PROFILE


Copyright © 2010 Android Engineer

先备注在这里,后面有时间在翻译和整理下,同学都可以看看,附上链接地址:
http://www.androidengineer.com/2010/06/using-ant-to-automate-building-android.html

可以参考下面链接:
http://www.cnblogs.com/stay/archive/2013/05/27/3102027.html
分享到:
评论

相关推荐

    hibernate_reference.pdf

    - **Building with Ant**: An Ant build script is provided to automate the building and deployment process of the application. - **Startup and Helpers**: This section covers the initialization of ...

    基于模糊故障树的工业控制系统可靠性分析与Python实现

    内容概要:本文探讨了模糊故障树(FFTA)在工业控制系统可靠性分析中的应用,解决了传统故障树方法无法处理不确定数据的问题。文中介绍了模糊数的基本概念和实现方式,如三角模糊数和梯形模糊数,并展示了如何用Python实现模糊与门、或门运算以及系统故障率的计算。此外,还详细讲解了最小割集的查找方法、单元重要度的计算,并通过实例说明了这些方法的实际应用场景。最后,讨论了模糊运算在处理语言变量方面的优势,强调了在可靠性分析中处理模糊性和优化计算效率的重要性。 适合人群:从事工业控制系统设计、维护的技术人员,以及对模糊数学和可靠性分析感兴趣的科研人员。 使用场景及目标:适用于需要评估复杂系统可靠性的场合,特别是在面对不确定数据时,能够提供更准确的风险评估。目标是帮助工程师更好地理解和预测系统故障,从而制定有效的预防措施。 其他说明:文中提供的代码片段和方法可用于初步方案验证和技术探索,但在实际工程项目中还需进一步优化和完善。

    风力发电领域双馈风力发电机(DFIG)Simulink模型的构建与电流电压波形分析

    内容概要:本文详细探讨了双馈风力发电机(DFIG)在Simulink环境下的建模方法及其在不同风速条件下的电流与电压波形特征。首先介绍了DFIG的基本原理,即定子直接接入电网,转子通过双向变流器连接电网的特点。接着阐述了Simulink模型的具体搭建步骤,包括风力机模型、传动系统模型、DFIG本体模型和变流器模型的建立。文中强调了变流器控制算法的重要性,特别是在应对风速变化时,通过实时调整转子侧的电压和电流,确保电流和电压波形的良好特性。此外,文章还讨论了模型中的关键技术和挑战,如转子电流环控制策略、低电压穿越性能、直流母线电压脉动等问题,并提供了具体的解决方案和技术细节。最终,通过对故障工况的仿真测试,验证了所建模型的有效性和优越性。 适用人群:从事风力发电研究的技术人员、高校相关专业师生、对电力电子控制系统感兴趣的工程技术人员。 使用场景及目标:适用于希望深入了解DFIG工作原理、掌握Simulink建模技能的研究人员;旨在帮助读者理解DFIG在不同风速条件下的动态响应机制,为优化风力发电系统的控制策略提供理论依据和技术支持。 其他说明:文章不仅提供了详细的理论解释,还附有大量Matlab/Simulink代码片段,便于读者进行实践操作。同时,针对一些常见问题给出了实用的调试技巧,有助于提高仿真的准确性和可靠性。

    基于西门子S7-200 PLC和组态王的八层电梯控制系统设计与实现

    内容概要:本文详细介绍了基于西门子S7-200 PLC和组态王软件构建的八层电梯控制系统。首先阐述了系统的硬件配置,包括PLC的IO分配策略,如输入输出信号的具体分配及其重要性。接着深入探讨了梯形图编程逻辑,涵盖外呼信号处理、轿厢运动控制以及楼层判断等关键环节。随后讲解了组态王的画面设计,包括动画效果的实现方法,如楼层按钮绑定、轿厢移动动画和门开合效果等。最后分享了一些调试经验和注意事项,如模拟困人场景、防抖逻辑、接线艺术等。 适合人群:从事自动化控制领域的工程师和技术人员,尤其是对PLC编程和组态软件有一定基础的人群。 使用场景及目标:适用于需要设计和实施小型电梯控制系统的工程项目。主要目标是帮助读者掌握PLC编程技巧、组态画面设计方法以及系统联调经验,从而提高项目的成功率。 其他说明:文中提供了详细的代码片段和调试技巧,有助于读者更好地理解和应用相关知识点。此外,还强调了安全性和可靠性方面的考量,如急停按钮的正确接入和硬件互锁设计等。

    CarSim与Simulink联合仿真:基于MPC模型预测控制实现智能超车换道

    内容概要:本文介绍了如何将CarSim的动力学模型与Simulink的智能算法相结合,利用模型预测控制(MPC)实现车辆的智能超车换道。主要内容包括MPC控制器的设计、路径规划算法、联合仿真的配置要点以及实际应用效果。文中提供了详细的代码片段和技术细节,如权重矩阵设置、路径跟踪目标函数、安全超车条件判断等。此外,还强调了仿真过程中需要注意的关键参数配置,如仿真步长、插值设置等,以确保系统的稳定性和准确性。 适合人群:从事自动驾驶研究的技术人员、汽车工程领域的研究人员、对联合仿真感兴趣的开发者。 使用场景及目标:适用于需要进行自动驾驶车辆行为模拟的研究机构和企业,旨在提高超车换道的安全性和效率,为自动驾驶技术研发提供理论支持和技术验证。 其他说明:随包提供的案例文件已调好所有参数,可以直接导入并运行,帮助用户快速上手。文中提到的具体参数和配置方法对于初学者非常友好,能够显著降低入门门槛。

    基于单片机的鱼缸监测设计(51+1602+AD0809+18B20+UART+JKx2)#0107

    包括:源程序工程文件、Proteus仿真工程文件、论文材料、配套技术手册等 1、采用51单片机作为主控; 2、采用AD0809(仿真0808)检测"PH、氨、亚硝酸盐、硝酸盐"模拟传感; 3、采用DS18B20检测温度; 4、采用1602液晶显示检测值; 5、检测值同时串口上传,调试助手监看; 6、亦可通过串口指令对加热器、制氧机进行控制;

    风电领域双馈永磁风电机组并网仿真及短路故障分析与MPPT控制

    内容概要:本文详细介绍了双馈永磁风电机组并网仿真模型及其短路故障分析方法。首先构建了一个9MW风电场模型,由6台1.5MW双馈风机构成,通过升压变压器连接到120kV电网。文中探讨了风速模块的设计,包括渐变风、阵风和随疾风的组合形式,并提供了相应的Python和MATLAB代码示例。接着讨论了双闭环控制策略,即功率外环和电流内环的具体实现细节,以及MPPT控制用于最大化风能捕获的方法。此外,还涉及了短路故障模块的建模,包括三相电压电流特性和离散模型与phasor模型的应用。最后,强调了永磁同步机并网模型的特点和注意事项。 适合人群:从事风电领域研究的技术人员、高校相关专业师生、对风电并网仿真感兴趣的工程技术人员。 使用场景及目标:适用于风电场并网仿真研究,帮助研究人员理解和优化风电机组在不同风速条件下的性能表现,特别是在短路故障情况下的应对措施。目标是提高风电系统的稳定性和可靠性。 其他说明:文中提供的代码片段和具体参数设置有助于读者快速上手并进行实验验证。同时提醒了一些常见的错误和需要注意的地方,如离散化步长的选择、初始位置对齐等。

    空手道训练测试系统BLE106版本

    适用于空手道训练和测试场景

    【音乐创作领域AI提示词】AI音乐提示词(deepseek,豆包,kimi,chatGPT,扣子空间,manus,AI训练师)

    内容概要:本文介绍了金牌音乐作词大师的角色设定、背景经历、偏好特点、创作目标、技能优势以及工作流程。金牌音乐作词大师凭借深厚的音乐文化底蕴和丰富的创作经验,能够为不同风格的音乐创作歌词,擅长将传统文化元素与现代流行文化相结合,创作出既富有情感又触动人心的歌词。在创作过程中,会严格遵守社会主义核心价值观,尊重用户需求,提供专业修改建议,确保歌词内容健康向上。; 适合人群:有歌词创作需求的音乐爱好者、歌手或音乐制作人。; 使用场景及目标:①为特定主题或情感创作歌词,如爱情、励志等;②融合传统与现代文化元素创作独特风格的歌词;③对已有歌词进行润色和优化。; 阅读建议:阅读时可以重点关注作词大师的创作偏好、技能优势以及工作流程,有助于更好地理解如何创作出高质量的歌词。同时,在提出创作需求时,尽量详细描述自己的情感背景和期望,以便获得更贴合心意的作品。

    linux之用户管理教程.md

    linux之用户管理教程.md

    基于单片机的搬运机器人设计(51+1602+L298+BZ+KEY6)#0096

    包括:源程序工程文件、Proteus仿真工程文件、配套技术手册等 1、采用51/52单片机作为主控芯片; 2、采用1602液晶显示设置及状态; 3、采用L298驱动两个电机,模拟机械臂动力、移动底盘动力; 3、首先按键配置-待搬运物块的高度和宽度(为0不能开始搬运); 4、按下启动键开始搬运,搬运流程如下: 机械臂先把物块抓取到机器车上, 机械臂减速 机器车带着物块前往目的地 机器车减速 机械臂把物块放下来 机械臂减速 机器车回到物块堆积处(此时机器车是空车) 机器车减速 蜂鸣器提醒 按下复位键,结束本次搬运

    基于下垂控制的三相逆变器电压电流双闭环仿真及MATLAB/Simulink/PLECS实现

    内容概要:本文详细介绍了基于下垂控制的三相逆变器电压电流双闭环控制的仿真方法及其在MATLAB/Simulink和PLECS中的具体实现。首先解释了下垂控制的基本原理,即有功调频和无功调压,并给出了相应的数学表达式。随后讨论了电压环和电流环的设计与参数整定,强调了两者带宽的差异以及PI控制器的参数选择。文中还提到了一些常见的调试技巧,如锁相环的响应速度、LC滤波器的谐振点处理、死区时间设置等。此外,作者分享了一些实用的经验,如避免过度滤波、合理设置采样周期和下垂系数等。最后,通过突加负载测试展示了系统的动态响应性能。 适合人群:从事电力电子、微电网研究的技术人员,尤其是有一定MATLAB/Simulink和PLECS使用经验的研发人员。 使用场景及目标:适用于希望深入了解三相逆变器下垂控制机制的研究人员和技术人员,旨在帮助他们掌握电压电流双闭环控制的具体实现方法,提高仿真的准确性和效率。 其他说明:本文不仅提供了详细的理论讲解,还结合了大量的实战经验和调试技巧,有助于读者更好地理解和应用相关技术。

    光伏并网逆变器全栈开发资料:硬件设计、控制算法及实战经验

    内容概要:本文详细介绍了光伏并网逆变器的全栈开发资料,涵盖了从硬件设计到控制算法的各个方面。首先,文章深入探讨了功率接口板的设计,包括IGBT缓冲电路、PCB布局以及EMI滤波器的具体参数和设计思路。接着,重点讲解了主控DSP板的核心控制算法,如MPPT算法的实现及其注意事项。此外,还详细描述了驱动扩展板的门极驱动电路设计,特别是光耦隔离和驱动电阻的选择。同时,文章提供了并联仿真的具体实现方法,展示了环流抑制策略的效果。最后,分享了许多宝贵的实战经验和调试技巧,如主变压器绕制、PWM输出滤波、电流探头使用等。 适合人群:从事电力电子、光伏系统设计的研发工程师和技术爱好者。 使用场景及目标:①帮助工程师理解和掌握光伏并网逆变器的硬件设计和控制算法;②提供详细的实战经验和调试技巧,提升产品的可靠性和性能;③适用于希望深入了解光伏并网逆变器全栈开发的技术人员。 其他说明:文中不仅提供了具体的电路设计和代码实现,还分享了许多宝贵的实际操作经验和常见问题的解决方案,有助于提高开发效率和产品质量。

    机器人轨迹规划中粒子群优化与3-5-3多项式结合的时间最优路径规划

    内容概要:本文详细介绍了粒子群优化(PSO)算法与3-5-3多项式相结合的方法,在机器人轨迹规划中的应用。首先解释了粒子群算法的基本原理及其在优化轨迹参数方面的作用,随后阐述了3-5-3多项式的数学模型,特别是如何利用不同阶次的多项式确保轨迹的平滑过渡并满足边界条件。文中还提供了具体的Python代码实现,展示了如何通过粒子群算法优化时间分配,使3-5-3多项式生成的轨迹达到时间最优。此外,作者分享了一些实践经验,如加入惩罚项以避免超速,以及使用随机扰动帮助粒子跳出局部最优。 适合人群:对机器人运动规划感兴趣的科研人员、工程师和技术爱好者,尤其是有一定编程基础并对优化算法有初步了解的人士。 使用场景及目标:适用于需要精确控制机器人运动的应用场合,如工业自动化生产线、无人机导航等。主要目标是在保证轨迹平滑的前提下,尽可能缩短运动时间,提高工作效率。 其他说明:文中不仅给出了理论讲解,还有详细的代码示例和调试技巧,便于读者理解和实践。同时强调了实际应用中需要注意的问题,如系统的建模精度和安全性考量。

    【KUKA 机器人资料】:kuka机器人压铸欧洲标准.pdf

    KUKA机器人相关资料

    光子晶体中BIC与OAM激发的模拟及三维Q值计算

    内容概要:本文详细探讨了光子晶体中的束缚态在连续谱中(BIC)及其与轨道角动量(OAM)激发的关系。首先介绍了光子晶体的基本概念和BIC的独特性质,随后展示了如何通过Python代码模拟二维光子晶体中的BIC,并解释了BIC在光学器件中的潜在应用。接着讨论了OAM激发与BIC之间的联系,特别是BIC如何增强OAM激发效率。文中还提供了使用有限差分时域(FDTD)方法计算OAM的具体步骤,并介绍了计算本征态和三维Q值的方法。此外,作者分享了一些实验中的有趣发现,如特定条件下BIC表现出OAM特征,以及不同参数设置对Q值的影响。 适合人群:对光子晶体、BIC和OAM感兴趣的科研人员和技术爱好者,尤其是从事微纳光子学研究的专业人士。 使用场景及目标:适用于希望通过代码模拟深入了解光子晶体中BIC和OAM激发机制的研究人员。目标是掌握BIC和OAM的基础理论,学会使用Python和其他工具进行模拟,并理解这些现象在实际应用中的潜力。 其他说明:文章不仅提供了详细的代码示例,还分享了许多实验心得和技巧,帮助读者避免常见错误,提高模拟精度。同时,强调了物理离散化方式对数值计算结果的重要影响。

    C#联合Halcon 17.12构建工业视觉项目的配置与应用

    内容概要:本文详细介绍了如何使用C#和Halcon 17.12构建一个功能全面的工业视觉项目。主要内容涵盖项目配置、Halcon脚本的选择与修改、相机调试、模板匹配、生产履历管理、历史图像保存以及与三菱FX5U PLC的以太网通讯。文中不仅提供了具体的代码示例,还讨论了实际项目中常见的挑战及其解决方案,如环境配置、相机控制、模板匹配参数调整、PLC通讯细节、生产数据管理和图像存储策略等。 适合人群:从事工业视觉领域的开发者和技术人员,尤其是那些希望深入了解C#与Halcon结合使用的专业人士。 使用场景及目标:适用于需要开发复杂视觉检测系统的工业应用场景,旨在提高检测精度、自动化程度和数据管理效率。具体目标包括但不限于:实现高效的视觉处理流程、确保相机与PLC的无缝协作、优化模板匹配算法、有效管理生产和检测数据。 其他说明:文中强调了框架整合的重要性,并提供了一些实用的技术提示,如避免不同版本之间的兼容性问题、处理实时图像流的最佳实践、确保线程安全的操作等。此外,还提到了一些常见错误及其规避方法,帮助开发者少走弯路。

    基于Matlab的9节点配电网中分布式电源接入对节点电压影响的研究

    内容概要:本文探讨了分布式电源(DG)接入对9节点配电网节点电压的影响。首先介绍了9节点配电网模型的搭建方法,包括定义节点和线路参数。然后,通过在特定节点接入分布式电源,利用Matlab进行潮流计算,模拟DG对接入点及其周围节点电压的影响。最后,通过绘制电压波形图,直观展示了不同DG容量和接入位置对配电网电压分布的具体影响。此外,还讨论了电压越限问题以及不同线路参数对电压波动的影响。 适合人群:电力系统研究人员、电气工程学生、从事智能电网和分布式能源研究的专业人士。 使用场景及目标:适用于研究分布式电源接入对配电网电压稳定性的影响,帮助优化分布式电源的规划和配置,确保电网安全稳定运行。 其他说明:文中提供的Matlab代码和图表有助于理解和验证理论分析,同时也为后续深入研究提供了有价值的参考资料。

    电力市场领域中基于CVaR风险评估的省间交易商最优购电模型研究与实现

    内容概要:本文探讨了在两级电力市场环境中,针对省间交易商的最优购电模型的研究。文中提出了一个双层非线性优化模型,用于处理省内电力市场和省间电力交易的出清问题。该模型采用CVaR(条件风险价值)方法来评估和管理由新能源和负荷不确定性带来的风险。通过KKT条件和对偶理论,将复杂的双层非线性问题转化为更易求解的线性单层问题。此外,还通过实际案例验证了模型的有效性,展示了不同风险偏好设置对购电策略的影响。 适合人群:从事电力系统规划、运营以及风险管理的专业人士,尤其是对电力市场机制感兴趣的学者和技术专家。 使用场景及目标:适用于希望深入了解电力市场运作机制及其风险控制手段的研究人员和技术开发者。主要目标是为省间交易商提供一种科学有效的购电策略,以降低风险并提高经济效益。 其他说明:文章不仅介绍了理论模型的构建过程,还包括具体的数学公式推导和Python代码示例,便于读者理解和实践。同时强调了模型在实际应用中存在的挑战,如数据精度等问题,并指出了未来改进的方向。

    西门子1200 PLC轴运动控制程序模板及其实战应用详解

    内容概要:本文详细介绍了一套成熟的西门子1200 PLC轴运动控制程序模板,涵盖多轴伺服控制、电缸控制、PLC通讯、气缸报警块、完整电路图、威纶通触摸屏程序和IO表等方面的内容。该模板已在多个项目中成功应用,如海康威视的路由器外壳装配机,确保了系统的稳定性和可靠性。文中不仅提供了具体的代码示例,还分享了许多实战经验和技巧,如参数设置、异常处理机制、通讯优化等。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些需要进行PLC编程和轴运动控制的从业者。 使用场景及目标:适用于需要快速搭建稳定可靠的PLC控制系统的企业和个人开发者。通过学习和应用该模板,可以提高开发效率,减少调试时间和错误发生率,从而更好地满足项目需求。 其他说明:文章强调了程序模板的实用性,特别是在异常处理和参数配置方面的独特设计,能够有效应对复杂的工业环境挑战。此外,还提到了一些常见的陷阱和解决方案,帮助读者避开常见错误,顺利实施项目。

Global site tag (gtag.js) - Google Analytics