如何使用命令行来生成apk文件? [英] how to generate apk file using a command line?

查看:317
本文介绍了如何使用命令行来生成apk文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何建立一个项目的apk文件,而无需使用的Eclipse IDE中。我发现关于使用批处理文件的相关信息的一些,但我不知道该如何改造它。

please tell me how to build apk files of a project without the use of ECLIPSE ide. i found some infos about using a batch file but i don't know how to remake 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%

我接到了一个网站上的这个codeS。 (http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line)

i got this codes from a site. (http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line)

我下载的源$ C ​​$ C样品,并在那里开了批处理文件,但它并没有产生它的apk文件。一般apk文件位于其斌\\吧?但是当我打开的文件夹,该文件是不是在那里。请帮助我如何使用这一个。我会AP preciate您有所帮助。

i downloaded the source code sample and opened the batch file in there but it didn't generate it's apk file. usually the apk file is located at its bin\ right? but when i opened the folder, the file is not in there. please help me how to use this one. i'd appreciate you help.

推荐答案

默认情况下,APK位于下仓,这是正确的,但是当你分发源$ C ​​$ C,最好不要添加任何的apk,因为一个鲜编译APK始终是一个更好的解决方案。

The apk by default is located under bin and this is correct, but when you distribute source code it's better to not add any apk because a "fresh" compiled apk is always a better solution.

如果您有一个名为的build.xml 在项目的根文件只是做

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 informations required for the building phase with

android update project -t android-10 -p .

在这种情况下,的android-10 是您的APK /应用/ API的目标,你可以自定义该选项为您的目标设备。

in this case android-10 is a target for your apk/app/api and you can customize this option for your targeted device.

在这之后你会得到你的的build.xml 键,一切就绪用于生成APK。

After this you get your build.xml and everything is in place for generating an apk.

这篇关于如何使用命令行来生成apk文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆