Skip to content

shauryag2002/generate-apk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ generate-apk

npm version License: MIT Node.js

A powerful and user-friendly Node.js CLI tool to convert Android App Bundles (AAB) to APKs using Google's BundleTool, with interactive prompts and automatic keystore management.

✨ Features

  • πŸš€ Two modes: Interactive and automated build mode
  • πŸ“₯ Automatic BundleTool download - no manual setup required
  • πŸ” Automatic keystore creation - generates signed APKs ready for distribution
  • 🎯 Smart AAB detection - finds .aab files automatically
  • πŸ“‹ Interactive prompts with sensible defaults
  • πŸ›‘οΈ Universal APK generation compatible with all devices
  • 🎨 Beautiful CLI interface with emojis and clear feedback
  • ⚑ Cross-platform support (Windows, macOS, Linux)
  • πŸ“ Organized output - uses dedicated build folder on desktop
  • πŸ”§ CI/CD friendly - scriptable build mode

πŸ“¦ Installation

Global Installation (Recommended)

npm install -g generate-apk

Local Installation

npm install generate-apk
npx generate-apk

πŸš€ Quick Start

Interactive Mode

Navigate to a directory containing your .aab file and run:

generate-apk

What it does:

  1. πŸ“₯ Downloads BundleTool automatically (if not present)
  2. πŸ” Detects .aab files in your directory
  3. πŸ” Prompts for keystore details or creates one automatically
  4. βš™οΈ Generates signed APK with your specified name

Build Mode (Automated)

For automated workflows and CI/CD:

generate-apk build <file.aab> --name=<output.apk>

What it does:

  1. πŸ“ Uses/creates build folder on desktop
  2. πŸ”‘ Creates keystore automatically (no prompts)
  3. βš™οΈ Generates signed APK with default settings
  4. πŸ“± Ready for distribution

πŸ› οΈ Usage Examples

Interactive Mode Examples

# Basic usage - finds .aab files automatically
generate-apk

# Direct file specification
generate-apk app-release.aab

Interactive workflow:

$ generate-apk
βœ… Found bundletool-all-1.18.1.jar
βš™οΈ  Only one .aab found, using app-release.aab

πŸ” Signing setup (press Enter for defaults or "skip" for unsigned)
Keystore path [chatreal-release.keystore] or "skip":
πŸ“‹ Keystore not found. Create new keystore? (Y/n): y
πŸ”‘ Creating keystore...
βœ… Keystore created: chatreal-release.keystore

πŸ”§ Building signed APKS from app-release.aab…
πŸ“¦ Extracting universal.apk…
Enter final APK name [app-release-signed.apk]: MyApp-v1.2.3.apk

βœ… APK ready: MyApp-v1.2.3.apk

Build Mode Examples

# Basic build command
generate-apk build app-release.aab --name=myapp.apk

# Multiple APKs (all go to same build folder)
generate-apk build app-release.aab --name=release.apk
generate-apk build app-debug.aab --name=debug.apk

Build mode workflow:

$ generate-apk build app-release.aab --name=myapp.apk

πŸ“ Using existing build directory: /home/user/Desktop/build
βœ… Found bundletool-all-1.18.1.jar
βœ… Found keystore: release.keystore
πŸ”§ Building signed APKS from app-release.aab...
πŸ“¦ Extracting universal.apk...

βœ… APK conversion completed!
πŸ“± APK file: myapp.apk (signed)
πŸ“ Location: /home/user/Desktop/build
πŸ” Signed with keystore: release.keystore

πŸ’‘ Your signed APK is ready for distribution and installation!

βš™οΈ Command Reference

Interactive Mode

generate-apk                    # Auto-detect AAB files
generate-apk <file.aab>         # Specify AAB file
generate-apk --help             # Show help

Build Mode

generate-apk build <file.aab> --name=<output.apk>

Build mode features:

  • βœ… Uses existing build folder on desktop (creates if needed)
  • βœ… No interactive prompts - uses defaults
  • βœ… Automatically creates and reuses keystore
  • βœ… Generates signed APKs ready for distribution
  • βœ… Perfect for automation and CI/CD

πŸ” Keystore Management

Interactive Mode

  • Prompts for keystore path, alias, and passwords
  • Can create new keystores with custom details
  • Supports existing keystores
  • Option to skip signing (unsigned APK)

Build Mode

  • Automatically creates release.keystore in build folder
  • Uses secure defaults: RSA 2048-bit, 10,000-day validity
  • Reuses existing keystore for subsequent builds
  • Fallback to unsigned APK if keystore creation fails

Default keystore settings:

  • File: release.keystore
  • Alias: release
  • Store password: 123456
  • Key password: 123456

Note: For production apps, consider using custom keystores with stronger passwords.

πŸ“ Project Structure

generate-apk/
β”œβ”€β”€ bin/
β”‚   └── generate-apk.js          # πŸš€ CLI entry point with command routing
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ index.js                 # πŸ› οΈ Interactive mode logic
β”‚   β”œβ”€β”€ build.js                 # πŸ—οΈ Build mode logic
β”‚   └── utils.js                 # πŸ”§ Cross-platform utilities
β”œβ”€β”€ package.json                 # πŸ“‹ Package configuration
└── README.md                   # πŸ“– Documentation

πŸ“‹ Output Structure

Interactive Mode

Creates files in current directory:

your-project/
β”œβ”€β”€ app-release.aab              # Your input file
β”œβ”€β”€ MyApp-v1.2.3.apk            # Generated APK
β”œβ”€β”€ bundletool-all-1.18.1.jar   # Downloaded tool
└── chatreal-release.keystore    # Created keystore

Build Mode

Creates organized build folder on desktop:

~/Desktop/build/
β”œβ”€β”€ bundletool-all-1.18.1.jar   # Downloaded once, reused
β”œβ”€β”€ release.keystore             # Auto-generated keystore
β”œβ”€β”€ myapp.apk                    # Your signed APKs
β”œβ”€β”€ release.apk                  # Multiple APKs supported
└── debug.apk                    # All in one place

πŸ”§ Prerequisites

  • Node.js 12.0.0 or higher
  • Java Runtime Environment (JRE) 8+ for BundleTool and keystore operations
  • Android App Bundle (.aab) file

Installing Java (if needed)

Ubuntu/Debian:

sudo apt update && sudo apt install openjdk-11-jdk

macOS:

brew install openjdk@11

Windows: Download from Oracle or use OpenJDK

🎯 Advanced Usage

React Native Integration

# Build your React Native app
cd android && ./gradlew bundleRelease

# Convert to APK
cd app/build/outputs/bundle/release
generate-apk build app-release.aab --name=MyApp-v1.0.0.apk

CI/CD Integration

# GitHub Actions example
- name: Convert AAB to APK
  run: |
    npm install -g generate-apk
    generate-apk build app/build/outputs/bundle/release/app-release.aab --name=release.apk

Package.json Scripts

{
  "scripts": {
    "build-apk": "generate-apk build android/app/build/outputs/bundle/release/app-release.aab --name=myapp.apk",
    "build-apk-interactive": "generate-apk"
  }
}

πŸ› Troubleshooting

Common Issues

"No .aab files found"

  • Ensure you're in the correct directory
  • Check that your file has the .aab extension
  • Use direct file path: generate-apk my-app.aab

"java: command not found"

  • Install Java JDK/JRE 8 or higher
  • Ensure java and keytool are in your system PATH
  • Test with: java -version and keytool -help

"keytool: command not found"

  • Install Java JDK (not just JRE)
  • On some systems: sudo apt install openjdk-11-jdk

Permission denied (Linux/macOS)

  • Run: chmod +x ./bin/generate-apk.js
  • Or install globally: npm install -g generate-apk

PowerShell errors (Windows)

  • Ensure PowerShell execution policy allows scripts
  • Run PowerShell as administrator if needed

Debug Information

The tool provides detailed feedback at each step:

  • βœ… Success indicators
  • πŸ“₯ Download progress
  • πŸ”§ Build process status
  • ⚠️ Warning messages
  • ❌ Clear error descriptions

πŸ”„ Version History

  • v1.1.0: Added build mode, cross-platform unzip, automatic keystore creation
  • v1.0.0: Initial release with interactive mode

πŸ™ Acknowledgments

  • Google BundleTool - The official tool for Android App Bundle operations
  • Android Developer Community - For feedback and feature requests
  • Node.js Community - For the excellent ecosystem

πŸ“ž Support


⭐ If this tool helped you, please give it a star on GitHub! ⭐

Made with ❀️ by Shaurya Gupta

About

CLI tool to convert .aab to .apk via BundleTool, with prompts and signing.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors