add basic android building support

This commit is contained in:
j-hc 2023-01-27 19:13:28 +03:00
parent ba170ffa20
commit 4705c7ec24
6 changed files with 91 additions and 39 deletions

View File

@ -3,36 +3,40 @@
Adding a new app is as easy as this:
```toml
[Some-App]
apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app" # download url for the app.
apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app"
```
or:
```toml
[Some-App]
uptodown-dlurl = "https://app.en.uptodown.com/android" # uptodown url.
uptodown-dlurl = "https://app.en.uptodown.com/android"
```
## If you'd like to get to know more about other options:
There exists an example below with all defaults and all the keys explicitly set.
Almost all keys are optional and are assigned their default values if not set explicitly.
There exists an example below with all defaults shown and all the keys explicitly set.
All keys are optional (except download urls) and are assigned to their default values if not set explicitly.
```toml
[Some-App]
app-name = "SomeApp" # if set, app name becomes SomeApp instead of Some-App. default is same as table name.
app-name = "SomeApp" # if set, app name becomes SomeApp instead of Some-App. default is same as table name, which is 'Some-App' here.
# this affects the release name and stuff like that
enabled = true # whether to build the app. default: true
build-mode = "both" # 'both', 'apk' or 'module'. default: apk
allow-alpha-version = false # allow downloading alpha versions from apkmirror. default: false
excluded-patches = "some-patch" # whitespace seperated list of patches to exclude. default: "" (empty)
included-patches = "patch-name" # whitespace seperated list of patches to include. default: "" (empty)
version = "auto" # 'auto', 'latest' or a custom one e.g. '17.40.41'. default: auto
exclusive-patches = false # exclude all patches by default. default: false
microg-patch = "microg-support" # name of the microg-patch if exists for the app. default: "" (empty)
apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app" # download url. if not set, uptodown dl url is used.
enabled = true # whether to build the app. default: true
build-mode = "both" # 'both', 'apk' or 'module'. default: apk
allow-alpha-version = false # allow downloading alpha versions from apkmirror. default: false
excluded-patches = "some-patch" # whitespace seperated list of patches to exclude. default: "" (empty)
included-patches = "patch-name" # whitespace seperated list of patches to include. default: "" (empty)
version = "auto" # 'auto', 'latest' or a custom one e.g. '17.40.41'. 'auto' option gets the latest version that is supported by the patches. default: auto
exclusive-patches = false # exclude all patches by default. default: false
microg-patch = "microg-support" # name of the microg-patch if exists for the app. default: "" (empty)
apkmirror-dlurl = "https://www.apkmirror.com/apk/inc/app" # download url. if not set, uptodown dl url is used.
uptodown-dlurl = "https://spotify.en.uptodown.com/android" # uptodown url. if not set, apkmirror dl url is used. apkmirror is prioritized
module-prop-name = "ytrv-magisk" # explicit magisk module prop name. not explicitly needed to be set.
arch = "arm64-v8a" # 'arm64-v8a', 'arm-v7a' or 'all'.
# this option is sometimes needed to be able to download the apks from apkmirror. default: all
module-prop-name = "ytrv-magisk" # magisk module prop name. not required.
arch = "arm64-v8a" # 'arm64-v8a', 'arm-v7a' or 'all'. default: all
# arch option is sometimes needed to be able to download the apks from apkmirror.
# and does not affect anything else
```
# Building ReVanced Extended
Use [`config-rv-ex.toml`](./config-rv-ex.toml) as the config.
By replacing config.toml with config-rv-ex.toml.

View File

@ -38,10 +38,16 @@ To add more Revanced apps or know more about `config.toml`, read here [`CONFIG.m
To be able to use non-root variants of YouTube and YT Music, install [Vanced MicroG](https://github.com/TeamVanced/VancedMicroG/releases).
# Building Locally
## On Termux
```console
$ curl -sSf https://raw.githubusercontent.com/j-hc/revanced-magisk-module/main/build-termux.sh | bash
```
## On Desktop
Make sure you have JDK 17 installed. Then run:
```console
$ git clone --recurse-submodules https://github.com/j-hc/revanced-magisk-module
$ git clone --recurse https://github.com/j-hc/revanced-magisk-module
$ cd revanced-magisk-module
$ ./build.sh
```

28
build-termux.sh Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -e
pr() {
echo -e "\033[0;32m[+] ${1}\033[0m"
}
pr "Setting up environment..."
(yes "" | pkg update -y && pkg install -y git wget openssl jq openjdk-17)
pr "Cloning revanced-magisk-module repository..."
git clone https://github.com/j-hc/revanced-magisk-module --recurse --depth 1
cd revanced-magisk-module
sed -i '/^enabled.*/d; /^\[.*\]/a enabled = false' config.toml
pr "Do you want to open the config.toml for customizations? [y/n]"
read -r y
if [ "$y" = y ]; then
nano config.toml
else
pr "No app is selected for patching."
fi
pr "Setup is done. Do you want to start building? [y/n]"
read -r y
if [ "$y" = y ]; then
./build.sh
fi

View File

@ -55,7 +55,7 @@ for table_name in $(toml_get_table_names); do
app_args[allow_alpha_version]=$(toml_get "$t" allow-alpha-version) || app_args[allow_alpha_version]=false
app_args[build_mode]=$(toml_get "$t" build-mode) && {
if ! isoneof "${app_args[build_mode]}" both apk module; then
abort "ERROR: undefined build mode '${app_args[build_mode]}' for '${table_name}': only 'both', 'apk' or 'module' are allowed"
abort "ERROR: '${app_args[build_mode]}' is not a valid option for '${table_name}': only 'both', 'apk' or 'module' are allowed"
fi
} || app_args[build_mode]=apk
app_args[uptodown_dlurl]=$(toml_get "$t" uptodown-dlurl) && {
@ -73,7 +73,7 @@ for table_name in $(toml_get_table_names); do
fi
app_args[arch]=$(toml_get "$t" arch) && {
if ! isoneof "${app_args[arch]}" all arm64-v8a arm-v7a; then
abort "ERROR: ${app_args[arch]} is not a valid option for '$table_name': only 'all', 'arm64-v8a', 'arm-v7a' are allowed"
abort "ERROR: '${app_args[arch]}' is not a valid option for '$table_name': only 'all', 'arm64-v8a', 'arm-v7a' are allowed"
fi
} || app_args[arch]="all"
app_args[module_prop_name]=$(toml_get "$t" module-prop-name) || {
@ -97,10 +97,10 @@ wait
rm -rf temp/tmp.*
if [ "$BUILD_MINDETACH_MODULE" = true ]; then
echo "Building mindetach module"
pr "Building mindetach module"
cp -f $PKGS_LIST mindetach-magisk/mindetach/detach.txt
pushd mindetach-magisk/mindetach/
zip -r ../../build/mindetach-"$(grep version= module.prop | cut -d= -f2)".zip .
zip -qr ../../build/mindetach-"$(grep version= module.prop | cut -d= -f2)".zip .
popd
fi
@ -112,4 +112,4 @@ if [ "$youtube_mode" != module ] || [ "$music_arm_mode" != module ] || [ "$music
fi
log "\n[revanced-magisk-module](https://github.com/j-hc/revanced-magisk-module)"
echo "Done"
pr "Done"

View File

@ -2,11 +2,12 @@
compression-level = 9 # compression level for module zips. between 1 and 9
logging-to-file = true # enables logging of every patch process to a seperate file
enable-magisk-update = true # set this to false if you do not want to receive updates for the module in magisk app
parallel-jobs = 3 # max number of concurrent building jobs
parallel-jobs = 1 # max number of concurrent building jobs
build-mindetach-module = true
# add 'enabled = false' for not patching a specific app
[YouTube]
enabled = true # add 'enabled = false' key to entries to not build them
enabled = true
build-mode = "both" # 'both', 'apk' or 'module'
excluded-patches = "debugging" # whitespace seperated list of patches to exclude (multiline strings are not supported)
included-patches = "" # whitespace seperated list of patches to include

View File

@ -10,6 +10,7 @@ if [ "${GITHUB_TOKEN:-}" ]; then GH_HEADER="Authorization: token ${GITHUB_TOKEN}
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-"j-hc/revanced-magisk-module"}
NEXT_VER_CODE=${NEXT_VER_CODE:-$(date +'%Y%m%d')}
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"
OS=$(uname -o)
SERVICE_SH=$(cat $MODULE_SCRIPTS_DIR/service.sh)
CUSTOMIZE_SH=$(cat $MODULE_SCRIPTS_DIR/customize.sh)
@ -33,8 +34,10 @@ toml_get() {
}
# ---------------------------------------------------
pr() { echo -e "\033[0;32m[+] ${1}\033[0m"; }
get_prebuilts() {
echo "Getting prebuilts"
pr "Getting prebuilts"
local rv_cli_url rv_integrations_url rv_patches rv_patches_changelog rv_patches_dl rv_patches_url
rv_cli_url=$(gh_req "https://api.github.com/repos/j-hc/revanced-cli/releases/latest" - | json_get 'browser_download_url') || return 1
RV_CLI_JAR="${PREBUILTS_DIR}/${rv_cli_url##*/}"
@ -57,6 +60,12 @@ get_prebuilts() {
dl_if_dne "$RV_INTEGRATIONS_APK" "$rv_integrations_url"
dl_if_dne "$RV_PATCHES_JAR" "$rv_patches_url"
dl_if_dne "$RV_PATCHES_JSON" "$(grep 'json' <<<"$rv_patches_dl")"
if [ "$OS" = Android ]; then
local arch
if [ "$(uname -m)" = aarch64 ]; then arch=arm64; else arch=arm; fi
dl_if_dne ${TEMP_DIR}/aapt2 https://github.com/rendiix/termux-aapt/raw/main/prebuilt-binary/${arch}/aapt2
fi
}
get_cmpr() {
@ -122,7 +131,7 @@ semver_validate() {
dl_if_dne() {
if [ ! -f "$1" ]; then
echo -e "\nGetting '$1' from '$2'"
pr "Getting '$1' from '$2'"
req "$2" "$1"
fi
}
@ -184,7 +193,10 @@ patch_apk() {
local stock_input=$1 patched_apk=$2 patcher_args=$3
declare -r tdir=$(mktemp -d -p $TEMP_DIR)
local cmd="java -jar $RV_CLI_JAR --rip-lib x86_64 --rip-lib x86 --temp-dir=$tdir -c -a $stock_input -o $patched_apk -b $RV_PATCHES_JAR --keystore=ks.keystore $patcher_args"
echo "$cmd"
if [ "$OS" = Android ]; then
cmd+=" --custom-aapt2-binary=${TEMP_DIR}/aapt2"
fi
pr "$cmd"
if [ "${DRYRUN:-}" = true ]; then
cp -f "$stock_input" "$patched_apk"
else
@ -197,9 +209,9 @@ zip_module() {
local patched_apk=$1 module_name=$2 stock_apk=$3 pkg_name=$4 template_dir=$5
cp -f "$patched_apk" "${template_dir}/base.apk"
cp -f "$stock_apk" "${template_dir}/${pkg_name}.apk"
pushd "$template_dir" || abort "Module template dir not found"
zip -"$COMPRESSION_LEVEL" -FSr "../../${BUILD_DIR}/${module_name}" .
popd || :
pushd >/dev/null "$template_dir" || abort "Module template dir not found"
zip -"$COMPRESSION_LEVEL" -FSqr "../../${BUILD_DIR}/${module_name}" .
popd >/dev/null || :
}
build_rv() {
@ -242,15 +254,15 @@ build_rv() {
fi
fi
if [ -z "$version" ]; then
echo "ERROR: empty version,not building ${app_name}."
pr "empty version, not building ${app_name}."
return 0
fi
echo "Choosing version '${version}' (${app_name})"
pr "Choosing version '${version}' (${app_name})"
local version_f=${version// /}
local stock_apk="${TEMP_DIR}/${pkg_name}-stock-${version_f}-${arch}.apk"
if [ ! -f "$stock_apk" ]; then
if [ "$dl_from" = apkmirror ]; then
echo "Downloading '${app_name}' from APKMirror"
pr "Downloading '${app_name}' from APKMirror"
if [ "$arch" = "all" ]; then
apkmirror_regex="APK</span>[^@]*@\([^#]*\)"
elif [ "$arch" = "arm64-v8a" ]; then
@ -262,7 +274,7 @@ build_rv() {
abort "ERROR: Could not find any release of '${app_name}' with version '${version}' from APKMirror"
fi
elif [ "$dl_from" = uptodown ]; then
echo "Downloading '${app_name}' from Uptodown"
pr "Downloading '${app_name}' from Uptodown"
if ! dl_uptodown "$uptwod_resp" "$version" "$stock_apk"; then
abort "ERROR: Could not download ${app_name} from Uptodown"
fi
@ -293,7 +305,7 @@ build_rv() {
local patcher_args patched_apk
for build_mode in "${build_mode_arr[@]}"; do
patcher_args=("${p_patcher_args[@]}")
echo "Building '${app_name}' (${arch}) in '$build_mode' mode"
pr "Building '${app_name}' (${arch}) in '$build_mode' mode"
if [ "$microg_patch" ]; then
patched_apk="${TEMP_DIR}/${app_name_l}-${RV_BRAND_F}-${version_f}-${arch}-${build_mode}.apk"
if [ "$build_mode" = apk ]; then
@ -309,14 +321,14 @@ build_rv() {
fi
if [ ! -f "$patched_apk" ]; then
if ! patch_apk "$stock_apk" "$patched_apk" "${patcher_args[*]}"; then
echo "BUILDING '${app_name}' FAILED"
pr "Building '${app_name}' failed!"
return 0
fi
fi
if [ "$build_mode" = apk ]; then
local apk_output="${BUILD_DIR}/${app_name_l}-${RV_BRAND_F}-v${version_f}-${arch}.apk"
cp -f "$patched_apk" "$apk_output"
echo "Built ${app_name} (${arch}) (non-root): '${apk_output}'"
pr "Built ${app_name} (${arch}) (non-root): '${apk_output}'"
continue
fi
local base_template upj
@ -341,9 +353,10 @@ build_rv() {
"$base_template"
local module_output="${app_name_l}-${RV_BRAND_F}-magisk-v${version}-${arch}.zip"
pr "Packing module ($app_name)"
zip_module "$patched_apk" "$module_output" "$stock_apk" "$pkg_name" "$base_template"
echo "Built ${app_name} (${arch}) (root): '${BUILD_DIR}/${module_output}'"
pr "Built ${app_name} (${arch}) (root): '${BUILD_DIR}/${module_output}'"
done
}