Skip to content

Rv607x/DocxGenerator

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ DocX Generator for Android

An Android application that generates Microsoft Word (.docx) documents with text and images using a Rust-powered backend. Built with Jetpack Compose and Rust via JNI.

✨ Features

  • ✍️ Multi-line Text Input - Write your content directly in the app
  • πŸ–ΌοΈ Multiple Image Support - Add multiple images from your gallery
  • πŸ‘οΈ Image Preview - See thumbnail previews of selected images
  • πŸ“ Custom Save Location - Choose where to save your documents
  • πŸš€ Fast Generation - Rust-powered document creation
  • πŸ“‚ Auto-Open - Automatically opens generated documents

πŸ“± Screenshots

Main Interface

  • Editable text field for content input
  • Horizontal image gallery showing selected images
  • Add Image button for gallery selection
  • Generate Document button to create and save .docx files

πŸ› οΈ Tech Stack

Frontend (Android)

  • Kotlin 2.1.0
  • Jetpack Compose 1.7.6 (Modern declarative UI)
  • Material Design Components
  • Coil 2.5.0 (Image loading)
  • Android SDK 35 (Target), 21 (Minimum)

Backend (Document Generation)

  • Rust - Core document generation logic
  • docx-rs 0.2.14 - Word document creation
  • JNI - Java Native Interface bridge
  • rifgen - Rust-to-Java code generation

Build Tools

  • Gradle 8.11.1
  • Android Gradle Plugin 8.7.3
  • Cargo (Rust package manager)
  • Android NDK 29.0.14206865

πŸ“‹ Requirements

Development Requirements

Essential

  • JDK 21 - Java Development Kit 21 or higher
  • Android Studio Hedgehog (2023.1.1) or later
  • Rust 1.70+ with rustup
  • Android NDK 29+ installed via Android Studio SDK Manager
  • Android SDK with API level 35

System Requirements

  • macOS, Linux, or Windows
  • 8GB RAM minimum (16GB recommended)
  • 10GB free disk space

Runtime Requirements (End Users)

  • Android 5.0 (Lollipop - API 21) or higher
  • Storage permission for saving documents
  • Media permission for selecting images

πŸš€ Setup & Installation

1. Clone the Repository

git clone https://github.com/yourusername/DocxGenerator.git
cd DocxGenerator

2. Install Rust & Android Targets

# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Add Android targets
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi

3. Install Java 21

# macOS (using Homebrew)
brew install openjdk@21

# Linux (Ubuntu/Debian)
sudo apt install openjdk-21-jdk

# Windows
# Download from https://adoptium.net/

4. Configure Android SDK & NDK

  1. Open Android Studio β†’ SDK Manager
  2. Under SDK Platforms, install Android 15.0 (API 35)
  3. Under SDK Tools, install:
    • Android SDK Build-Tools 34
    • Android SDK Platform-Tools
    • NDK (Side by side) - version 29+
    • Android SDK Command-line Tools

5. Configure NDK Path

Update docx_lib/.cargo/config.toml with your NDK path:

[target.aarch64-linux-android]
ar = "/path/to/Android/sdk/ndk/29.0.14206865/toolchains/llvm/prebuilt/YOUR-PLATFORM/bin/llvm-ar"
linker = "/path/to/Android/sdk/ndk/29.0.14206865/toolchains/llvm/prebuilt/YOUR-PLATFORM/bin/aarch64-linux-android21-clang"

[target.armv7-linux-androideabi]
ar = "/path/to/Android/sdk/ndk/29.0.14206865/toolchains/llvm/prebuilt/YOUR-PLATFORM/bin/llvm-ar"
linker = "/path/to/Android/sdk/ndk/29.0.14206865/toolchains/llvm/prebuilt/YOUR-PLATFORM/bin/armv7a-linux-androideabi21-clang"

Replace:

  • /path/to/Android/sdk with your Android SDK location
  • YOUR-PLATFORM with darwin-x86_64 (macOS), linux-x86_64 (Linux), or windows-x86_64 (Windows)

6. Create local.properties

echo "sdk.dir=/path/to/Android/sdk" > local.properties

Replace /path/to/Android/sdk with your actual Android SDK path:

  • macOS: ~/Library/Android/sdk
  • Linux: ~/Android/Sdk
  • Windows: C:\\Users\\YourUsername\\AppData\\Local\\Android\\Sdk

πŸ”¨ Building the App

Build Debug APK

# Set Java 21 as active JDK
export JAVA_HOME=/path/to/java-21

# Build using Gradle wrapper
./gradlew assembleDebug

Output location: app/build/outputs/apk/debug/app-debug.apk

Build Release APK

./gradlew assembleRelease

Build from Android Studio

  1. Open the project in Android Studio
  2. File β†’ Project Structure β†’ SDK Location β†’ verify Android SDK and NDK paths
  3. Build β†’ Build Bundle(s) / APK(s) β†’ Build APK(s)

Common Build Issues

Issue: Unsupported class file major version 68

Solution: Ensure you're using Java 21

java -version  # Should show version 21
export JAVA_HOME=/path/to/java-21

Issue: linker 'aarch64-linux-android21-clang' not found

Solution: Install NDK via Android Studio SDK Manager and update .cargo/config.toml

Issue: SDK location not found

Solution: Create local.properties with correct SDK path

πŸ“¦ Installation (End Users)

Install Pre-built APK

  1. Download docx-generator-debug.apk from Releases
  2. Enable Install from Unknown Sources in Settings
  3. Install the APK
  4. Grant required permissions

Permissions Required

  • Storage - To save generated .docx files
  • Media/Photos - To select images from gallery

🎯 Usage

  1. Enter Text - Type your document content in the text field
  2. Add Images - Tap "Add Image" to select from gallery (repeat for multiple images)
  3. Preview - View selected image thumbnails in the horizontal gallery
  4. Generate - Tap "Generate Document"
  5. Choose Location - Select where to save the .docx file
  6. Done! - Document opens automatically

πŸ—οΈ Project Structure

DocxGenerator/
β”œβ”€β”€ app/                          # Android app module
β”‚   β”œβ”€β”€ src/main/
β”‚   β”‚   β”œβ”€β”€ java/.../MainActivity.kt  # Main UI & logic
β”‚   β”‚   β”œβ”€β”€ res/                      # Resources
β”‚   β”‚   └── AndroidManifest.xml
β”‚   └── build.gradle              # App dependencies
β”œβ”€β”€ docx_lib/                     # Rust library
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ lib.rs                # Rust library entry point
β”‚   β”‚   └── docx_glue.rs          # JNI bindings (generated)
β”‚   β”œβ”€β”€ .cargo/config.toml        # Rust Android build config
β”‚   β”œβ”€β”€ Cargo.toml                # Rust dependencies
β”‚   └── build.rs                  # Build script
β”œβ”€β”€ releases/                     # Pre-built APKs
β”‚   └── docx-generator-debug.apk
β”œβ”€β”€ build.gradle                  # Root build config
β”œβ”€β”€ settings.gradle               # Project settings
└── README.md                     # This file

πŸ”§ Architecture

High-Level Flow

User Input (Compose UI)
    ↓
MainActivity (Kotlin)
    ↓
JNI Bridge
    ↓
Rust Library (docx_lib)
    ↓
docx-rs (Document Creation)
    ↓
.docx File Output

Key Components

1. MainActivity.kt

  • Jetpack Compose UI
  • Text input management
  • Image selection handling
  • Document generation coordination

2. AndroidDocBuilder (Rust)

  • new() - Create document builder
  • add_text(text) - Add text paragraph
  • add_image(path, width, height) - Add image
  • generate_docx(path) - Save document

3. JNI Bridge

  • Generated by rifgen and flapigen
  • Provides Kotlin/Java API for Rust functions
  • Handles memory management across language boundary

πŸ§ͺ Testing

Run Tests

# Android instrumented tests
./gradlew connectedAndroidTest

# Unit tests
./gradlew test

# Rust tests
cd docx_lib
cargo test

πŸ› Troubleshooting

Build Issues

Problem: Gradle sync fails

# Solution: Clear caches
./gradlew clean
rm -rf .gradle .idea build app/build

Problem: Rust compilation fails

# Solution: Clean Rust artifacts
cd docx_lib
cargo clean

Problem: NDK not found

# Solution: Check NDK installation
ls $ANDROID_SDK_ROOT/ndk/
# Update .cargo/config.toml with correct path

Runtime Issues

Problem: App crashes on image selection

  • Solution: Grant media permissions in Settings

Problem: Document not saving

  • Solution: Grant storage permissions and ensure valid save location

Problem: Native library not found

  • Solution: Rebuild app to regenerate .so files
./gradlew clean assembleDebug

🚧 Development

Adding New Features

  1. Modify Rust Library (docx_lib/src/lib.rs)
  2. Rebuild to regenerate JNI bindings
  3. Update UI in MainActivity.kt
  4. Test on device/emulator

Code Style

  • Kotlin: Follow Android Kotlin style guide
  • Rust: Run cargo fmt before committing

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“§ Support

For issues and questions:

πŸ™ Acknowledgments

πŸ“Š Project Status

Status: Active Development πŸš€

Version: 1.0.0

Last Updated: October 2025


Made with ❀️ using Kotlin, Rust, and Jetpack Compose

About

A Simple Word document builder using Rust and Android

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 70.6%
  • Rust 17.1%
  • Java 12.3%