Skip to content

Instantly share code, notes, and snippets.

@koraysels
Last active August 29, 2024 14:38
Show Gist options
  • Save koraysels/2baf4076e7c25fe827ff009f363cef45 to your computer and use it in GitHub Desktop.
Save koraysels/2baf4076e7c25fe827ff009f363cef45 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Define the SDK directory path as a variable
SDK_DIR="/Users/selsk/Library/Android/sdk"
# Define the subdirectory containing the android project
PROJECT_DIR="/hero"
JAVA_HOME="/Users/selsk/Applications/Android Studio.app/Contents/jbr/Contents/Home"
# Function to search for 'hero' folders 2 directories deep and execute the required commands
search_and_execute() {
for dir in */*/; do
hero_dir="$dir$PROJECT_DIR"
# Check if the 'hero' directory exists
if [ -d "$hero_dir" ]; then
echo "Found 'hero' folder in $hero_dir"
# Navigate to the 'hero' directory
cd "$hero_dir"
# Modify or create the local.properties file with the SDK directory
if [ -f "local.properties" ]; then
echo "sdk.dir=$SDK_DIR" > local.properties
echo "Updated local.properties with new SDK path."
else
echo "sdk.dir=$SDK_DIR" > local.properties
echo "Created local.properties and set SDK path."
fi
# Modify or create the .gradle/config.properties file with the Java home path
if [ -f ".gradle/config.properties" ]; then
echo "java.home=$JAVA_HOME" > .gradle/config.properties
echo "Updated .gradle/config.properties with new Java home path."
else
# Ensure the .gradle directory exists
mkdir -p .gradle
echo "java.home=$JAVA_HOME" > .gradle/config.properties
echo "Created .gradle/config.properties and set Java home path."
fi
# Make gradlew executable and run the assembleDebug task
if [ -f "gradlew" ]; then
chmod +x gradlew
./gradlew assembleDebug
else
echo "No 'gradlew' script found in $hero_dir"
fi
# Navigate back to the initial directory
cd - > /dev/null
fi
done
}
# Execute the function
search_and_execute
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment