How to generate apk file using command line?

please tell me how to create apk files for a project without using ECLIPSE ide. I found some information about using a batch file, but I do not know how to redo it.

echo on SET PREV_PATH=%CD% cd /d %0\.. REM Clear bin folder rmdir "bin" /S /Q rmdir "gen" /S /Q mkdir "bin" || goto EXIT mkdir "gen" || goto EXIT REM Set your application name SET APP_NAME=SecureSms REM Define minimal Android revision SET ANDROID_REV=android-8 REM Define aapt add command SET ANDROID_AAPT_ADD="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" add REM Define aapt pack and generate resources command SET ANDROID_AAPT_PACK="%ANDROID-SDK%\platforms\%ANDROID_REV%\tools\aapt.exe" package -v -f -I "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar" REM Define class file generator command SET ANDROID_DX="%ANDROID-SDK%\platform-tools\dx.bat" --dex REM Define Java compiler command SET JAVAC="%JAVABIN%\javac.exe" -classpath "%ANDROID-SDK%\platforms\%ANDROID_REV%\android.jar" SET JAVAC_BUILD=%JAVAC% -sourcepath "src;gen" -d "bin" REM Generate R class and pack resources and assets into resources.ap_ file call %ANDROID_AAPT_PACK% -M "AndroidManifest.xml" -A "assets" -S "res" -m -J "gen" -F "bin\resources.ap_" || goto EXIT REM Compile sources. All *.class files will be put into the bin folder call %JAVAC_BUILD% src\org\secure\sms\*.java || goto EXIT REM Generate dex files with compiled Java classes call %ANDROID_DX% --output="%CD%\bin\classes.dex" %CD%\bin || goto EXIT REM Recources file need to be copied. This is needed for signing. copy "%CD%\bin\resources.ap_" "%CD%\bin\%APP_NAME%.ap_" || goto EXIT REM Add generated classes.dex file into application package call %ANDROID_AAPT_ADD% "%CD%\bin\%APP_NAME%.ap_" "%CD%\bin\classes.dex" || goto EXIT REM Create signed Android application from *.ap_ file. Output and Input files must be different. call "%JAVABIN%\jarsigner" -keystore "%CD%\keystore\my-release-key.keystore" -storepass "password" -keypass "password" -signedjar "%CD%\bin\%APP_NAME%.apk" "%CD%\bin\%APP_NAME%.ap_" "alias_name" || goto EXIT REM Delete temp file del "bin\%APP_NAME%.ap_" :EXIT cd "%PREV_PATH%" ENDLOCAL exit /b %ERRORLEVEL% 

I got these codes from the site. (Http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line)

I downloaded a sample source code and opened a batch file there, but it did not generate its apk file. usually the apk file is in its bin \ right? but when I opened the folder, the file is not there. please help me how to use this. I would appreciate help.

+7
source share
4 answers

By default, apk is in bin, and that’s correct, but when you distribute the source code, it’s best not to add any apk, because a β€œfresh” compiled apk is always the best solution.

if you have a file called build.xml in the root of your project, just do

 ant debug 

otherwise, you need to update your project with the minimum information needed for the construction phase using

 android update project -t android-10 -p . 

in this case, android-10 is the target of your apk / app / api, and you can configure this setting for your target device.

After that, you will get your build.xml and everything will be created to create apk.

+4
source

You must have Apache ant for this:

 ant debug 

This will create and sign the required .apk files.

For more information see this: http://codeseekah.com/2012/02/09/command-line-android-development-basics/

EDIT:

ant is not part of the standard Android SDK setup. You will need to install it.

Download the latest ant zip file from the Apache ant Project .

 Extract the zip file to a folder, say c:\ant\ Add c:\ant to your path environment variable 

Once they are done, you can run ant from the command line

+5
source
 ant debug install 

really viable if you create a project (note that during installation, if you use multiple devices, you must specify a virtual device with the command "adb -s")

 android create project -n <project_name> -t <target_version> -p <path> -k <package> -a <activity> 

and use this command to run on avd (if you ran it)

 adb -e shell "am start -a android.intent.action.MAIN -n com.your.package/.YourActivity" 

(change -e to -d if you are working on devices)

link

it is better to use "AVD Manager.exe" to start the virtual device if you do not know this command or parameters, since there are a lot of them.

0
source

One of the best examples I've found on the Internet to create an Android APK is https://geosoft.no/development/android.html. You can also use the assemblyDebug command in the root directory (make sure gradle is selected as the environment variable) if you are using Gradle.

0
source

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


All Articles