linux下用脚本命令编译android应用

来源:互联网 发布:php erp管理系统 编辑:程序博客网 时间:2024/06/14 00:06


1.前期所准备的环境和软件。

jdk1.7.0_79

android-sdk-linux

apache-ant-1.8.2

......................................

tar -vxzf apahce-ant-1.8.2-bin.tar.gz
chmod 755 -R apache-ant-1.8.2

2.环境配置

vi /etc/profile    修改系统配置文件

export JAVA_HOME=/usr/jvm/jdk1.7.0_79
export SDK_HOME=/usr/local/android-sdk-linux/
export ANT_HOME=/home/kf/apache-ant-1.8.2
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$SDK_HOME/tools:$SDK_HOME/build-tools/android-4.4W:$SDK_HOME/platform-tools:$PATH:$ANT_HOME/bin

source /etc/proifle   立刻将配置生效

ant -version   测试ant是否生效

3.建立项目

列出目标平台ID

user abc # $SDK_HOME/tools/android list targetsAvailable Android targets:----------id: 1 or "android-20"     Name: Android 4.4W     Type: Platform     API level: 20     Revision: 1     Skins: WSVGA, WXGA720, WXGA800-7in, WQVGA432, WQVGA400, HVGA, WVGA800 (default), WVGA854, WXGA800, QVGA Tag/ABIs : no ABIs.

建立新的android工程(效果同使用eclipse新建android工程一致)

$ANDROID_SDK_DIR/tools/android create project –k包名 –a项目名 –t目标平台ID –p 路径

user abc # $SDK_HOME/tools/android create project -k com.sy.qm -a dq -t 1 -p /home/yanfa1/abc/

user abc # lltotal 52drwxr-xr-x  6 root   root   4096 12月 14 15:55 ./drwxrwxrwx 26 yanfa1 yanfa1 4096 12月 14 15:31 ../-rw-r--r--  1 root   root    627 12月 14 15:36 AndroidManifest.xml-rw-r--r--  1 root   root    698 12月 14 15:36 ant.properties-rw-r--r--  1 root   root    105 12月 14 15:46 .ant-targets-build.xml-rw-r--r--  1 root   root   3914 12月 14 15:44 build.xmldrwxr-xr-x  3 root   root   4096 12月 14 15:46 gen/drwxr-xr-x  2 root   root   4096 12月 14 15:36 libs/-rw-r--r--  1 root   root    422 12月 14 15:44 local.properties-rw-r--r--  1 root   root    781 12月 14 15:44 proguard-project.txt-rw-r--r--  1 root   root    563 12月 14 15:44 project.propertiesdrwxr-xr-x  8 root   root   4096 12月 14 15:36 res/drwxr-xr-x  3 root   root   4096 12月 14 15:36 src/

建立ant编译脚本build.xml

$ANDROID_SDK_DIR/tools/android update project --name项目名 –t目标平台ID –p路径

user abc # $SDK_HOME/tools/android update project --name dq -t 1 -p /home/yanfa1/abc/

编译工程:

a)生成debug版本
$ ant debug
生成带debug未签名的apk

-package:[apkbuilder] Current build type is different than previous build: forced apkbuilder run.[apkbuilder] Creating dq-debug-unaligned.apk and signing it with a debug key...-post-package:-do-debug: [zipalign] Running zip align on final apk...     [echo] Debug Package: /home/user/abc/bin/dq-debug.apk[propertyfile] Creating new property file: /home/user/abc/bin/build.prop[propertyfile] Updating property file: /home/user/abc/bin/build.prop[propertyfile] Updating property file: /home/user/abc/bin/build.prop[propertyfile] Updating property file: /home/user/abc/bin/build.prop-post-build:debug:BUILD SUCCESSFULTotal time: 3 seconds

user bin # lltotal 168drwxr-xr-x 5 root root  4096 12月 14 15:59 ./drwxr-xr-x 7 root root  4096 12月 14 15:59 ../-rw-r--r-- 1 root root   627 12月 14 15:59 AndroidManifest.xml-rw-r--r-- 1 root root    84 12月 14 15:59 AndroidManifest.xml.d-rw-r--r-- 1 root root   179 12月 14 15:59 build.propdrwxr-xr-x 3 root root  4096 12月 14 15:59 classes/-rw-r--r-- 1 root root  1996 12月 14 15:59 classes.dex-rw-r--r-- 1 root root   419 12月 14 15:59 classes.dex.ddrwxr-xr-x 2 root root  4096 12月 14 15:59 dexedLibs/-rw-r--r-- 1 root root 34140 12月 14 15:59 dq.ap_-rw-r--r-- 1 root root   599 12月 14 15:59 dq.ap_.d-rw-r--r-- 1 root root 37481 12月 14 15:59 dq-debug.apk-rw-r--r-- 1 root root 37472 12月 14 15:59 dq-debug-unaligned.apk-rw-r--r-- 1 root root   113 12月 14 15:59 dq-debug-unaligned.apk.d-rw-r--r-- 1 root root    83 12月 14 15:59 proguard.txtdrwxr-xr-x 6 root root  4096 12月 14 15:59 res/


b)生成release版本
$ ant release

生成带release未签名的apk

-release-prompt-for-password:-release-nosign:     [echo] No key.store and key.alias properties found in build.properties.     [echo] Please sign /home/user/abc/bin/dq-release-unsigned.apk manually     [echo] and run zipalign from the Android SDK tools.[propertyfile] Creating new property file: /home/user/abc/bin/build.prop[propertyfile] Updating property file: /home/user/abc/bin/build.prop[propertyfile] Updating property file: /home/user/abc/bin/build.prop[propertyfile] Updating property file: /home/user/abc/bin/build.prop-release-sign:-post-build:release:BUILD SUCCESSFULTotal time: 3 seconds

userbin # lltotal 124drwxr-xr-x 5 root root  4096 12月 14 16:04 ./drwxr-xr-x 7 root root  4096 12月 14 16:04 ../-rw-r--r-- 1 root root   627 12月 14 16:04 AndroidManifest.xml-rw-r--r-- 1 root root    84 12月 14 16:04 AndroidManifest.xml.d-rw-r--r-- 1 root root   183 12月 14 16:04 build.propdrwxr-xr-x 3 root root  4096 12月 14 16:04 classes/-rw-r--r-- 1 root root  1992 12月 14 16:04 classes.dex-rw-r--r-- 1 root root   419 12月 14 16:04 classes.dex.ddrwxr-xr-x 2 root root  4096 12月 14 16:04 dexedLibs/-rw-r--r-- 1 root root 34117 12月 14 16:04 dq.ap_-rw-r--r-- 1 root root   599 12月 14 16:04 dq.ap_.d-rw-r--r-- 1 root root 35254 12月 14 16:04 dq-release-unsigned.apk-rw-r--r-- 1 root root   114 12月 14 16:04 dq-release-unsigned.apk.d-rw-r--r-- 1 root root    83 12月 14 16:04 proguard.txtdrwxr-xr-x 6 root root  4096 12月 14 16:04 res/

备注:

eclipse:

-rw-rw-r--  1 yanfa1 yanfa1 2633 12月 13 10:52 AndroidManifest.xmldrwxrwxr-x  2 yanfa1 yanfa1 4096 12月 14 15:07 assets/drwxrwxr-x  3 yanfa1 yanfa1 4096 12月 14 15:07 gen/drwxrwxr-x  2 yanfa1 yanfa1 4096 12月 14 15:07 lib/drwxrwxr-x  8 yanfa1 yanfa1 4096 12月 14 15:07 libs/-rw-rw-r--  1 yanfa1 yanfa1  781 12月  4 14:07 proguard-project.txt-rw-rw-r--  1 yanfa1 yanfa1  563 12月  6 10:06 project.propertiesdrwxrwxr-x 14 yanfa1 yanfa1 4096 12月 14 15:07 res/drwxrwxr-x  3 yanfa1 yanfa1 4096 12月 14 15:07 src/

执行

$SDK_HOME/tools/android update project --name Project -t 1 -p /home/user/Project/

user Project #  $SDK_HOME/tools/android update project --name Project -t 1 -p /home/yanfa1/Project/Updated project.propertiesUpdated local.propertiesAdded file /home/yanfa1/Project/build.xmlUpdated file /home/yanfa1/Project/proguard-project.txt

ant release

OK.

第三方包,库放到libs下

如果引用了一些包放到lib下,只需编译不需打包进入,如何办呢?需新加

<property name="jar.lib.dir" value="lib" /><property name="jar.lib.absolute.dir" location="${jar.lib.dir}" /><property name="jar.libs.dir" value="libs" /><property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />

 <javac encoding="${java.encoding}"                    source="${java.source}" target="${java.target}"                    debug="true" extdirs="" includeantruntime="false"                    destdir="${out.classes.absolute.dir}"                    bootclasspathref="project.target.class.path"                    verbose="${verbose}"                    classpathref="project.javac.classpath"                    fork="${need.javac.fork}">                <src path="${source.absolute.dir}" />                <src path="${gen.absolute.dir}" />                <classpath>                    <fileset dir="${jar.lib.dir}" includes="*.jar" />                </classpath>                <compilerarg line="${java.compilerargs}" />            </javac>




build.sh

ant clean

ant release









原创粉丝点击