Configure your ant script and automatically pack the signed Android apk_android with Eclipse

Source: Internet
Author: User
Tags pack

Eclipse Although the use of less, but in some ancient projects will also use drops, the most troublesome thing is to play with a signature package problem, not too convenient, the following through this article for everyone to record the configuration ant, Automatic packaging with signature apk process, as a backup. (PC environment is MAC)

1, the first step to Ann ant, download the corresponding installation package, after decompression configuration environment variables:

Export ant_home= "/users/yanzi/work/apache-ant-1.9.4"
export Path=${path}:${ant_home}/bin

Check to see if the installation was successful through which Ant.

2, run under the project directory: Android update project-p./If there is a dependency package, run the command under each dependency pack directory. After running this command, there will be two more files: Build.xml and Local.properties

Local.properties File Contents:

Sdk.dir=/users/yanzi/work/android-tool/android-sdk-macosx

Build.xml File Contents:

<?xml version= "1.0" encoding= "UTF-8"?> <project name= "Tongcheng" default= "Help" > <!--the Local.propert 
IES file is created and updated by the ' Android ' tool. It contains the path to the SDK. It should *not* be checked to Version control Systems. --> <property file= "local.properties"/> <!--the ant.properties file can be created by you. 
It is only edited by the ' Android ' tool to add properties to it. 
This is the "place" to "change" some Ant specific build properties. Here are some properties your may 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 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 the ' Update ' action. This is a integral part of the builds system for your appliCation and should be checked to Version control Systems. --> <property file= "ant.properties"/> <!--if Sdk.dir is not set from one to the property file, then get 
It from the Android_home env var. This must is done before we load project.properties since the Proguard config can use Sdk.dir--> the <property Enviro nment= "env"/> <condition property= sdk.dir "value=" ${env. Android_home} "> <isset property=" env. Android_home "/> </condition> <!--The project.properties file is created and updated by the ' Android ' tool 
, as as and as ADT. This contains project specific properties such as project target, and library dependencies. 
Lower level builds properties are stored in ant.properties (or in. classpath for Eclipse projects). This is a integral part of the builds system for your application and should are checked to 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 builds rules if present at the root of the project. This is the "place" to "put" custom intermediary targets such as:-pre-build-pre-compile-post-compile (this is typically 
Used for code obfuscation.  
Compiled code location: ${out.classes.absolute.dir} If This isn't done 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 are two options:-Customize only one target:-copy/paste "target into" fil 
E, *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) in this file, replacing the <import> task. 
-Customize to your needs. IMPORTANT *********************** In all cases your must update the value of Versi On-tag below to read ' custom ' instead of an integer, in order to avoid has your file is overridden by tools such as "a Ndroid Update Project "--> <!--version-tag:1--> <import file=" ${sdk.dir}/tools/ant/build.xml "  ;/project>

None of these two files are moved, and the name of project above is written with the names you want. Then the project root directory creates a new ant.properties, which reads as follows:

# This file is used to override default values used by the Ant build system. 
# This 
file must being checked in Version control Systems, as it's # integral to the ' build 
system of your project. # This file is a used by the 
Ant script. 
# to override default values such as 
# ' Source.dir ' for the location of your Java source folder and
   # ' Out.dir ' for the location of your output folder. 
# can also use it define how the release builds are signed by declaring 
# The following properties: 
# ' Key.st Ore ' for the location of your keystore and 
# ' Key.alias ' for the ' name 
of ' # The password would be asked during the "build" at the ' release ' Target. 
Key.alias=com.tongcheng 
Key.store=tongcheng.keystore 
key.store.password=12377778 

Configure information on KeyStore.

It's OK to execute ant clean first and then execute ANT release!

3, of course, for the better, you'll need the following script:

Vim release.sh, the contents are as follows:

echo-----------------start---------
start=$ (date +%s)
ant clean
ant release
adb Uninstall Com.android.tongcheng
adb install bin/tongcheng-release.apk
end=$ (date +%s)
echo "----over, time-consuming $[${end}- ${start}] seconds---"

Then each time you want to install the signed package, direct./release.sh!

The above is a small set for you to introduce the eclipse under the configuration ant script and automatically pack with signed Android APK content, I hope to help!

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.