用于生成未签名的APK
。
apkbuidler
是个shell
脚本,它的的实现如下:
#!/bin/sh
# Copyright 2005-2007, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Set up prog to be the path of this script, including following symlinks,
# and set up progdir to be the fully-qualified pathname of its directory.
prog="$0"
while [ -h "${prog}" ]; do
newProg=`/bin/ls -ld "${prog}"`
newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
if expr "x${newProg}" : 'x/' >/dev/null; then
prog="${newProg}"
else
progdir=`dirname "${prog}"`
prog="${progdir}/${newProg}"
fi
done
oldwd=`pwd`
progdir=`dirname "${prog}"`
cd "${progdir}"
progdir=`pwd`
prog="${progdir}"/`basename "${prog}"`
cd "${oldwd}"
jarfile=sdklib.jar
frameworkdir="$progdir"
if [ ! -r "$frameworkdir/$jarfile" ]
then
frameworkdir=`dirname "$progdir"`/tools/lib
fi
if [ ! -r "$frameworkdir/$jarfile" ]
then
frameworkdir=`dirname "$progdir"`/framework
fi
if [ ! -r "$frameworkdir/$jarfile" ]
then
echo `basename "$prog"`": can't find $jarfile"
exit 1
fi
# Check args.
if [ debug = "$1" ]; then
# add this in for debugging
java_debug=-agentlib:jdwp=transport=dt_socket,server=y,address=8050,suspend=y
shift 1
else
java_debug=
fi
if [ "$OSTYPE" = "cygwin" ] ; then
jarpath=`cygpath -w "$frameworkdir/$jarfile"`
else
jarpath="$frameworkdir/$jarfile"
fi
# might need more memory, e.g. -Xmx128M
exec java -Xmx128M $java_debug -classpath "$jarpath" com.android.sdklib.build.ApkBuilderMain "$@"
需要注意的是:这个脚本从sdk r17
开始不再提供了。 但是从apkbuilder
的实现我们知道,apkbuilder
最终调用的是sdklib.jar
中的com.android.sdklib.build.ApkBuilderMain
类来做事情的,所以,我们可以将这个脚本复制一份,放到原来的位置, 或者直接使用java
命令执行这个类:
查看shell
脚本的帮助,如下:
使用Jar包的执行效果与shell脚本是一样的。
用法:
apkbuilder <apkfile> [option]
参数说明:
参数 | 是否可选 | 说明 |
---|---|---|
outArchive | 必选 | 表示要输出的apk路径。例如:~/HelloWorld/bin/my.apk |
-v | 可选 | 输出日志 |
-d | 可选 | 生成的文件中包含debug信息。 |
-u | 可选 | 表示创建一个未签名的apk |
-storetype | 可选 | 忽略storetype校验失败 |
-z | 可选 | 指定编译好的资源包。例如:~/HelloWorld/bin/resources.ap_ |
-f | 可选 | 指定dex文件的路径。例如:~/HelloWorld/bin/classes.dex |
--rf | 可选 | 指定源文件的路径。例如:~/HelloWorld/src |
--rj | 可选 | 指定引用的库的路径。例如:~/HelloWorld/libs |
示例:
apkbuilder Prism.apk -v -u -z bin/ressources.ap_ -f bin/classes.dex -rj libs