Easy way to compile, sign, zipalign APK for Android Play Store (Also SHA1 Key Viewer)

最后都变了- 提交于 2020-01-23 13:58:08

问题


How do you easily compile and deploy your APK packages to the Google Play Store? i have been searching around for the easiest way i could find for my setup and ended up doing the following below? Would you suggest a better way for this?

"Can you sign and zip align your APK file from within Android Studio using a GUI, not by using the terminal?"

Two Batch Files to assist with your deployment process

The following batch file i created to speed up the testing of my APK files across various devices as i also develop a few person Android to Arudino communications.. So i may need a APK ready after a single change of code/syntax. Anyway... What do they do?

Compile, Sign, ZipAlign (Android Studio Version)

  • Uses Gradle (Included with Android Studio) to compile your project as a release version
  • Copies the release APK from the project folder to a relese folder of your own
  • Uses jarsigner to sign the APK file with your KeyStore file
  • Uses ZipAlign to create a new copy of the APK ready for google Play Store.
  • Deletes the original file that ZipAlign leaves behind

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

Viewing APK SHA1 Value

The following batch file with simply let you view the SHA1 key or other details as you need

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

I hope these two can be of some help / use to people

来源:https://stackoverflow.com/questions/21310215/easy-way-to-compile-sign-zipalign-apk-for-android-play-store-also-sha1-key-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!