ANDRO icon indicating copy to clipboard operation
ANDRO copied to clipboard

Create Automated Cleanup and Build Scripts

Open AryanVBW opened this issue 6 months ago • 0 comments

Description

The current APK building process lacks automated scripts for cleaning up and properly rebuilding APKs, making the process error-prone and difficult to maintain.

Current Behavior

  • Manual cleanup of decompiled files is required before building
  • No automated handling of common errors and fixes
  • No systematic approach to the build, signing, and verification process

Expected Behavior

  • Automated scripts for cleaning decompiled files
  • Consistent build and signing process
  • Better error detection and recovery

Proposed Solution

Create two new scripts:

1. clean-decompiled.sh

#!/bin/bash

# Script to clean up and fix common issues in decompiled APK files
DECOMPILED_DIR="$1"

if [ -z "$DECOMPILED_DIR" ]; then
    echo "Usage: $0 <decompiled-directory>"
    exit 1
fi

echo "Cleaning up decompiled directory: $DECOMPILED_DIR"

# Remove files with problematic names
find "$DECOMPILED_DIR" -name "# *" -type f -delete
find "$DECOMPILED_DIR" -name "* *" -type f | while read file; do
    new_name=$(echo "$file" | sed 's/ /_/g')
    echo "Renaming $file to $new_name"
    mv "$file" "$new_name"
done

# Fix common syntax issues in smali files
MAIN_ACTIVITY_PATH="$DECOMPILED_DIR/smali/com/etechd/l3mon/MainActivity.smali"
if [ -f "$MAIN_ACTIVITY_PATH" ]; then
    echo "Fixing MainActivity.smali file"
    sed -i '' 's/```//g' "$MAIN_ACTIVITY_PATH"
    sed -i '' "s/\`/'/g" "$MAIN_ACTIVITY_PATH"
fi

echo "Cleanup complete"

2. rebuild-apk.sh

#!/bin/bash

# Script to safely rebuild an APK from decompiled sources
BASE_DIR="$(dirname "$(cd "$(dirname "$0")" && pwd)")"
DECOMPILED_DIR="$BASE_DIR/app/factory/decompiled"
OUTPUT_APK="$BASE_DIR/assets/webpublic/build.apk"
APKTOOL_JAR="$BASE_DIR/app/factory/apktool.jar"
SIGN_JAR="$BASE_DIR/app/factory/sign.jar"
TESTKEY_PK8="$BASE_DIR/app/factory/testkey.pk8"
TESTKEY_X509="$BASE_DIR/app/factory/testkey.x509.pem"

echo "Starting APK rebuild process..."

# Clean up decompiled directory
echo "Cleaning up decompiled directory..."
bash "$BASE_DIR/scripts/clean-decompiled.sh" "$DECOMPILED_DIR"

# Backup apktool.yml to restore later if needed
cp "$DECOMPILED_DIR/apktool.yml" "$DECOMPILED_DIR/apktool.yml.backup"

# Build the APK
echo "Building APK..."
java -jar "$APKTOOL_JAR" b "$DECOMPILED_DIR" -o "$OUTPUT_APK" -f

# Check if build was successful
if [ $? -ne 0 ]; then
    echo "Build failed. Trying again with --use-aapt2 option..."
    java -jar "$APKTOOL_JAR" b "$DECOMPILED_DIR" -o "$OUTPUT_APK" -f --use-aapt2
    
    if [ $? -ne 0 ]; then
        echo "Build failed again. Exiting."
        exit 1
    fi
fi

# Sign the APK
echo "Signing APK..."
java -jar "$SIGN_JAR" "$OUTPUT_APK" "$TESTKEY_PK8" "$TESTKEY_X509"

echo "APK rebuild complete: $OUTPUT_APK"

Additional Context

These scripts should be made executable (chmod +x) and integrated into the APK building process to improve reliability.


Issue 7: Improve Build Error Reporting in Web Interface

Description

Currently, when an APK build fails, the error messages displayed in the web interface are too technical and not user-friendly. Users often see raw error outputs that are difficult to understand and don't provide clear guidance on how to resolve the issue.

Current Behavior

Error messages like the following are shown directly to users:

brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [...]
W: Unknown file type, ignoring: [...]/# Code Citations.md
Error for input '`': Invalid text

Expected Behavior

  1. User-friendly error messages that explain the problem in simple terms
  2. Categorized errors (e.g., "Resource error", "File format error", "Permissions error")
  3. Suggested solutions for common errors
  4. Detailed technical logs available for developers but not shown by default to users

Proposed Solution

Create an error handling middleware that intercepts build errors, categorizes them, and displays user-friendly messages:

// Error categorization and user-friendly messages
function formatBuildError(error) {
  if (error.includes('Error for input')) {
    return {
      type: 'Syntax Error',
      message: 'The app code contains invalid characters that need to be fixed.',
      suggestion: 'Try rebuilding after the system automatically fixes these issues.',
      technical: error
    };
  } else if (error.includes('Unknown file type')) {
    return {
      type: 'File Error',
      message: 'Some files in the project have names that are causing problems.',
      suggestion: 'The system will try to automatically rename these files.',
      technical: error
    };
  } else if (error.includes('No resource found')) {
    return {
      type: 'Resource Error',
      message: 'The app is missing some required design elements.',
      suggestion: 'The system will try to provide alternative design elements.',
      technical: error
    };
  }
  
  // Default case
  return {
    type: 'Build Error',
    message: 'There was a problem building your app.',
    suggestion: 'Please try again or contact support.',
    technical: error
  };
}

Then update the UI to show these user-friendly messages with an option to view technical details.

Additional Context

Making error messages more user-friendly will improve the overall user experience and reduce confusion when builds fail.

AryanVBW avatar Apr 06 '25 03:04 AryanVBW