通过ant脚本,编译打包android工程
Eclipse中使用Android Tools进行签名,ant和命令行使用jdk的jarsigner对未签名的包进行apk签名。
通过命令打包的脚本:见附件bulid0.xml,这个ant脚本只能编译打包一个单独的android工程或依赖一个library 的android工程
Initializing all output directories...
Generating R.java from the resources...
Compiling .aidl into java files...
Compiling java source code...
Converting compiled files and external libraries into a .dex
file...
Packaging resources and assets...
Packaging unsigned apk for release...
It will need to be signed with jarsigner before being published.
Packaging signed apk for release...
APK is released. path:${out-signed-package-ospath}
Android官方提供的打包脚本: 1400多行,我加了中文注释,希望能看懂。
详见build.xml
@{elseText}
@{elseText}
Running tests ...
Uninstalling @{app.package} from the default emulator or device...
Gathering info for ${ant.project.name}...
Building Libraries
############################################
**** Back to project ${ant.project.name} ****
############################################
Building tested project at ${tested.project.absolute.dir}
############################################
**** Back to project ${ant.project.name} ****
############################################
Switching from instrumented to non-instrumented build.
Deleting previous compilation output:
Creating output directories if needed...
----------
Handling aidl files...
----------
Handling RenderScript files...
----------
Handling Resources...
Creating library output jar file...
Custom jar packaging exclusion: ${android.package.excludes}
Instrumenting classes from ${out.absolute.dir}/classes...
@${proguard.config}
-injars ${project.jars}
-outjars "${obfuscated.jar.file}"
-libraryjars ${android.libraryjars}
-dump "${obfuscate.absolute.dir}/dump.txt"
-printseeds "${obfuscate.absolute.dir}/seeds.txt"
-printusage "${obfuscate.absolute.dir}/usage.txt"
-printmapping "${obfuscate.absolute.dir}/mapping.txt"
Debug Package: ${out.final.file}
No key.store and key.alias properties found in build.properties.
Please sign ${out.packaged.file} manually
and run zipalign from the Android SDK tools.
*************************************************
**** Android Manifest has debuggable=true ****
**** Doing DEBUG packaging with RELEASE keys ****
*************************************************
Signing final apk...
Release Package: ${out.final.file}
Instrumented Package: ${out.final.file}
WARNING: Code Coverage is currently only supported on the emulator and rooted devices.
Downloading coverage file into project directory...
Extracting coverage report...
Cleaning up temporary files...
Saving the report file in ${basedir}/coverage/coverage.html
Installing ${out.final.file} onto default emulator or device...
Install file not specified.
'ant install' now requires the build target to be specified as well.
ant debug install
ant release install
ant instrument install
This will build the given package and install it.
Alternatively, you can use
ant installd
ant installr
ant installi
ant installt
to only install an existing package (this will not rebuild the package.)
Could not find application package in manifest. Cannot run 'adb uninstall'.
Could not find tested application package in manifest. Cannot run 'adb uninstall'.
Android Ant Build. Available targets:
help: Displays this help.
clean: Removes output files created by other targets.
The 'all' target can be used to clean dependencies
(tested projects and libraries)at the same time
using: 'ant all clean'
debug: Builds the application and signs it with a debug key.
release: Builds the application. The generated apk file must be
signed before it is published.
instrument:Builds an instrumented package and signs it with a
debug key.
test: Runs the tests. Project must be a test project and
must have been built. Typical usage would be:
ant [emma] debug installt test
emma: Transiently enables code coverage for subsequent
targets.
install: Installs the newly build package. Must either be used
in conjunction with a build target (debug/release/
instrument) or with the proper suffix indicating
which package to install (see below).
If the application was previously installed, the
application is reinstalled if the signature matches.
installd: Installs (only) the debug package.
installr: Installs (only) the release package.
installi: Installs (only) the instrumented package.
installt: Installs (only) the test and tested packages.
uninstall: Uninstalls the application from a running emulator or
device.