from .util import *
from .merge_resources import merge_resources

import subprocess

def assemble_apk():
    updated = merge_resources()
    
    print(f"IS UPDATED: {updated}")
    
    if not updated and Path(ASSEMBLED_APK).exists():
        print("Skipping assembly")
        return False
    
    # Assemble
    print("Assembling APK...")
    res = subprocess.run([JAVA_BIN, '-jar', APKTOOL, 'b', MERGED_RSC_DIR, '-o', ASSEMBLED_APK])
    if res.returncode != 0:
        print("Error ocurred while assembling")
        exit(res.returncode)
    
    return True