Skip to content

firebenders/uber-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uber Android Sample App with Bazel

A sample Uber-like ride-hailing Android application built exclusively with the Bazel build system. Features Google Maps integration, ride type selection, and mock data for demonstration purposes.

Features

  • 🗺️ Google Maps integration with pickup/dropoff markers
  • 🚗 Multiple ride types (UberX, UberXL, Uber Black)
  • 💰 Real-time fare estimation
  • 📍 Location-based services
  • 🎨 Material Design UI with bottom sheet
  • 🔧 Built with Bazel build system (no Gradle!)

Prerequisites

Before building this project, ensure you have the following installed:

1. Bazel

Install Bazel (version 7.0 or higher):

# macOS
brew install bazel

# Or download from https://bazel.build/install

Verify installation:

bazel version

2. Android SDK

Install Android SDK (API level 34 required):

Option A: Using Android Studio (Recommended)

  • Download and install Android Studio
  • Open Android Studio and go to Tools → SDK Manager
  • Install "Android SDK Platform 34" and "Android SDK Build-Tools 34"
  • SDK will be at: ~/Library/Android/sdk (macOS) or ~/Android/Sdk (Linux)

Option B: Using sdkmanager

sdkmanager "platforms;android-34"
sdkmanager "build-tools;34.0.0"

3. Set ANDROID_HOME

Add to your ~/.zshrc or ~/.bash_profile:

export ANDROID_HOME=$HOME/Library/Android/sdk  # macOS
# or
export ANDROID_HOME=$HOME/Android/Sdk  # Linux

export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Then reload your shell:

source ~/.zshrc  # or ~/.bash_profile

4. Google Maps API Key

To enable Google Maps functionality:

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable "Maps SDK for Android"
  4. Create credentials (API Key)
  5. Restrict the key to Android apps
  6. Add your app's package name: com.uber.sample
  7. Get your debug keystore SHA-1:
    keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
  8. Add the SHA-1 to your API key restrictions
  9. Update the API key in app/src/main/res/values/strings.xml:
    <string name="google_maps_key">YOUR_API_KEY_HERE</string>

Note: The app will run without a valid API key, but the map will show a "For development purposes only" watermark.

Building the App with Bazel

1. Build the APK

cd uber-android
bazel build //app:uber_app

The APK will be generated at: bazel-bin/app/uber_app.apk

2. Install to Device/Emulator

Using ADB:

# Connect your Android device or start an emulator
adb devices

# Install the APK
adb install -r bazel-bin/app/uber_app.apk

Using Bazel mobile-install (faster for development):

bazel mobile-install //app:uber_app

3. Clean Build

# Clean build artifacts
bazel clean

# Deep clean (removes all cached data)
bazel clean --expunge

4. Build Specific Targets

# Build just the library
bazel build //app:uber_lib

# Run queries
bazel query //app/...

# Show dependency tree
bazel query --output=graph //app:uber_app > graph.dot

Project Structure

uber-android/
├── WORKSPACE                           # Bazel workspace configuration
├── MODULE.bazel                        # Bazel module definition
├── BUILD.bazel                         # Root build file
├── .bazelrc                            # Bazel configuration
├── app/
│   ├── BUILD.bazel                     # App build configuration
│   ├── AndroidManifest.xml             # Android manifest
│   └── src/main/
│       ├── java/com/uber/sample/
│       │   ├── MainActivity.kt                    # Main activity
│       │   ├── models/
│       │   │   ├── RideType.kt                   # Ride type enum
│       │   │   └── Location.kt                   # Location data class
│       │   ├── ui/
│       │   │   ├── MapFragment.kt                # Google Maps fragment
│       │   │   └── RideBookingBottomSheet.kt     # Bottom sheet UI
│       │   └── data/
│       │       └── MockDataProvider.kt           # Sample data
│       └── res/
│           ├── layout/                           # XML layouts (5 files)
│           ├── values/                           # Strings, colors, themes
│           └── drawable/                         # Vector drawables
└── third_party/
    └── BUILD.bazel                     # Third-party dependencies marker

How Bazel Works for This Project

Workspace Configuration (WORKSPACE)

The WORKSPACE file defines:

  • Android Rules: rules_android v0.5.1 for Android build support
  • Kotlin Rules: rules_kotlin v1.9.6 for Kotlin compilation
  • Maven Dependencies: rules_jvm_external for managing Maven artifacts

Build Configuration (app/BUILD.bazel)

Defines two main targets:

  • android_binary (uber_app): The final APK
  • kt_android_library (uber_lib): Kotlin library with all source code

Dependencies

All dependencies are managed through Maven and defined in WORKSPACE:

  • AndroidX libraries (AppCompat, ConstraintLayout, Fragment, etc.)
  • Material Design Components
  • Google Play Services (Maps, Location)
  • Kotlin standard library

Mock Data

The app includes mock data for demonstration:

Sample Locations

  • Pickup: Market Street, San Francisco, CA (37.7749°N, 122.4194°W)
  • Dropoff: Broadway, Oakland, CA (37.8044°N, 122.2712°W)

Ride Types

Ride Type Price/Mile Capacity ETA
UberX $1.50 4 5min
UberXL $2.25 6 7min
Uber Black $3.50 4 8min

How to Use the App

  1. Launch the app on your Android device or emulator
  2. Grant location permissions when prompted
  3. The map will load with default pickup and dropoff locations
  4. Swipe up on the bottom sheet to see ride options
  5. Tap on a ride type to select it
  6. Tap "Request Ride" to simulate booking

Architecture

Technology Stack

  • Language: Kotlin
  • Build System: Bazel (v9.0)
  • Maps: Google Maps Android API
  • UI Framework: Material Design Components
  • Architecture: Single Activity with Fragments

Key Components

MainActivity.kt (app/src/main/java/com/uber/sample/MainActivity.kt:19)

  • Handles location permissions
  • Coordinates map and bottom sheet

MapFragment.kt (app/src/main/java/com/uber/sample/ui/MapFragment.kt:21)

  • Displays Google Maps
  • Shows pickup/dropoff markers
  • Draws route line

RideBookingBottomSheet.kt (app/src/main/java/com/uber/sample/ui/RideBookingBottomSheet.kt:17)

  • Lists available ride types
  • Handles ride selection
  • Displays fare estimates

MockDataProvider.kt (app/src/main/java/com/uber/sample/data/MockDataProvider.kt:11)

  • Provides sample locations
  • Calculates trip estimates
  • Supplies ride type data

Troubleshooting

Build Errors

Error: Android SDK not found

# Verify ANDROID_HOME is set
echo $ANDROID_HOME

# Should output something like: /Users/your-username/Library/Android/sdk

Error: Could not find SDK version

# List installed SDK versions
ls $ANDROID_HOME/platforms/

# Install required SDK
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager "platforms;android-34"

Error: rules_android not found

# Clean and retry
bazel clean --expunge
bazel build //app:uber_app

Runtime Issues

Map not loading

  • Verify you have a valid Google Maps API key
  • Check that "Maps SDK for Android" is enabled in Google Cloud Console
  • Ensure your package name (com.uber.sample) and SHA-1 are in API key restrictions

Location permission denied

  • Go to device Settings → Apps → Uber Sample → Permissions
  • Enable Location permission

App crashes on startup

  • Check logs: adb logcat | grep AndroidRuntime
  • Ensure you built with: bazel build //app:uber_app

Bazel Issues

Bazel version issues

# Check version
bazel version

# Update Bazel
brew upgrade bazel

Dependency resolution fails

# Clean Maven cache
rm -rf ~/.cache/bazel

# Retry build
bazel build //app:uber_app

Build is slow

# Use disk cache (already configured in .bazelrc)
# Verify it's enabled
bazel info | grep disk_cache

Development Guide

Adding New Features

  1. Add new Kotlin files to app/src/main/java/com/uber/sample/
  2. Add new resources to app/src/main/res/
  3. Files will be automatically included via glob() in BUILD.bazel
  4. Build and test:
    bazel build //app:uber_app
    adb install -r bazel-bin/app/uber_app.apk

Adding New Dependencies

  1. Edit WORKSPACE file and add to maven_install:

    maven_install(
        artifacts = [
            # ... existing dependencies
            "com.example:new-library:1.0.0",
        ],
        # ...
    )
  2. Add to app/BUILD.bazel in the deps list:

    deps = [
        # ... existing deps
        "@maven//:com_example_new_library",
    ]
  3. Clean and rebuild:

    bazel sync --configure
    bazel build //app:uber_app

Viewing Build Graph

# Generate build dependency graph
bazel query --output=graph //app:uber_app > graph.in

# Convert to PNG (requires Graphviz)
dot -Tpng < graph.in > graph.png

Why Bazel?

Advantages

  • Fast Incremental Builds: Only rebuilds what changed
  • Reproducible Builds: Same source → same output, always
  • Scalable: Handles monorepos with thousands of targets
  • Multi-language: Build Java, Kotlin, C++, and more in one system
  • Remote Caching: Share build artifacts across teams
  • Hermetic: Doesn't depend on system-installed tools

Performance

On a typical development machine:

  • Full build: ~45-60 seconds (first time)
  • Incremental build: ~5-10 seconds (after code changes)
  • No-op build: <2 seconds

License

This is a sample application for demonstration purposes.

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors