on findAndReplaceInText(theText, theSearchString, theReplacementString) set AppleScript's text item delimiters to theSearchString set theTextItems to every text item of theText set AppleScript's text item delimiters to theReplacementString set theText to theTextItems as string set AppleScript's text item delimiters to "" return theText end findAndReplaceInText set apksfound to "no" set apkfound to "no" set apkalreadyexists to "no" set aabpath to POSIX path of (choose file with prompt "Select AAB" of type "aab") set outputapks to findAndReplaceInText(aabpath, ".aab", ".apks") set outputapk to findAndReplaceInText(aabpath, ".aab", ".apk") tell application "Finder" to if exists outputapks as POSIX file then set apkalreadyexists to "yes" if apkalreadyexists = "yes" then display alert "An APKS already exists in the specified directory. Please rename or delete it and try again." quit end if display dialog "Bundle Name" default answer "" with title "Enter Bundle Name" buttons {"OK"} default button 1 if the button returned of the result is "OK" then set bundlename to text returned of the result else quit end if set bundletoolpath to POSIX path of (choose file with prompt "Select bundletool" of type "jar") set keystorepath to POSIX path of (choose file with prompt "Select Keystore") display dialog "Keystore Password" default answer "" with title "Enter Keystore Password" buttons {"OK"} default button 1 if the button returned of the result is "OK" then set keystorepass to text returned of the result else quit end if set apkcommand to ("java -jar " & "\"" & bundletoolpath & "\"" & " build-apks --ks=" & "\"" & keystorepath & "\" --ks-key-alias=" & bundlename & " --mode=universal --ks-pass=pass:" & keystorepass & " --bundle " & "\"" & aabpath & "\"" & " --output=\"" & outputapks & "\"") display alert "Press OK to begin generating your APKS. This may take several minutes and you'll see no feedback while it does it, so please wait..." do shell script apkcommand repeat until apksfound = "yes" tell application "Finder" to if exists outputapks as POSIX file then set apksfound to "yes" end repeat if apksfound = "yes" then display alert "APKS generated. Press OK to extract the APK." set zipcommand to "unzip -p " & "\"" & outputapks & "\"" & " universal.apk >" & "\"" & outputapk & "\"" do shell script zipcommand end if repeat until apkfound = "yes" tell application "Finder" to if exists outputapk as POSIX file then set apkfound to "yes" end repeat if apkfound = "yes" then display alert "All done! Your APK is in the same folder as your AAB file." quit end if