Skip to content

Instantly share code, notes, and snippets.

@Ehsanul-Hoque
Last active April 9, 2020 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ehsanul-Hoque/90959e07c29acbb255877967e7556b00 to your computer and use it in GitHub Desktop.
Save Ehsanul-Hoque/90959e07c29acbb255877967e7556b00 to your computer and use it in GitHub Desktop.
Python code for generating release apk automatically (Part 5)
# Function for generating signed apk
def generateSignedApk():
print('\nGENERATING apk...')
process = Popen('./gradlew assembleRelease', shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
output, errors = process.communicate()
# Zero returncode means process success
if not process.returncode:
print('Signed apk generated!')
return True
else:
print('Signed apk generation output = ' + output)
print('Signed apk generation error = ' + errors)
print('Signed apk generation process return code = ' + str(process.returncode))
print('Signed apk generation failed!')
return False
# Function for renaming apk
def renameSignedApk(item_dict):
print('\nRENAMING apk...')
try:
os.remove(constants.RELEASE_APK_FOLDER + item_dict[constants.JSON_KEY_APP_NAME] + '.apk')
except:
# Eat exception
print('', end='')
os.rename(constants.RELEASE_APK_FOLDER + constants.RELEASE_APK_FILE_NAME,
constants.RELEASE_APK_FOLDER + item_dict[constants.JSON_KEY_APP_NAME] + '.apk')
print('Renaming successful')
# Function for installing signed apk to the physical device (Optional)
def installSignedApk(app_name_with_extension):
print('\nDo you want to install the release apk to any connected device? (y/n)')
install = input()
if (install is 'y') or (install is 'Y'):
process = Popen('adb install "' + constants.RELEASE_APK_FOLDER + app_name_with_extension + '"', shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True)
output, errors = process.communicate()
# Zero returncode means process success
if not process.returncode:
print('App installed.')
return True
else:
print('App installation output = ' + output)
print('App installation error = ' + errors)
print('App installation process return code = ' + str(process.returncode))
print('App installation failed!')
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment