split apk support

This commit is contained in:
2026-12-05 21:45:37 +05:00
parent b2e5d7ef1e
commit 64e528b706
4 changed files with 100 additions and 16 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
set -e
gradle assembleRelease
APP_NAME=$(grep 'app_name' app/src/main/res/values/strings.xml | sed 's/.*>\(.*\)<.*/\1/' | tr -d ' ')
APP_VERSION=$(grep 'versionName = ' app/build.gradle.kts | sed 's/.*versionName = "\(.*\)".*/\1/')
OUT=app/build/outputs/apk/release
declare -A ABIS=(
[armeabi-v7a]=arm32
[arm64-v8a]=arm64
[x86]=x86
[x86_64]=x86_64
[universal]=universal
)
for ABI in "${!ABIS[@]}"; do
SRC="${OUT}/app-${ABI}-release.apk"
if [ ! -f "$SRC" ]; then
echo "Missing expected APK: $SRC" >&2
exit 1
fi
mv "$SRC" "/release/${APP_NAME}-v${APP_VERSION}-${ABIS[$ABI]}.apk"
done
ls -l /release
+3
View File
@@ -3,7 +3,10 @@ services:
image: git.shihaam.dev/dockerfiles/runners/gradle
network_mode: host
env_file: .env
# custom build apk script with multi arch support
command: ["bash", "/bin/build-apk.sh"]
volumes:
- ./release:/release
- ../../:/source
- ./build-apk.sh:/bin/build-apk.sh:ro
- /root/.cache/cache-runners/gradle:/root/.gradle
+59 -16
View File
@@ -24,12 +24,30 @@ jobs:
working-directory: .build/release
run: docker compose run --rm release
- name: Rename APK
- name: Rename APKs
run: |
APP_NAME="${{ gitea.repository }}"
APP_NAME="${APP_NAME//\//-}"
TAG="${{ gitea.ref_name }}"
find .build/release/release/ -maxdepth 1 -name "*.apk" | head -1 | xargs -I{} mv {} ".build/release/release/${APP_NAME}-${TAG}.apk"
OUT=".build/release/release"
mkdir -p dist
# build-apk.sh outputs <App>-v<version>-<arch>.apk
for ARCH in arm32 arm64 x86 x86_64 universal; do
APK=$(find "$OUT" -maxdepth 1 -name "*-${ARCH}.apk" | head -1)
if [ -z "$APK" ]; then
echo "Missing APK for $ARCH"
exit 1
fi
mv "$APK" "dist/${APP_NAME}-${TAG}-${ARCH}.apk"
done
ls -l dist
COUNT=$(ls dist/*.apk 2>/dev/null | wc -l)
if [ "$COUNT" -ne 5 ]; then
echo "Expected 5 APKs, found $COUNT"
exit 1
fi
- name: Extract release notes
run: |
@@ -54,7 +72,6 @@ jobs:
TAG="${{ gitea.ref_name }}"
TITLE="${APP_NAME} ${TAG}"
NOTES_FILE="release_notes.md"
ASSET_PATH=".build/release/release/${APP_NAME}-${TAG}.apk"
API_URL="${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases"
@@ -77,17 +94,23 @@ jobs:
echo "Created release with ID: $RELEASE_ID"
ASSET_NAME=$(basename "$ASSET_PATH")
UPLOAD_URL="${API_URL}/${RELEASE_ID}/assets?name=${ASSET_NAME}"
for ASSET_PATH in dist/*.apk; do
ASSET_NAME=$(basename "$ASSET_PATH")
UPLOAD_URL="${API_URL}/${RELEASE_ID}/assets?name=${ASSET_NAME}"
curl -s -X POST "$UPLOAD_URL" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@${ASSET_PATH}"
HTTP_CODE=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$UPLOAD_URL" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@${ASSET_PATH}")
echo "Uploaded asset: $ASSET_NAME"
if [ "$HTTP_CODE" != "201" ]; then
echo "Failed to upload $ASSET_NAME (HTTP $HTTP_CODE)"
exit 1
fi
echo "Uploaded asset: $ASSET_NAME"
done
- name: Send APK to Telegram
- name: Send APKs to Telegram
env:
TG_BOT_TOKEN: ${{ secrets.TG_BOT_TOKEN }}
TG_CHAT_ID: ${{ vars.TG_CHAT_ID }}
@@ -100,10 +123,30 @@ jobs:
APP_NAME="${{ gitea.repository }}"
APP_NAME="${APP_NAME//\//-}"
TAG="${{ gitea.ref_name }}"
ASSET_PATH=".build/release/release/${APP_NAME}-${TAG}.apk"
CAPTION="$(printf '%s\n\n%s' "${APP_NAME} ${TAG}" "$(cat release_notes.md)" | head -c 1024)"
curl -s -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendDocument" \
-F "chat_id=${TG_CHAT_ID}" \
-F "document=@${ASSET_PATH}" \
--form-string "caption=${CAPTION}"
# Send all APKs as a single album; Telegram shows the caption of the last item.
ARGS=()
MEDIA="[]"
FILES=(dist/*.apk)
LAST=$(( ${#FILES[@]} - 1 ))
for i in "${!FILES[@]}"; do
ARGS+=(-F "file${i}=@${FILES[$i]}")
if [ "$i" -eq "$LAST" ]; then
MEDIA=$(jq -c --arg m "attach://file${i}" --arg c "$CAPTION" '. + [{type:"document",media:$m,caption:$c}]' <<<"$MEDIA")
else
MEDIA=$(jq -c --arg m "attach://file${i}" '. + [{type:"document",media:$m}]' <<<"$MEDIA")
fi
done
RESPONSE=$(curl -s -X POST "https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMediaGroup" \
--form-string "chat_id=${TG_CHAT_ID}" \
--form-string "media=${MEDIA}" \
"${ARGS[@]}")
if [ "$(echo "$RESPONSE" | jq -r '.ok')" != "true" ]; then
echo "Telegram upload failed:"
echo "$RESPONSE"
exit 1
fi
echo "Sent ${#FILES[@]} APKs to Telegram"
+10
View File
@@ -39,6 +39,16 @@ android {
}
}
// multi arch support
splits {
abi {
isEnable = true
reset()
include("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
isUniversalApk = true
}
}
buildTypes {
debug {
applicationIdSuffix = ".debug"