Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apk_rebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def message_create_resources(first):
def message_building(first, second):
return f'Building {first} from {second}...'

@staticmethod
def message_workaround_apktool_2756():
return f'Applying Apktool issue #2756 workaround...'

@staticmethod
def message_zipalign(first, second):
return f'Zipalign {first} to {second}...'
Expand Down Expand Up @@ -196,6 +200,8 @@ def rebuild_apk(self, input_filename, output_filename):
self.__change_manifest(manifest_filename)
Logger.success(ProgressMessages.message_create_resources(network_security_xml))
self.__create_network_security_xml(network_security_xml, Rebuilder.Constants.NETWORK_SECURITY_XML)
Logger.warning(ProgressMessages.message_workaround_apktool_2756())
self.__workaround_apktool_2756(unpacked_folder, manifest_filename)
Logger.success(ProgressMessages.message_building(output_filename, unpacked_folder))
self.__build_apk(output_filename, unpacked_folder)
Logger.success(ProgressMessages.message_zipalign(output_filename, aligned_filename))
Expand Down Expand Up @@ -224,6 +230,40 @@ def __unpack_apk(self, input_filename, folder):
shell = self.__utils.is_os_windows()
subprocess.call(["apktool", "d", input_filename, "-f", "-o", folder], shell=shell)

def __workaround_apktool_2756(self, folder, manifest_filename):
shell = self.__utils.is_os_windows()

if shell:
locales_config_path = f'{folder}\\res\\xml\\locales_config.xml'
else:
locales_config_path = f'{folder}/res/xml/locales_config.xml'

if os.path.exists( locales_config_path ):
os.remove( locales_config_path )

if shell:
public_path = f'{folder}\\res\\values\\public.xml'
else:
public_path = f'{folder}/res/values/public.xml'

xmldoc = minidom.parse( public_path )

public_items = xmldoc.getElementsByTagName("public")

for item in public_items:
if item.getAttribute('name') == 'locales_config':
item.parentNode.removeChild(item)

self.__utils.write_to_file( public_path , xmldoc.toxml() )

xmldoc = minidom.parse(manifest_filename)
application_item = xmldoc.getElementsByTagName("application")

if application_item[0].hasAttribute('android:localeConfig'):
application_item[0].removeAttribute('android:localeConfig')

self.__utils.write_to_file( manifest_filename, xmldoc.toxml() )

def __build_apk(self, output_filename, folder):
shell = self.__utils.is_os_windows()
subprocess.call(["apktool", "b", folder, '--use-aapt2', "-o", output_filename], shell=shell)
Expand Down