【问题标题】:How to create apk file in command line?如何在命令行中创建apk文件?
【发布时间】:2013-09-16 07:11:04
【问题描述】:

我正在使用 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

我有 ant 版本 1.9.2 。和安卓版本 17。 我有 build.xml 文件。

编辑:我将我的 ant 版本更改为 1.8.0,但无论我做什么,我仍然得到那些未能创建任务或键入 checkenv 错误。

【问题讨论】:

  • ant 1.8.0 版正在与我合作
  • 你能检查一下 anttasks.jar 是否可用并且可以访问吗?如果没有,您可以下载它。
  • 如何下载anttasks.jar文件?
  • anttasks.jar 是 Android SDK 的一部分,它应该位于路径 $SDK/tools/lib/anttasks.jar。看来您的文件可能已损坏。此命令是否有效:jar tf $SDK/tools/lib/anttasks.jar(其中$SDK 是您的 Android SDK 的路径)
  • 当给出命令 jar tf $SDK/tools/lib/anttasks.jar 时,它告诉 java.util.zip.ZipException:error in opening zip file at java.util.zip.ZipException.open (本机方法)

标签: java android eclipse ant command-line


【解决方案1】:

【讨论】:

  • 我知道这已经有几年的历史了,但请注意,只有链接的答案是strongly discouraged
【解决方案2】:

确保您在根目录(即与您的build.xml 相同的目录)中有一个名为local.properties 的文件。

确保该文件包含如下一行:

sdk.dir=c:\\tools\\android-sdk

(当然你需要将路径适配到你的有效sdk位置)

仔细检查路径是否正确。

重新运行ant debug

注意:文件 local.properties 是本地文件(通常不受版本控制!)

【讨论】:

  • 我有 local.properties 和 sdk.dir 路径是正确的。我已经检查过了..这不是问题
  • 你能检查你的sdk安装没有损坏吗?特别要检查 android-sdk/tools/lib/ant-tasks.jar 是否存在并且是可执行的。
  • 我有 anttasks.jar 文件。但是你能告诉我如何检查它是否可执行吗??
  • ls -l in android-sdk/tools/lib/ :它将为您提供有关所有者/组等的信息... ant 进程的所有者(即您)必须有权读取它(不确定可执行文件是必需,但在我的安装 -windows- 上它是可执行的)
  • @ben75 我也有同样的问题。我已经检查了local.properties,。 sdk.dir=E:\\JEGADEES\\Android\\adt-bundle-windows-x86_64-20131030,。但仍然存在同样的问题。任何想法?但我在 E:\JEGADEES\Android\adt-bundle-windows-x86_64-20131030\sdk\tools\ant 路径中找不到 ant-tasks.jar。
【解决方案3】:

使用这个例子 您需要将sdk.dir 传递给ant,即ant -Dsdk.dir=&lt;path to Android SDK&gt;

您还需要指定七个左右的 Android 构建目标之一,因为默认构建目标是“帮助”。

如果你只是运行ant -Dsdk.dir=&lt;path to Android SDK&gt;,你会得到一些帮助输出,像这样:

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.

构建成功 总时间:7秒 要构建 APK,您必须指定调试或发布。

ant -Dsdk.dir=<path to Android SDK> debug

这将帮助您创建一个 apk 文件

【讨论】:

  • 如果我写 ant -Dsdk.dir= debug 那么我也会遇到同样的错误
  • @SSS 为什么构建失败?
  • 这就是我要问的。为什么创建任务或类型 checkenv 失败并失败??
【解决方案4】:

我正在做的事情

1) sdk/tools/android 更新项目-t 3 -p

2) 蚂蚁清洁释放

3) jarsigner -keystore -storepass -keypass

4) sdk/tools/zipalign -v 4 /bin/.apk

【讨论】:

  • 但对我来说它说:无法打开 zip 文件 anttasks.jar
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多