How to create apk file in command line?

2019-03-28 01:39发布

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 :

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 .

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 .

4条回答
劫难
2楼-- · 2019-03-28 02:16

I am doing like

1) sdk/tools/android update project -t 3 -p

2) ant clean release

3) jarsigner -keystore -storepass -keypass

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

查看更多
神经病院院长
4楼-- · 2019-03-28 02:29

Be sure that you have a file named local.properties in the root directory (i.e. same directory as your 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)

Double-check that the path is correct.

Re-run ant debug

Note : the file local.properties is local (and is usually not under version control !)

查看更多
贪生不怕死
5楼-- · 2019-03-28 02:31

Use this example You need to pass sdk.dir into ant, i.e. 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'.

If you just run ant -Dsdk.dir=<path to Android SDK>, you'll get some help output, like so:

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.

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

This will help you creating an apk file

查看更多
登录 后发表回答