Java 如何在命令行中创建apk文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18755109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create apk file in command line?
提问by SSS
I was using eclipse ide to build apk file . Now i want to create apk file in command line in linux. But when i say ant debug it gives following error :
我正在使用 eclipse ide 来构建 apk 文件。现在我想在 linux 的命令行中创建 apk 文件。但是当我说 ant debug 时,它给出了以下错误:
Unable to obtain resource from anttasks.jar
java.util.zip.ZipException : error in opening zip file
Problem : failed to create task or type checkenv
Cause : The name is undefined
Action : Check the spelling
Action : Check that any custom tasks/types have been declared
Action : Check that any <presetdef>/<macrodef> declarations have taken place
I have ant version 1.9.2 . and android version 17. I have build.xml file .
我有蚂蚁版本 1.9.2 。和 android 版本 17。我有 build.xml 文件。
Edit : I changed my ant version into 1.8.0 , But whatever i do still i am getting those failed to create task or type checkenv error .
编辑:我将我的 ant 版本更改为 1.8.0,但无论我做什么,我仍然遇到那些无法创建任务或键入 checkenv 错误的问题。
回答by Ethel Beauchamp
Use this example
You need to pass sdk.dir
into ant, i.e. ant -Dsdk.dir=<path to Android SDK>
使用这个例子你需要传入sdk.dir
ant,即ant -Dsdk.dir=<path to Android SDK>
You'll also need to specify one of the seven or so Android build targets because the default build target is 'help'.
您还需要指定七个左右的 Android 构建目标之一,因为默认构建目标是“帮助”。
If you just run ant -Dsdk.dir=<path to Android SDK>
, you'll get some help output, like so:
如果你只是运行ant -Dsdk.dir=<path to Android SDK>
,你会得到一些帮助输出,像这样:
help:
[echo] Android Ant Build. Available targets:
[echo] help: Displays this help.
[echo] clean: Removes output files created by other targets.
[echo] compile: Compiles project's .java files into .class files.
[echo] debug: Builds the application and signs it with a debug key.
[echo] release: Builds the application. The generated apk file must be
[echo] signed before it is published.
[echo] install: Installs/reinstalls the debug package onto a running
[echo] emulator or device.
[echo] If the application was previously installed, the
[echo] signatures must match.
[echo] uninstall: Uninstalls the application from a running emulator or
[echo] device.
BUILD SUCCESSFUL Total time: 7 seconds To build the APK, you have to specify debug or release.
BUILD SUCCESSFUL 总时间:7 秒 要构建 APK,您必须指定 debug 或 release。
ant -Dsdk.dir=<path to Android SDK> debug
This will help you creating an apk file
这将帮助您创建一个 apk 文件
回答by Biraj Zalavadia
I am doing like
我正在做
1) sdk/tools/android update project -t 3 -p
1) sdk/tools/android 更新项目 -t 3 -p
2) ant clean release
2)蚂蚁清理发布
3) jarsigner -keystore -storepass -keypass
3) jarsigner -keystore -storepass -keypass
4) sdk/tools/zipalign -v 4 /bin/.apk
4) sdk/tools/zipalign -v 4 /bin/.apk
回答by Nikhil Virupakshi
Check this following developer link
检查以下开发人员链接
http://developer.android.com/tools/building/building-cmdline.html
http://developer.android.com/tools/building/building-cmdline.html
回答by ben75
Be sure that you have a file named local.properties
in the root directory (i.e. same directory as your build.xml
).
确保您local.properties
在根目录(即与您的 相同的目录build.xml
)中有一个文件。
Be sure that this file contains a line like this:
确保该文件包含如下一行:
sdk.dir=c:\tools\android-sdk
(Of course you need to adapt the path to your effective sdk location)
(当然你需要调整路径到你的有效sdk位置)
Double-check that the path is correct.
仔细检查路径是否正确。
Re-run ant debug
重新运行 ant debug
Note : the file local.properties is local (and is usually not under version control !)
注意:文件 local.properties 是本地的(通常不受版本控制!)