#!/bin/bash

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
export ANDROID_HOME=$HOME/Android/Sdk

if [ ! -f "gradle/wrapper/gradle-wrapper.jar" ]; then
    echo "Downloading Gradle Wrapper..."
    wget -q https://services.gradle.org/distributions/gradle-8.4-bin.zip
    unzip -q gradle-8.4-bin.zip
    cp gradle-8.4/lib/plugins/gradle-wrapper-8.4.jar gradle/wrapper/gradle-wrapper.jar
    rm -rf gradle-8.4 gradle-8.4-bin.zip
fi

./gradlew assembleDebug

if [ $? -eq 0 ]; then
    echo ""
    echo "Build successful!"
    echo "APK location: app/build/outputs/apk/debug/app-debug.apk"
else
    echo ""
    echo "Build failed. Please check the error messages above."
fi