How to create apk file on command line?

I used eclipse ide to build the apk file. Now I want to create an apk file on the command line in linux. But when I say ant debug, it gives the 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 the version for Android 17. I have a build.xml file.

Edit: I changed my version of ant to 1.8.0, but whatever I did, I was unable to create a task or enter checkenv.

+6
source share
4 answers

Make sure you have a file called local.properties in the root directory (i.e. the same directory as your build.xml ).

Make sure this file contains the following line:

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

(Of course, you need to adapt the path to your effective sdk location)

Double check the correct path.

Re-run ant debug

Note: the local.properties file is local (and, as a rule, not supported by the version!)

+1
source

Use this example. You need to pass sdk.dir to ant, i.e. ant -Dsdk.dir=<path to Android SDK>

You also need to specify one of the seven target build goals for Android, because the default build goal is "help."

If you just run ant -Dsdk.dir=<path to Android SDK> , you will get some help, for example:

 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 .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. 

CREATE SUCCESSFULL Total Time: 7 seconds To create an APK, you must specify a debug or release.

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

This will help you create an apk file.

0
source

I do as

1) Project sdk / tools / android update -t ​​3 -p

2) ant clean release

3) jarsigner -keystore -storepass -keypass

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

0
source

Source: https://habr.com/ru/post/953669/


All Articles