build: local android release

This commit is contained in:
ardocrat 2024-09-14 01:47:06 +03:00
parent 6f7156ef17
commit 68c9c9df04
3 changed files with 67 additions and 170 deletions

View file

@ -2,43 +2,6 @@ name: Build
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
android:
name: Android Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Setup build
run: |
cargo install cargo-ndk
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add x86_64-linux-android
- name: Setup Java build
run: |
chmod +x android/gradlew
echo "${{ secrets.ANDROID_RELEASE }}" > release.keystore.txt
base64 -d release.keystore.txt > android/keystore
echo -e "storePassword=${{ secrets.ANDROID_RELEASE_STORE }}\nkeyPassword=${{ secrets.ANDROID_RELEASE_KEY }}\nkeyAlias=${{ secrets.ANDROID_RELEASE_ALIAS }}\nstoreFile=../keystore" > android/keystore.properties
- name: Build lib 1/2
continue-on-error: true
run: |
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0" && cargo ndk -t arm64-v8a build --profile release-apk
- name: Build lib 2/2
run: |
unset CPPFLAGS && unset CFLAGS && cargo ndk -t arm64-v8a -o android/app/src/main/jniLibs build --profile release-apk
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
- name: Build APK
working-directory: android
run: |
./gradlew assembleRelease
linux: linux:
name: Linux Build name: Linux Build
runs-on: ubuntu-latest runs-on: ubuntu-latest

View file

@ -6,89 +6,6 @@ on:
- "v*.*.*" - "v*.*.*"
jobs: jobs:
android_release:
name: Android Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Setup Rust build
run: |
cargo install cargo-ndk
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add x86_64-linux-android
- name: Setup Java build
run: |
chmod +x android/gradlew
echo "${{ secrets.ANDROID_RELEASE }}" > release.keystore.txt
base64 -d release.keystore.txt > android/keystore
echo -e "storePassword=${{ secrets.ANDROID_RELEASE_STORE }}\nkeyPassword=${{ secrets.ANDROID_RELEASE_KEY }}\nkeyAlias=${{ secrets.ANDROID_RELEASE_ALIAS }}\nstoreFile=../keystore" > android/keystore.properties
- name: Build lib ARMv8 1/2
continue-on-error: true
run: |
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0" && cargo ndk -t arm64-v8a build --profile release-apk
- name: Build lib ARMv8 2/2
run: |
unset CPPFLAGS && unset CFLAGS && cargo ndk -t arm64-v8a -o android/app/src/main/jniLibs build --profile release-apk
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
- name: Build lib ARMv7 1/2
continue-on-error: true
run: |
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0" && cargo ndk -t armeabi-v7a build --profile release-apk
- name: Build lib ARMv7 2/2
run: |
unset CPPFLAGS && unset CFLAGS && cargo ndk -t armeabi-v7a -o android/app/src/main/jniLibs build --profile release-apk
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
- name: Build APK ARM
working-directory: android
run: |
rm -rf app/build
./gradlew assembleRelease
mv app/build/outputs/apk/release/app-release.apk grim-${{ github.ref_name }}-android.apk
rm -rf app/src/main/jniLibs/*
- name: Checksum APK ARM
working-directory: android
shell: pwsh
run: get-filehash -algorithm sha256 grim-${{ github.ref_name }}-android.apk | Format-List | Out-String | ForEach-Object { $_.Trim() } > grim-${{ github.ref_name }}-android-sha256sum.txt
- name: Build lib x86 1/2
continue-on-error: true
run: |
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0" && cargo ndk -t x86_64 build --profile release-apk
- name: Build lib x86 2/2
run: |
unset CPPFLAGS && unset CFLAGS && cargo ndk -t x86_64 -o android/app/src/main/jniLibs build --profile release-apk
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
- name: Build APK x86
working-directory: android
run: |
rm -rf app/build
./gradlew assembleRelease
mv app/build/outputs/apk/release/app-release.apk grim-${{ github.ref_name }}-android-x86_64.apk
- name: Checksum APK x86
working-directory: android
shell: pwsh
run: get-filehash -algorithm sha256 grim-${{ github.ref_name }}-android-x86_64.apk | Format-List | Out-String | ForEach-Object { $_.Trim() } > grim-${{ github.ref_name }}-android-x86_64-sha256sum.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
files: |
android/grim-${{ github.ref_name }}-android.apk
android/grim-${{ github.ref_name }}-android-sha256sum.txt
android/grim-${{ github.ref_name }}-android-x86_64.apk
android/grim-${{ github.ref_name }}-android-x86_64-sha256sum.txt
linux_release: linux_release:
name: Linux Release name: Linux Release
runs-on: ubuntu-latest runs-on: ubuntu-latest

View file

@ -1,81 +1,98 @@
#!/bin/bash #!/bin/bash
usage="Usage: build_run_android.sh [type] [platform]\n - type: 'debug', 'release'\n - platform: 'v7', 'v8'" usage="Usage: android.sh [type] [platform]\n - type: 'build', 'release', ''\n - platform, for build type: 'v7', 'v8', 'x86'"
case $1 in case $1 in
debug|release) build|release)
;; ;;
*) *)
printf "$usage" printf "$usage"
exit 1 exit 1
esac esac
case $2 in if [[ $1 == "build" ]]; then
v7|v8) case $2 in
;; v7|v8|x86)
*) ;;
printf "$usage" *)
exit 1 printf "$usage"
esac exit 1
esac
fi
# Setup build directory # Setup build directory
BASEDIR=$(cd $(dirname $0) && pwd) BASEDIR=$(cd $(dirname $0) && pwd)
cd ${BASEDIR} cd ${BASEDIR}
cd .. cd ..
# Setup release argument # Install platforms and tools
type=$1 rustup target add armv7-linux-androideabi
[[ ${type} == "release" ]] && release_param="--profile release-apk" rustup target add aarch64-linux-android
rustup target add x86_64-linux-android
# Setup platform argument
[[ $2 == "v7" ]] && arch+=(armeabi-v7a)
[[ $2 == "v8" ]] && arch+=(arm64-v8a)
# Setup platform path
[[ $2 == "v7" ]] && platform+=(armv7-linux-androideabi)
[[ $2 == "v8" ]] && platform+=(aarch64-linux-android)
# Install platform
[[ $2 == "v7" ]] && rustup target install armv7-linux-androideabi
[[ $2 == "v8" ]] && rustup target install aarch64-linux-android
# Build native code
cargo install cargo-ndk cargo install cargo-ndk
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
# temp fix for https://stackoverflow.com/questions/57193895/error-use-of-undeclared-identifier-pthread-mutex-robust-cargo-build-liblmdb-s
success=0 success=0
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0"
cargo ndk -t ${arch} build ${release_param}
unset CPPFLAGS && unset CFLAGS
cargo ndk -t ${arch} -o android/app/src/main/jniLibs build ${release_param}
if [ $? -eq 0 ]
then
success=1
fi
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml ### Build native code
function build_lib() {
[[ $1 == "v7" ]] && arch=(armeabi-v7a)
[[ $1 == "v8" ]] && arch=(arm64-v8a)
[[ $1 == "x86" ]] && arch=(x86_64)
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
# Fix for https://stackoverflow.com/questions/57193895/error-use-of-undeclared-identifier-pthread-mutex-robust-cargo-build-liblmdb-s
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0"
cargo ndk -t ${arch} build --profile release-apk
unset CPPFLAGS && unset CFLAGS
cargo ndk -t ${arch} -o android/app/src/main/jniLibs build --profile release-apk
if [ $? -eq 0 ]
then
success=1
fi
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
}
### Build application
function build_apk() {
version=$(grep -m 1 -Po 'version = "\K[^"]*' Cargo.toml)
# Build Android application and launch at all connected devices
if [ $success -eq 1 ]
then
cd android cd android
# Setup gradle argument
[[ $1 == "release" ]] && gradle_param+=(assembleRelease)
[[ $1 == "debug" ]] && gradle_param+=(build)
./gradlew clean ./gradlew clean
./gradlew ${gradle_param} ./gradlew assembleRelease
# Setup apk path # Setup release file name
[[ $1 == "release" ]] && apk_path+=(app/build/outputs/apk/release/app-release.apk) if [ -n $1 ]; then
[[ $1 == "debug" ]] && apk_path+=(app/build/outputs/apk/debug/app-debug.apk) rm -rf grim-${version}-$1.apk
mv app/build/outputs/apk/release/app-release.apk grim-${version}-$1.apk
fi
cd ..
}
# Remove build targets
rm -rf target/release-apk
rm -rf target/aarch64-linux-android
rm -rf target/x86_64-linux-android
rm -rf target/armv7-linux-androideabi
rm -rf android/app/src/main/jniLibs/*
if [[ $1 == "build" ]]; then
build_lib $2
[ $success -eq 1 ] && build_apk
# Launch application at all connected devices.
for SERIAL in $(adb devices | grep -v List | cut -f 1); for SERIAL in $(adb devices | grep -v List | cut -f 1);
do do
adb -s $SERIAL install ${apk_path} adb -s $SERIAL install ${apk_path}
sleep 1s sleep 1s
adb -s $SERIAL shell am start -n mw.gri.android/.MainActivity; adb -s $SERIAL shell am start -n mw.gri.android/.MainActivity;
done done
else
build_lib "v7"
[ $success -eq 1 ] && build_lib "v8"
[ $success -eq 1 ] && build_apk "arm"
rm -rf android/app/src/main/jniLibs/*
[ $success -eq 1 ] && build_lib "x86"
[ $success -eq 1 ] && build_apk "x86_64"
fi fi