gpt4 book ai didi

android - 如何使用命令行生成apk文件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:25:50 26 4
gpt4 key购买 nike

请告诉我如何在不使用 ECLIPSE ide 的情况下构建项目的 apk 文件。我找到了一些关于使用批处理文件的信息,但我不知道如何重新制作它。

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%

我从网站上获得了这些代码。 (http://www.apriorit.com/our-company/dev-blog/233-how-to-build-apk-file-from-command-line)

我下载了源代码示例并打开了其中的批处理文件,但它没有生成它的 apk 文件。通常 apk 文件位于其 bin\中,对吗?但是当我打开文件夹时,文件不在那里。请帮助我如何使用这个。非常感谢你的帮助。

最佳答案

您必须为此安装 Apache ant:

ant debug

这将构建并签署必要的 .apk 文件。

更多信息,请查看:http://codeseekah.com/2012/02/09/command-line-android-development-basics/

编辑:

ant 不是标准 Android SDK 设置的一部分。您必须安装它。

Apache Ant Project 下载最新的 ant zip 文件.

Extract the zip file to a folder, say c:\ant\ 

Add c:\ant to your path environment variable

完成这些后,您就可以从命令行运行 ant

关于android - 如何使用命令行生成apk文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com