轻松编译,签名,zipalign APK for Android Play Store(也是SHA1密钥查看器)

时间:2014-01-23 13:56:49

标签: android batch-file apk release sha1

如何轻松地将您的APK包编译并部署到Google Play商店?我一直在寻找我能找到的最简单的设置方式,最后在下面进行以下操作?你会建议一个更好的方法吗?

“您可以使用GUI在Android Studio中签名和压缩对齐APK文件,而不是使用终端吗?”

两个批处理文件,以协助您的部署过程

我创建的以下批处理文件是为了加快我在各种设备上测试我的APK文件,因为我还开发了一些Android到Arudino通信的人。所以我可能需要在单一更改代码/语法后准备好APK。无论如何......他们做了什么?

编译,签名,ZipAlign(Android Studio版本)

  • 使用Gradle(包含在Android Studio中)将项目编译为发布版本
  • 将发布APK从项目文件夹复制到您自己的
  • 的相关文件夹
  • 使用jarsigner使用您的KeyStore文件对APK文件进行签名
  • 使用ZipAlign为Google Play商店创建适用于APK的新副本。
  • 删除ZipAlign留下的原始文件

complile_release.bat

@echo off
REM Modify the variables between the lines to match your installation and project
REM ----------------------------------------------------
set sKeyAlias=MyProjectNameAlias
set sStorePass=MyPassword
set sPathKeyStore=C:\Projects\Android\Key_Stores.keystore
set sFileTmp=igetdeleted.apk
set sFileOutput=MyProjectName.apk
set sPathOrigAPK=C:\Projects\MyProjectFolder\MyProjectName\build\apk\MyProjectName-release-unsigned.apk
set sPathOutput=C:\Projects\Releases
set sPathJavaBin=C:\Program Files\Java\jdk1.7.0_10\bin
set sPathAnTools=C:\Program Files\Android\android-studio\sdk\tools
set sPathGradle=C:\Projects\MyProjectFolder\
set sDriveGradle=%sPathGradle:~0,2% 
REM ----------------------------------------------------


REM -- Navigate to gradlew.bat folder and execute with "aR" for a release version
%sDriveGradle%
cd %sPathGradle%
call "gradlew.bat" aR

REM -- Copy the compiled APK to our output/release folder
copy "%sPathOrigAPK%" "%sPathOutput%\%sFileTmp%" /Y >nul

REM -- Sign the APK package
"%sPathJavaBin%\jarsigner.exe" -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore "%sPathKeyStore%" -storepass "%sStorePass%" "%sPathOutput%\%sFileTmp%" %sKeyAlias%

REM -- Zipalign the APK package (This creates a copy)
"%sPathAnTools%\zipalign.exe" -f -v 4 "%sPathOutput%\%sFileTmp%" "%sPathOutput%\%sFileOutput%"

REM -- Delete the original from the zipalign output the APK package
del "%sPathOutput%\%sFileTmp%"

REM -- Awaiting user input before closing the window
pause

查看APK SHA1值

以下批处理文件只需让您可以根据需要查看SHA1密钥或其他详细信息

view_sha1.bat

@echo off

REM Modify the variables between the lines to match your installation and project
REM ----------------------------------------------------
set sKeyAlias=MyProjectNameAlias
set sStorePass=MyPassword
set sPathJavaBin=C:\Program Files\Java\jdk1.7.0_10\bin
set sPathKeyStore=C:\Projects\Android\Key_Stores.keystore
REM ----------------------------------------------------

REM -- This will use the Java keytool to display the some information about the APK including the SHA1 key as required for google
"%sPathJavaBin%\keytool" -list -v -keystore "%sPathKeyStore%" -storepass "%sStorePass%" -alias "%sKeyAlias%"

REM -- Awaiting user input before closing the window
pause

我希望这两个可以为人们提供帮助/使用

0 个答案:

没有答案