In Hudson, use ant to automatically compile and package the Android project APK

Source: Internet
Author: User

This article explains how to configure the ant compilation Package apk in Hudson, including the Build.xml file authoring, the configuration of the environment, and the creation of tasks in Hudson.

I. Create a build.xml file for the Android project

1. Open cmd into the tools directory under the SDK directory, enter: Android.bat list target to query our existing version of the list. Such as:



On the way with the red box of the ID and the blue box circled the version number corresponding to the relationship, the following need to use.


2. Open the Project.Properties file under Android project to view the target version number, such as:



3. Use the command Android update project-n webviewsession-t 19-p e:\lenovocw\▲ technology solution \ Android WebView Session delivery \webviewsession Generate the Build.xml file under Engineering, as shown in:

-N corresponds to the project name
-T is the version of the SDK we previously queried the corresponding ID, people according to their own project version to make a choice, I this is Android 4.4.2 so with ID 19
-P is the generated path


At this point, Build.xml and local.properties 2 files are automatically generated in the project

Viewing the Build.xml file can be found, the Build.xml file reads Local.properties and ant.properties 2 configuration files, and finally references the Build.xml file under the SDK.

If we need to customize our target, we need to use some configuration parameters, we put it in Local.properties, the generated local.properties file has been automatically specified in our SDK directory.


4, configure the signing certificate information, let ant automatically package for us and use our configured certificate to sign

Under Project Engineering, add the Ant.properties file and configure our certificate information as shown in:



At this point, we can do ant packaging for Android projects.

If our project references an external jar package, the "crunch" error that occurs when building a project using Ant build is as follows:

-code-gen:[mergemanifest] Found Deleted Target file[mergemanifest] merging androidmanifest files into one. [Mergemanifest] Manifest merger disabled. Using project manifest only.     [Echo] Handling aidl Files ...     [Aidl] No aidl files to compile.     [Echo]----------     [echo] handling Renderscript files ...     [Echo]----------     [echo] Handling Resources     ... [AAPT] Generating Resource IDs ...     [AAPT] Invalid resource directory Name:f:\workspace\zlib\bin\res/crunch  BUILD failedd:\android\sdk\tools\ant\ Build.xml:601:the following error occurred while executing this line:d:\android\sdk\tools\ant\build.xml:653:the Following error occurred while executing this line:d:\android\sdk\tools\ant\build.xml:698:null returned:1

The following compilation errors occur, the workaround is as follows:

Method 1: Assign a value in the system Tool/ant/build.xml file <property name= "aapt.ignore.assets" value= "Crunch"/>

Method 2: Add <property name= "Aapt.ignore.assets" value= "in your project build file!. Svn:!. git:\x3cdir\x3e_*:.*:! Cvs:!thumbs.db:!picasa.ini:!*.scc:*~:crunch "/>

I do not want to modify the Build.xml file inside the SDK, so the Build.xml file I generated in the project is configured using Method 2.


Below is the code for my project under Build.xml, where the red part is what I need to add for myself.

<?xml version= "1.0" encoding= "UTF-8"? ><project name= "Webviewsession" default= "deploy" ><!--the         Local.properties file is created and updated by the ' Android ' tool. It contains the path to the SDK. It should *not* is checked into Version Control Systems. --><property file= "Local.properties"/> <condition property=" Sdk.dir "value=" ${window.sdk.dir} "else=" ${linux.sdk.dir} " ><os family= "Windows"/></condition> <condition property= "deploy.dir.apk" value= "${ WINDOW.DEPLOY.DIR.APK} "else=" ${linux.deploy.dir.apk} "><os family=" Windows "/></CONDITION> <!--the ant.properties file can created by.         It is only edited by the ' Android ' tool to add properties to it.         The "the" to "change some Ant specific build properties. Here is some properties want to change/update:source.dir the name of the source directory.         Default is ' src '. Out.dir the name of the output directory.         Default is ' bin '.         For other overridable properties, look at the beginning of the rules files in the SDK, at Tools/ant/build.xml Properties related to the SDK location or the project target should is updated using the ' Android ' tool with T         He ' update ' action. This file is a integral part of the build system for your application and should are checked into Version Control         Systems. --><property file= "Ant.properties"/><!--if Sdk.dir is not set from one of the property file and then G Et it from the android_home envVar. This must is done before we load project.properties since the Proguard config can use Sdk.dir--><property E Nvironment= "env"/><condition property= "Sdk.dir" value= "${env". Android_home} "><isset property=" env. Android_home "/></condition><!--resolve the "crunch" error--><property name= "Aapt.ignore.assets" When you build your project in ant build Value= "!. Svn:!. git:\x3cdir\x3e_*:.*:! Cvs:!thumbs.db:!picasa.ini:!*.scc:*~:crunch "/> <!--the project.properties file is created and updated by the ' Android ' tool, as well as ADT. This contains project specific properties such as project target, and library dependencies.         Lower level build properties is stored in ant.properties (or in. classpath for Eclipse projects). This file is a integral part of the build system for your application and should are checked into Version Control Systems. --><loadproperties srcfile= "Project.Properties"/><!--quick check on Sdk.dir--><fail message= " Sdk.dir is missing.  Make sure to generate Local.properties using ' Android Update Project ' or to inject it through the android_home environment Variable. "unless=" Sdk.dir "/><!--Import per project custom build rules if present at the root of the Proje        Ct. This was the place to put custom intermediary targets such as:-pre-build-pre-compile-po St-compile (This is typically Used for code obfuscation. Compiled code location: ${out.classes.absolute.dir} If The is not do in place, override ${out . Dex.input.absolute.dir})-post-package-post-build-pre-clean--><import file= "         Custom_rules.xml "optional=" true "/><!--Import the actual build file. To customize existing targets, there is, options:-Customize only one target:-Copy/paste the TA             Rget into this file, *before* the <import> task.         -Customize it to your needs.               -Customize the whole content of build.xml-copy/paste the content of the rules files (minus the top node)             Into this file, replacing the <import> task.         -Customize to your needs. IMPORTANT ****** *********************** In all cases must UPDA Te the value of VersioN-tag below to read ' custom ' instead of a integer, in order to avoid have your file be overridden by tools such As "Android Update Project"--><!--version-tag:1--><import file= "${sdk.dir}/tools/ant/build.xml"/><!--output apk file--><target name= "deploy" ><antcall target= "release"/><!--replication must also involve the issue of overwriting with the same name, Ant is explained in the Copy Class API: Files is just copied if the source file is newer than the destination file, where newer refers to the modified time of the file, even when you modify the contents of the file There is no change, but the modification time changes, Ant also overwrites the file with the same name, that is, Ant does not check the file contents. --><copy file= "${out.absolute.dir}/${ant.project.name}-release.apk" tofile= "${deploy.dir.apk}/${ ant.project.name}.apk "/></target><!--compile and install a signed apk--><target name=" installsignedapk "depends=" Deploy "><antcall target=" Installr "/></target></project>


Second, configure the ANDROID-SDK environment on the server (I use the Linux system, window is the development environment is no longer a separate description, the use is the same)

Download the Linux version of ANDROID-SDK, upload it to the server, and the directory structure after unpacking the package is as follows:

Android-sdk-linux

-Tools

-Android

-Ant

-Apps

-DDMS

-Draw9patch

-Emulator

-Emulator64-arm

-Emulator64-mips

-Emulator64-x86

-Emulator-arm

-Emulator-mips

-Emulator-x86

-Hierarchyviewer

-Jobb

-Lib

-Lint

-Mksdcard

-Monitor

-Monkeyrunner

-NOTICE.txt

-Proguard

-Screenshot2

-Source.properties

-Support

-Templates

-TraceView

-Uiautomatorviewer

-Platform-tools

-ADB

-API

-Dmtracedump

-Etc1tool

-FastBoot

-Hprof-conv

-NOTICE.txt

-Source.properties

-Sqlite3

-Systrace

-Platforms

-Android-19

-Build-tools

-20.0.0


III. create a task in Hudson (as for how to install Hudson, do not repeat here)

1, create a new task in Hudson, enter ProjectName, generally we tick "use custom Workspace" using their own workspace directory, such as:



2, configure the SVN information, Hudson will be based on our configured SVN information to help us update the code from SVN, as shown in:



3, we can check the build perodically Schedule as required, this is to Hudson automatically help us to perform this task within a specified time, as shown in:

The configuration of the expression can be clicked on the following question mark to see a simple description, the input can be more than a line of content.



4. Configure Ant

Select the ant that you have installed, specify the targets that you want to perform in Build.xml, specify the Build.xml file (. Start with a relative path, or you can use an absolute path, and then you can enter the variables we need in the Build.xml file in the properties, written in key=value format, and write a key-value pair per line.



5. Click the Save button at the bottom to save the task.


--------------------------------------------

Note:

If you use ant compilation to package the APK on Linux, the following error occurs:
/usr/local/android-sdk-linux/tools/ant/build.xml:698:execute failed:java.io.IOException:Cannot Run Program "/usr/ Local/android-sdk-linux/build-tools/22.0.0/aapt ": error=2, No such file or directory

Solutions See: http://blog.csdn.net/catoop/article/details/47157631











Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

In Hudson, use ant to automatically compile and package the Android project APK

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.