Last active
April 10, 2020 19:10
-
-
Save Ehsanul-Hoque/017817abb11bff2e4536dc33f1aaabdb to your computer and use it in GitHub Desktop.
Python code for generating release apk automatically (Part 6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
# ... | |
# Main function | |
def main(): | |
global company_item | |
global input_company_id | |
global input_key_filename | |
global input_store_pass | |
global input_key_alias | |
global input_key_pass | |
global keystore_exists | |
if len(sys.argv) is 3: | |
keystore_exists = True | |
# Take input from command line arguments | |
(input_company_id, input_key_filename) = (int(sys.argv[1]), sys.argv[2]) | |
input_key_alias = "" | |
input_store_pass = "" | |
elif len(sys.argv) is 5: | |
keystore_exists = False | |
# Take input from command line arguments | |
(input_company_id, input_key_filename, input_key_alias, input_store_pass) = (int(sys.argv[1]), sys.argv[2], sys.argv[3], sys.argv[4]) | |
else: | |
print('Parameter list length error: syntax:') | |
print('\tpython3 makeApp.py <company_id> <keystore_filename> <key_alias> <keystore_password>') | |
print('\tpython3 makeApp.py <company_id> <existing_keystore_filename>') | |
return | |
input_key_pass = input_store_pass | |
# Read companies from json | |
input_file = open(constants.COMPANY_INFO_FILE) | |
company_array = json.load(input_file) | |
# Iterate over company list | |
for item in company_array: | |
item_id = item[constants.JSON_KEY_ID] | |
if item_id == input_company_id: | |
company_item = item | |
break | |
if company_item is None: | |
print('No company found with id ' + str(input_company_id)) | |
else: | |
print('Found a company! App name will be "' + company_item[constants.JSON_KEY_APP_NAME] + '"') | |
startProcessing(company_item) | |
# Function for start cooking | |
def startProcessing(item_dict): | |
global company_name | |
global input_key_filename | |
global input_store_pass | |
global input_key_alias | |
# Overwrite properties of app | |
overwriteGradleProperties(item_dict) | |
# Create keystore | |
result = createKeystore(item_dict) | |
if not result: | |
return | |
# Create/modify a file to save the keystore info | |
saveKeystoreInfo() | |
# Download icon in the drawable/whatever folder | |
result = downloadIcon(item_dict) | |
if not result: | |
return | |
# Generate the apk | |
result = generateSignedApk() | |
if not result: | |
return | |
# Rename the apk | |
renameSignedApk(item_dict) | |
# Install the apk | |
installSignedApk(item_dict[constants.JSON_KEY_APP_NAME] + '.apk') | |
# LET'S BEGIN | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment