Android build for ungoogled-chromium. https://uc.droidware.info
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.8 KiB

10 months ago
  1. #!/bin/bash
  2. # Modified from Vanadium
  3. set -o errexit -o nounset -o pipefail
  4. SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  5. source "${SCRIPT_PATH}/.build_config"
  6. KEYSTORE=$PWD/../../uc_keystore/uc-release-key.keystore
  7. KEYSTORE_PASS=$PWD/../../uc_keystore/keystore_pass
  8. APKSIGNER=$PWD/third_party/android_sdk/public/build-tools/30.0.1/apksigner
  9. BUNDLETOOL=$PWD/build/android/gyp/bundletool.py
  10. AAPT2=$PWD/third_party/android_build_tools/aapt2/aapt2
  11. # Argument parser from https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash/29754866#29754866
  12. # -allow a command to fail with !’s side effect on errexit
  13. # -use return value from ${PIPESTATUS[0]}, because ! hosed $?
  14. ! getopt --test > /dev/null
  15. if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
  16. echo 'I’m sorry, `getopt --test` failed in this environment.'
  17. exit 1
  18. fi
  19. OPTIONS=o:a:t:
  20. LONGOPTS=output:,arch:,target:
  21. # -regarding ! and PIPESTATUS see above
  22. # -temporarily store output to be able to check for errors
  23. # -activate quoting/enhanced mode (e.g. by writing out “--options”)
  24. # -pass arguments only via -- "[email protected]" to separate them correctly
  25. ! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "[email protected]")
  26. if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
  27. # e.g. return value is 1
  28. # then getopt has complained about wrong arguments to stdout
  29. exit 2
  30. fi
  31. # read getopt’s output this way to handle the quoting right:
  32. eval set -- "$PARSED"
  33. OUTPUT=- TARGET=-
  34. # now enjoy the options in order and nicely split until we see --
  35. while true; do
  36. case "$1" in
  37. -o|--output)
  38. OUTPUT="$2"
  39. shift 2
  40. ;;
  41. -a|--arch)
  42. ARCH="$2"
  43. shift 2
  44. ;;
  45. -t|--target)
  46. TARGET="$2"
  47. shift 2
  48. ;;
  49. --)
  50. shift
  51. break
  52. ;;
  53. *)
  54. echo "Programming error"
  55. exit 3
  56. ;;
  57. esac
  58. done
  59. if [[ "$ARCH" != "arm64" ]] && [[ "$ARCH" != "arm" ]] && [[ "$ARCH" != "x86" ]]; then
  60. echo "Wrong architecture"
  61. exit 4
  62. fi
  63. if [[ "$TARGET" != "$chrome_modern_target" ]] && [[ "$TARGET" != "$trichrome_chrome_bundle_target" ]] && [[ "$TARGET" != "$trichrome_chrome_64_bundle_target" ]] \
  64. && [[ "$TARGET" != "$trichrome_chrome_apk_target" ]] && [[ "$TARGET" != "$trichrome_webview_target" ]] && [[ "$TARGET" != "$trichrome_webview_64_target" ]]; then
  65. echo "Wrong target"
  66. exit 4
  67. fi
  68. if [[ ! -d $OUTPUT ]]; then
  69. echo "Output folder doesn't exist"
  70. exit 1
  71. fi
  72. case "$TARGET" in
  73. "$chrome_modern_target")
  74. FILENAME="ChromeModernPublic"
  75. FILENAME_OUT="ChromeModernPublic"
  76. ;;
  77. "$trichrome_chrome_bundle_target")
  78. FILENAME="TrichromeChrome"
  79. FILENAME_OUT="TrichromeChrome"
  80. ;;
  81. "$trichrome_chrome_64_bundle_target")
  82. FILENAME="TrichromeChrome64"
  83. FILENAME_OUT="TrichromeChrome"
  84. ;;
  85. "$trichrome_chrome_apk_target")
  86. FILENAME="TrichromeChrome"
  87. FILENAME_OUT="TrichromeChrome"
  88. ;;
  89. "$trichrome_webview_target")
  90. FILENAME="TrichromeWebView"
  91. FILENAME_OUT="TrichromeWebView"
  92. ;;
  93. "$trichrome_webview_64_target")
  94. FILENAME="TrichromeWebView64"
  95. FILENAME_OUT="TrichromeWebView"
  96. ;;
  97. *)
  98. echo "Filename parsing error"
  99. exit 3
  100. ;;
  101. esac
  102. echo "output: $OUTPUT, arch: $ARCH, target: $TARGET, filename: $FILENAME"
  103. cd $OUTPUT/apks
  104. rm -rf release
  105. mkdir release
  106. cd release
  107. if [[ "$TARGET" != "$trichrome_webview_target" ]] && [[ "$TARGET" != "$trichrome_webview_64_target" ]] && [[ "$TARGET" != "$trichrome_chrome_apk_target" ]]; then
  108. $BUNDLETOOL build-apks --aapt2 $AAPT2 --bundle ../"$FILENAME".aab --output "$FILENAME".apks --mode=universal --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc
  109. unzip "$FILENAME".apks universal.apk
  110. mv universal.apk "${FILENAME_OUT}".apk
  111. $APKSIGNER sign --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc --in "${FILENAME_OUT}".apk --out "${FILENAME_OUT}".apk
  112. fi
  113. if [[ "$TARGET" == "$trichrome_chrome_bundle_target" ]] || [[ "$TARGET" == "$trichrome_webview_target" ]] || [[ "$TARGET" == "$trichrome_chrome_apk_target" ]]; then
  114. for app in TrichromeLibrary TrichromeWebView TrichromeChrome; do
  115. if [ -f "../${app}.apk" ]; then
  116. $APKSIGNER sign --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc --in "../${app}.apk" --out "${app}.apk"
  117. fi
  118. done
  119. fi
  120. if [[ "$TARGET" == "$trichrome_chrome_64_bundle_target" ]] || [[ "$TARGET" == "$trichrome_webview_64_target" ]]; then
  121. for app in TrichromeLibrary TrichromeWebView; do
  122. if [ -f "../${app}64.apk" ]; then
  123. $APKSIGNER sign --ks $KEYSTORE --ks-pass file:$KEYSTORE_PASS --ks-key-alias uc --in "../${app}64.apk" --out "${app}.apk"
  124. fi
  125. done
  126. fi