From 0a05674f2ff497d49c9fe13383221fe3047bb903 Mon Sep 17 00:00:00 2001 From: f321x Date: Tue, 24 Jun 2025 17:38:03 +0200 Subject: [PATCH 1/3] android: replace qr code scanning library Replaces the unmaintained and unreliable `me.dm7.barcodescanner:zxing:1.9.8` qr code scanning library used only on android with the `com.github.markusfisch:BarcodeScannerView:1.6.0` (https://github.com/markusfisch/BarcodeScannerView) library which seems more actively maintained. The `BarcodeScannerView` library is incredibly fast and scanning qr codes is now fun again :) wip: still looking into ways to pin the library. --- contrib/android/buildozer_qml.spec | 6 +++- .../electrum/qr/SimpleScannerActivity.java | 30 +++++++++---------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/contrib/android/buildozer_qml.spec b/contrib/android/buildozer_qml.spec index 7e0d32330..59da3d80e 100644 --- a/contrib/android/buildozer_qml.spec +++ b/contrib/android/buildozer_qml.spec @@ -160,9 +160,13 @@ android.add_jars = .buildozer/android/platform/*/build/libs_collections/Electrum # directory containing the files) android.add_src = electrum/gui/qml/java_classes/ +# (list) Gradle repositories to add {can be necessary for some android.gradle_dependencies} +# e.g. android.gradle_repositories = maven { url "https://repo.spring.io/release" } +android.add_gradle_repositories = maven { url "https://jitpack.io" } + android.gradle_dependencies = com.android.support:support-compat:28.0.0, - me.dm7.barcodescanner:zxing:1.9.8 + com.github.markusfisch:BarcodeScannerView:1.6.0 android.add_activities = org.electrum.qr.SimpleScannerActivity diff --git a/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java b/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java index 0f356719f..71e2785c0 100644 --- a/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java +++ b/electrum/gui/qml/java_classes/org/electrum/qr/SimpleScannerActivity.java @@ -20,17 +20,15 @@ import androidx.core.app.ActivityCompat; import java.util.Arrays; -import me.dm7.barcodescanner.zxing.ZXingScannerView; +import de.markusfisch.android.barcodescannerview.widget.BarcodeScannerView; -import com.google.zxing.Result; -import com.google.zxing.BarcodeFormat; import org.electrum.electrum.res.R; // package set in build.gradle -public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler { +public class SimpleScannerActivity extends Activity { private static final int MY_PERMISSIONS_CAMERA = 1002; - private ZXingScannerView mScannerView = null; + private BarcodeScannerView mScannerView = null; final String TAG = "org.electrum.SimpleScannerActivity"; private boolean mAlreadyRequestedPermissions = false; @@ -85,23 +83,23 @@ public class SimpleScannerActivity extends Activity implements ZXingScannerView. public void onPause() { super.onPause(); if (null != mScannerView) { - mScannerView.stopCamera(); // Stop camera on pause + mScannerView.close(); // Stop camera on pause } } private void startCamera() { - mScannerView = new ZXingScannerView(this); - mScannerView.setFormats(Arrays.asList(BarcodeFormat.QR_CODE)); + mScannerView = new BarcodeScannerView(this); + mScannerView.setCropRatio(0.75f); // Set crop ratio to 75% (this defines the square area shown in the scanner view) + // by default only Format.QR_CODE is set ViewGroup contentFrame = (ViewGroup) findViewById(R.id.content_frame); contentFrame.addView(mScannerView); - mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results. - mScannerView.startCamera(); // Start camera on resume - } - - @Override - public void handleResult(Result rawResult) { - //resultIntent.putExtra("format", rawResult.getBarcodeFormat().toString()); - this.setResultAndClose(rawResult.getText()); + mScannerView.setOnBarcodeListener(result -> { + // Handle the scan result + this.setResultAndClose(result.getText()); + // Return false to stop scanning after first result + return false; + }); + mScannerView.openAsync(); // Start camera on resume } private void setResultAndClose(String resultText) { From 5ae2deb7048fec246cde7e97ac4cf640dbf7d0e9 Mon Sep 17 00:00:00 2001 From: f321x Date: Wed, 25 Jun 2025 13:50:48 +0200 Subject: [PATCH 2/3] android: shasum pin barcode scanner pins the barcode scanner aar used in the android build and its 2 dependencies to a sha256 hash using a script `fetch_barcode_scanner.sh` which is called in the process of building the apk by `make_apk.sh`. It fetches the 3 aar files if not already existing, puts them in `/contrib/android/aars` and verifies their shasum against the hardcoded hashes in `fetch_barcode_scanner.sh`. --- .gitignore | 1 + contrib/android/buildozer_qml.spec | 13 +++--- contrib/android/fetch_barcode_scanner.sh | 50 ++++++++++++++++++++++++ contrib/android/make_apk.sh | 4 ++ 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100755 contrib/android/fetch_barcode_scanner.sh diff --git a/.gitignore b/.gitignore index 9f013f3c7..0cb917442 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ contrib/build-linux/appimage/.cache/ contrib/osx/.cache/ contrib/osx/build-venv/ contrib/android/android_debug.keystore +contrib/android/.cache/ contrib/secp256k1/ contrib/zbar/ contrib/libusb/ diff --git a/contrib/android/buildozer_qml.spec b/contrib/android/buildozer_qml.spec index 59da3d80e..a0e4e6709 100644 --- a/contrib/android/buildozer_qml.spec +++ b/contrib/android/buildozer_qml.spec @@ -156,17 +156,20 @@ android.accept_sdk_license = True android.add_jars = .buildozer/android/platform/*/build/libs_collections/Electrum/jar/*.jar +android.add_aars = + contrib/android/.cache/aars/BarcodeScannerView.aar, + contrib/android/.cache/aars/CameraView.aar, + contrib/android/.cache/aars/zxing-cpp.aar + + # (list) List of Java files to add to the android project (can be java or a # directory containing the files) android.add_src = electrum/gui/qml/java_classes/ -# (list) Gradle repositories to add {can be necessary for some android.gradle_dependencies} -# e.g. android.gradle_repositories = maven { url "https://repo.spring.io/release" } -android.add_gradle_repositories = maven { url "https://jitpack.io" } - +# kotlin-stdlib is required for zxing-cpp (BarcodeScannerView) android.gradle_dependencies = com.android.support:support-compat:28.0.0, - com.github.markusfisch:BarcodeScannerView:1.6.0 + org.jetbrains.kotlin:kotlin-stdlib:1.8.22 android.add_activities = org.electrum.qr.SimpleScannerActivity diff --git a/contrib/android/fetch_barcode_scanner.sh b/contrib/android/fetch_barcode_scanner.sh new file mode 100755 index 000000000..ce6056aec --- /dev/null +++ b/contrib/android/fetch_barcode_scanner.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# script to fetch and pin https://github.com/markusfisch/BarcodeScannerView and its dependencies, +# https://github.com/markusfisch/CameraView/ and https://github.com/markusfisch/zxing-cpp +# which are being used as barcode scanner in the Android app. + +# To bump the version of BarcodeScannerView, get the newest version tag from the github repo, +# then get the required dependencies from +# https://jitpack.io/com/github/markusfisch/BarcodeScannerView/**NEWEST_VERSION**/BarcodeScannerView-**NEWEST_VERSION**.pom +# then fetch the aars from jitpack and update the versions and sha256s below. Also update kotlin-stdlib +# in buildozer_qml.spec + +BARCODE_SCANNER_VIEW_VERSION="1.6.0" +BARCODE_SCANNER_VIEW_AAR_SHA256="2be6c9a5ab86f7198683af4a6c0e5acd3e8fe6a02df2d12c3b716dc422537789" + +CAMERA_VIEW_VERSION="1.9.2" +CAMERA_VIEW_AAR_SHA256="3c9be35d29b84637d2a2b0e0e7253bc5a35408fafb26c5cb7225aeb7326e2be4" + +ZXING_CPP_VERSION="v2.2.0.1" +ZXING_CPP_AAR_SHA256="7991381f181ff16555c4ac9c5d83e6a0d3a7da896efb8c3807897305ca33b957" + +DOWNLOAD_REPOSITORY_ROOT="https://jitpack.io/com/github/markusfisch" + +set -e + +CONTRIB_ANDROID="$(dirname "$(readlink -e "$0")")" +CONTRIB="$CONTRIB_ANDROID"/.. +CACHEDIR="$CONTRIB_ANDROID/.cache" + +. "$CONTRIB"/build_tools_util.sh + +# check if $CACHEDIR/aars exists, create it if not +if [ ! -d "$CACHEDIR/aars" ]; then + mkdir -p "$CACHEDIR/aars" +fi + +info "Fetching BarcodeScannerView..." +download_if_not_exist "$CACHEDIR/aars/BarcodeScannerView.aar" \ + "${DOWNLOAD_REPOSITORY_ROOT}/BarcodeScannerView/${BARCODE_SCANNER_VIEW_VERSION}/BarcodeScannerView-${BARCODE_SCANNER_VIEW_VERSION}.aar" +verify_hash "$CACHEDIR/aars/BarcodeScannerView.aar" "$BARCODE_SCANNER_VIEW_AAR_SHA256" + +info "Fetching CameraView..." +download_if_not_exist "$CACHEDIR/aars/CameraView.aar" \ + "${DOWNLOAD_REPOSITORY_ROOT}/CameraView/${CAMERA_VIEW_VERSION}/CameraView-${CAMERA_VIEW_VERSION}.aar" +verify_hash "$CACHEDIR/aars/CameraView.aar" "$CAMERA_VIEW_AAR_SHA256" + +info "Fetching zxing-cpp..." +download_if_not_exist "$CACHEDIR/aars/zxing-cpp.aar" \ + "${DOWNLOAD_REPOSITORY_ROOT}/zxing-cpp/${ZXING_CPP_VERSION}/zxing-cpp-${ZXING_CPP_VERSION}.aar" +verify_hash "$CACHEDIR/aars/zxing-cpp.aar" "$ZXING_CPP_AAR_SHA256" diff --git a/contrib/android/make_apk.sh b/contrib/android/make_apk.sh index 0eb245c91..11b5ad89c 100755 --- a/contrib/android/make_apk.sh +++ b/contrib/android/make_apk.sh @@ -27,6 +27,10 @@ info "preparing electrum-locale." rm -r "$PROJECT_ROOT/electrum/locale/locale"/*/electrum.po ) +# fetch barcode scanner aars +info "fetching barcode scanner aars." +"$CONTRIB_ANDROID"/fetch_barcode_scanner.sh || fail "fetch_barcode_scanner.sh failed" + pushd "$CONTRIB_ANDROID" info "apk building phase starts." From 10b75ebed7e8d0594ded4709cc40e8c840fce6a3 Mon Sep 17 00:00:00 2001 From: f321x Date: Thu, 26 Jun 2025 15:42:49 +0200 Subject: [PATCH 3/3] android: build BarcodeScannerView from src Adds a script `make_barcode_scanner.sh` which builds the `BarcodeScannerView` library and its dependencies, `zxing-cpp` and `CameraView` from source. Builds `zxing-cpp` architecture dependent reducing the final apk size. --- contrib/android/fetch_barcode_scanner.sh | 50 -------- contrib/android/make_apk.sh | 10 +- contrib/android/make_barcode_scanner.sh | 144 +++++++++++++++++++++++ contrib/build_tools_util.sh | 22 ++++ 4 files changed, 172 insertions(+), 54 deletions(-) delete mode 100755 contrib/android/fetch_barcode_scanner.sh create mode 100755 contrib/android/make_barcode_scanner.sh diff --git a/contrib/android/fetch_barcode_scanner.sh b/contrib/android/fetch_barcode_scanner.sh deleted file mode 100755 index ce6056aec..000000000 --- a/contrib/android/fetch_barcode_scanner.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -# script to fetch and pin https://github.com/markusfisch/BarcodeScannerView and its dependencies, -# https://github.com/markusfisch/CameraView/ and https://github.com/markusfisch/zxing-cpp -# which are being used as barcode scanner in the Android app. - -# To bump the version of BarcodeScannerView, get the newest version tag from the github repo, -# then get the required dependencies from -# https://jitpack.io/com/github/markusfisch/BarcodeScannerView/**NEWEST_VERSION**/BarcodeScannerView-**NEWEST_VERSION**.pom -# then fetch the aars from jitpack and update the versions and sha256s below. Also update kotlin-stdlib -# in buildozer_qml.spec - -BARCODE_SCANNER_VIEW_VERSION="1.6.0" -BARCODE_SCANNER_VIEW_AAR_SHA256="2be6c9a5ab86f7198683af4a6c0e5acd3e8fe6a02df2d12c3b716dc422537789" - -CAMERA_VIEW_VERSION="1.9.2" -CAMERA_VIEW_AAR_SHA256="3c9be35d29b84637d2a2b0e0e7253bc5a35408fafb26c5cb7225aeb7326e2be4" - -ZXING_CPP_VERSION="v2.2.0.1" -ZXING_CPP_AAR_SHA256="7991381f181ff16555c4ac9c5d83e6a0d3a7da896efb8c3807897305ca33b957" - -DOWNLOAD_REPOSITORY_ROOT="https://jitpack.io/com/github/markusfisch" - -set -e - -CONTRIB_ANDROID="$(dirname "$(readlink -e "$0")")" -CONTRIB="$CONTRIB_ANDROID"/.. -CACHEDIR="$CONTRIB_ANDROID/.cache" - -. "$CONTRIB"/build_tools_util.sh - -# check if $CACHEDIR/aars exists, create it if not -if [ ! -d "$CACHEDIR/aars" ]; then - mkdir -p "$CACHEDIR/aars" -fi - -info "Fetching BarcodeScannerView..." -download_if_not_exist "$CACHEDIR/aars/BarcodeScannerView.aar" \ - "${DOWNLOAD_REPOSITORY_ROOT}/BarcodeScannerView/${BARCODE_SCANNER_VIEW_VERSION}/BarcodeScannerView-${BARCODE_SCANNER_VIEW_VERSION}.aar" -verify_hash "$CACHEDIR/aars/BarcodeScannerView.aar" "$BARCODE_SCANNER_VIEW_AAR_SHA256" - -info "Fetching CameraView..." -download_if_not_exist "$CACHEDIR/aars/CameraView.aar" \ - "${DOWNLOAD_REPOSITORY_ROOT}/CameraView/${CAMERA_VIEW_VERSION}/CameraView-${CAMERA_VIEW_VERSION}.aar" -verify_hash "$CACHEDIR/aars/CameraView.aar" "$CAMERA_VIEW_AAR_SHA256" - -info "Fetching zxing-cpp..." -download_if_not_exist "$CACHEDIR/aars/zxing-cpp.aar" \ - "${DOWNLOAD_REPOSITORY_ROOT}/zxing-cpp/${ZXING_CPP_VERSION}/zxing-cpp-${ZXING_CPP_VERSION}.aar" -verify_hash "$CACHEDIR/aars/zxing-cpp.aar" "$ZXING_CPP_AAR_SHA256" diff --git a/contrib/android/make_apk.sh b/contrib/android/make_apk.sh index 11b5ad89c..2b6ee7360 100755 --- a/contrib/android/make_apk.sh +++ b/contrib/android/make_apk.sh @@ -27,10 +27,6 @@ info "preparing electrum-locale." rm -r "$PROJECT_ROOT/electrum/locale/locale"/*/electrum.po ) -# fetch barcode scanner aars -info "fetching barcode scanner aars." -"$CONTRIB_ANDROID"/fetch_barcode_scanner.sh || fail "fetch_barcode_scanner.sh failed" - pushd "$CONTRIB_ANDROID" info "apk building phase starts." @@ -90,16 +86,22 @@ if [[ "$2" == "all" ]] ; then # FIXME failures are not propagated out: we should fail the script if any arch build fails export APP_ANDROID_ARCHS=armeabi-v7a export APP_ANDROID_NUMERIC_VERSION=$("$CONTRIB_ANDROID"/get_apk_versioncode.py "$APP_ANDROID_ARCHS") + "$CONTRIB_ANDROID"/make_barcode_scanner.sh "$APP_ANDROID_ARCHS" || fail "make_barcode_scanner.sh failed" make $TARGET + export APP_ANDROID_ARCHS=arm64-v8a export APP_ANDROID_NUMERIC_VERSION=$("$CONTRIB_ANDROID"/get_apk_versioncode.py "$APP_ANDROID_ARCHS") + "$CONTRIB_ANDROID"/make_barcode_scanner.sh "$APP_ANDROID_ARCHS" || fail "make_barcode_scanner.sh failed" make $TARGET + export APP_ANDROID_ARCHS=x86_64 export APP_ANDROID_NUMERIC_VERSION=$("$CONTRIB_ANDROID"/get_apk_versioncode.py "$APP_ANDROID_ARCHS") + "$CONTRIB_ANDROID"/make_barcode_scanner.sh "$APP_ANDROID_ARCHS" || fail "make_barcode_scanner.sh failed" make $TARGET else export APP_ANDROID_ARCHS=$2 export APP_ANDROID_NUMERIC_VERSION=$("$CONTRIB_ANDROID"/get_apk_versioncode.py "$APP_ANDROID_ARCHS") + "$CONTRIB_ANDROID"/make_barcode_scanner.sh "$APP_ANDROID_ARCHS" || fail "make_barcode_scanner.sh failed" make $TARGET fi diff --git a/contrib/android/make_barcode_scanner.sh b/contrib/android/make_barcode_scanner.sh new file mode 100755 index 000000000..19df7752e --- /dev/null +++ b/contrib/android/make_barcode_scanner.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +# script to clone and build https://github.com/markusfisch/BarcodeScannerView and its dependencies, +# https://github.com/markusfisch/CameraView/ and https://github.com/markusfisch/zxing-cpp +# which are being used as barcode scanner in the Android app. + +# To bump the version of BarcodeScannerView, get the newest version tag from the github repo, +# then get the required dependencies from +# https://github.com/markusfisch/BarcodeScannerView/blob/**VERSION_TAG**/barcodescannerview/build.gradle +# then update the commit hashes below. Also update kotlin-stdlib in buildozer_qml.spec to the +# "kotlin-version" specified in the used zxing-cpp commit: +# https://github.com/markusfisch/zxing-cpp/blob/master/wrappers/aar/build.gradle + + +BARCODE_SCANNER_VIEW_COMMIT_HASH="a4928bf83c0aae8ecb80e665d93f10b70232455b" # 1.6.3 +BARCODE_SCANNER_VIEW_REPO="https://github.com/markusfisch/BarcodeScannerView.git" + +CAMERA_VIEW_COMMIT_HASH="745597d05bc6abfdb3637a09a8ecaf30fdce7b6e" # 1.10.0 +CAMERA_VIEW_REPO="https://github.com/markusfisch/CameraView.git" + +ZXING_CPP_COMMIT_HASH="0741a597409ff69a96a326f3a65fe6440d87ad99" # v2.2.0.5 using kotlin-stdlib 1.8.22 +ZXING_CPP_REPO="https://github.com/markusfisch/zxing-cpp.git" + + +######################################################################################################## +set -e + +CONTRIB_ANDROID="$(dirname "$(readlink -e "$0")")" +CONTRIB="$CONTRIB_ANDROID"/.. +CACHEDIR="$CONTRIB_ANDROID/.cache" +BUILDDIR="$CACHEDIR/builds" + +. "$CONTRIB"/build_tools_util.sh + +# target architecture passed as argument by`make_apk.sh` +TARGET_ARCH="$1" + +# check if TARGET_ARCH is set and supported +if [[ "$TARGET_ARCH" != "armeabi-v7a" \ + && "$TARGET_ARCH" != "arm64-v8a" \ + && "$TARGET_ARCH" != "x86_64" ]]; then + fail "build_barcode_scanner.sh invalid target architecture argument: $TARGET_ARCH" +fi + +info "Building BarcodeScannerView and deps for architecture: $TARGET_ARCH" + +# check if directories exist, create them if not +if [ ! -d "$CACHEDIR/aars" ]; then + mkdir -p "$CACHEDIR/aars" +fi + +if [ ! -d "$BUILDDIR" ]; then + mkdir -p "$BUILDDIR" +fi + + +####### zxing-cpp ######## + +# check if zxing-cpp aar is already in cachedir, else build it +ZXING_CPP_BUILD_ID="$TARGET_ARCH-$ZXING_CPP_COMMIT_HASH" +if [ -f "$CACHEDIR/aars/zxing-cpp-$ZXING_CPP_BUILD_ID.aar" ]; then + info "zxing-cpp for $ZXING_CPP_BUILD_ID already exists in cache, skipping build." + cp "$CACHEDIR/aars/zxing-cpp-$ZXING_CPP_BUILD_ID.aar" "$CACHEDIR/aars/zxing-cpp.aar" +else + info "Building zxing-cpp for $ZXING_CPP_BUILD_ID..." + ZXING_CPP_DIR="$BUILDDIR/zxing-cpp" + clone_or_update_repo "$ZXING_CPP_REPO" "$ZXING_CPP_COMMIT_HASH" "$ZXING_CPP_DIR" + cd "$ZXING_CPP_DIR/wrappers/aar" + chmod +x gradlew + + # Set local.properties to use SDK of docker container + echo "sdk.dir=${ANDROID_SDK_HOME}" > local.properties + # gradlew will install a specific NDK version required by zxing-cpp + ./gradlew :zxingcpp:assembleRelease -Pandroid.injected.build.abi="$TARGET_ARCH" + + # Copy the built AAR to cache directory + ZXING_AAR_SOURCE="$ZXING_CPP_DIR/wrappers/aar/zxingcpp/build/outputs/aar/zxingcpp-release.aar" + ZXING_AAR_DEST_GENERIC="$CACHEDIR/aars/zxing-cpp.aar" + ZXING_AAR_DEST_SPECIFIC="$CACHEDIR/aars/zxing-cpp-$ZXING_CPP_BUILD_ID.aar" + if [ ! -f "$ZXING_AAR_SOURCE" ]; then + fail "zxing-cpp AAR not found at $ZXING_AAR_SOURCE, build failed?" + fi + cp "$ZXING_AAR_SOURCE" "$ZXING_AAR_DEST_GENERIC" + # keeping an arch specific copy allows to skip the build later if it already exists + cp "$ZXING_AAR_SOURCE" "$ZXING_AAR_DEST_SPECIFIC" + info "zxing-cpp AAR copied to $ZXING_AAR_DEST_GENERIC" +fi + +########### CameraView ########### + +CAMERA_VIEW_BUILD_ID="$CAMERA_VIEW_COMMIT_HASH" +if [ -f "$CACHEDIR/aars/CameraView-$CAMERA_VIEW_BUILD_ID.aar" ]; then + info "CameraView AAR already exists in cache, skipping build." + cp "$CACHEDIR/aars/CameraView-$CAMERA_VIEW_BUILD_ID.aar" "$CACHEDIR/aars/CameraView.aar" +else + info "Building CameraView..." + CAMERA_VIEW_DIR="$BUILDDIR/CameraView" + clone_or_update_repo "$CAMERA_VIEW_REPO" "$CAMERA_VIEW_COMMIT_HASH" "$CAMERA_VIEW_DIR" + cd "$CAMERA_VIEW_DIR" + chmod +x gradlew + + echo "sdk.dir=${ANDROID_SDK_HOME}" > local.properties + ./gradlew :cameraview:assembleRelease + + CAMERA_AAR_SOURCE="$CAMERA_VIEW_DIR/cameraview/build/outputs/aar/cameraview-release.aar" + CAMERA_AAR_DEST_GENERIC="$CACHEDIR/aars/CameraView.aar" + CAMERA_AAR_DEST_SPECIFIC="$CACHEDIR/aars/CameraView-$CAMERA_VIEW_BUILD_ID.aar" + if [ ! -f "$CAMERA_AAR_SOURCE" ]; then + fail "CameraView AAR not found at $CAMERA_AAR_SOURCE" + fi + cp "$CAMERA_AAR_SOURCE" "$CAMERA_AAR_DEST_GENERIC" + cp "$CAMERA_AAR_SOURCE" "$CAMERA_AAR_DEST_SPECIFIC" + info "CameraView AAR copied to $CAMERA_AAR_DEST" +fi + +########### BarcodeScannerView ########### + +BARCODE_SCANNER_VIEW_BUILD_ID="$BARCODE_SCANNER_VIEW_COMMIT_HASH" +if [ -f "$CACHEDIR/aars/BarcodeScannerView-$BARCODE_SCANNER_VIEW_BUILD_ID.aar" ]; then + info "BarcodeScannerView AAR already exists in cache, skipping build." + cp "$CACHEDIR/aars/BarcodeScannerView-$BARCODE_SCANNER_VIEW_BUILD_ID.aar" "$CACHEDIR/aars/BarcodeScannerView.aar" +else + info "Building BarcodeScannerView..." + BARCODE_SCANNER_VIEW_DIR="$BUILDDIR/BarcodeScannerView" + clone_or_update_repo "$BARCODE_SCANNER_VIEW_REPO" "$BARCODE_SCANNER_VIEW_COMMIT_HASH" "$BARCODE_SCANNER_VIEW_DIR" + cd "$BARCODE_SCANNER_VIEW_DIR" + chmod +x gradlew + + echo "sdk.dir=${ANDROID_SDK_HOME}" > local.properties + ./gradlew :barcodescannerview:assembleRelease + + BARCODE_AAR_SOURCE="$BARCODE_SCANNER_VIEW_DIR/barcodescannerview/build/outputs/aar/barcodescannerview-release.aar" + BARCODE_AAR_DEST_GENERIC="$CACHEDIR/aars/BarcodeScannerView.aar" + BARCODE_AAR_DEST_SPECIFIC="$CACHEDIR/aars/BarcodeScannerView-$BARCODE_SCANNER_VIEW_BUILD_ID.aar" + if [ ! -f "$BARCODE_AAR_SOURCE" ]; then + fail "BarcodeScannerView AAR not found at $BARCODE_AAR_SOURCE" + fi + cp "$BARCODE_AAR_SOURCE" "$BARCODE_AAR_DEST_GENERIC" + cp "$BARCODE_AAR_SOURCE" "$BARCODE_AAR_DEST_SPECIFIC" + info "BarcodeScannerView AAR copied to $BARCODE_AAR_DEST" +fi + + +info "All barcode scanner libraries built successfully for $TARGET_ARCH" diff --git a/contrib/build_tools_util.sh b/contrib/build_tools_util.sh index cc2a0cb8c..aab00efdd 100755 --- a/contrib/build_tools_util.sh +++ b/contrib/build_tools_util.sh @@ -50,6 +50,28 @@ function download_if_not_exist() { fi } +# Function to clone or update a git repository to a specific commit +clone_or_update_repo() { + local repo_url=$1 + local commit_hash=$2 + local repo_dir=$3 + + if [ -z "$repo_url" ] || [ -z "$commit_hash" ] || [ -z "$repo_dir" ]; then + fail "clone_or_update_repo: invalid arguments: repo_url='$repo_url', commit_hash='$commit_hash', repo_dir='$repo_dir'" + fi + + if [ -d "$repo_dir" ]; then + info "Repository $repo_url exists in $repo_dir, updating..." + git -C "$repo_dir" clean -ffxd >/dev/null 2>&1 || fail "Failed to clean repository $repo_dir" + git -C "$repo_dir" fetch --all >/dev/null 2>&1 || fail "Failed to fetch from repository" + git -C "$repo_dir" reset --hard "$commit_hash^{commit}" >/dev/null 2>&1 || fail "Failed to reset to commit $commit_hash" + else + info "Cloning repository: $repo_url to $repo_dir" + git clone "$repo_url" "$repo_dir" >/dev/null 2>&1 || fail "Failed to clone repository $repo_url" + git -C "$repo_dir" checkout "$commit_hash^{commit}" >/dev/null 2>&1 || fail "Failed to checkout commit $commit_hash" + fi +} + # https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh function retry() { local result=0