cargo-mobile2

repository·dev·Indexed 23 days ago

https://github.com/tauri-apps/cargo-mobile2

A tool designed to simplify Rust development for iOS and Android by automating the generation of Xcode and Android Studio project files, building, and running on devices. It provides commands such as `cargo apple run` and `cargo android run` to manage mobile project execution and includes template packs for Bevy, Dioxus, egui, wgpu, winit, and wry.

Tokens
5.6K
Snippets
17
Records
48
Agent score
79%

What's inside cargo-mobile2

  1. Run the winit example on desktop and mobile

    dev

    The winit example is a modified version of the standard winit window example. It uses the #[mobile_entry_point] annotation to generate the necessary boilerplate extern functions for mobile platforms and android_logger for logging on Android.

    Desktop

    To run the example on your desktop, use the standard cargo command:

    cargo run

    Mobile

    To run the example on mobile devices, use the following commands:

    • Android: cargo android run (or cargo android open to open the project in Android Studio)
    • iOS/Apple: cargo apple run (or cargo apple open to open the project in Xcode)
    # Desktop
    cargo run
    
    # Android
    cargo android run
    
    # Apple
    cargo apple run
  2. Run and manage mobile projects

    dev

    After initializing a project, use the following commands to run your application on mobile devices or open them in native IDEs:

    Running Applications:

    • cargo apple run: Runs the app on a connected iOS device.
    • cargo android run: Runs the app on a connected Android device.
    • cargo run: Runs the app on your desktop (standard Cargo behavior).

    Opening IDEs:

    • cargo apple open: Opens the project in Xcode.
    • cargo android open: Opens the project in Android Studio.

    Maintenance:

    • cargo mobile update: Updates the cargo-mobile2 installation.
    cargo android run
    cargo apple run
    cargo android open
  3. Install cargo-mobile2

    dev

    Install cargo-mobile2 directly from the GitHub repository using cargo install. This tool is used to manage mobile project generation and execution for iOS and Android.

    Supported Platforms:

    • macOS, Linux, and Windows.
    • Note: Targeting iOS requires macOS. Android can be targeted from any supported platform.

    Prerequisites:

    • Xcode (for iOS support)
    • Android SDK/NDK (for Android support)
    cargo install --git https://github.com/tauri-apps/cargo-mobile2
  4. Run the wgpu-app template on desktop and mobile

    dev

    The wgpu-app template is a wgpu-rs triangle example adapted for mobile platforms.

    To run the application on different platforms, use the following commands:

    • Desktop: Use standard cargo commands.
    • Android: Use cargo android run (or cargo android open to open the project in Android Studio).
    • iOS/Apple: Use cargo apple run (or cargo apple open to open the project in Xcode).
    # Desktop
    cargo run
    
    # Android
    cargo android run
    cargo android open
    
    # Apple
    cargo apple run
    cargo apple open
  5. Initialize a new mobile project

    dev

    To start a new project, create a directory, navigate into it, and run cargo mobile init. You will be prompted to select a template pack to generate the project boilerplate.

    Available Template Packs:

    nameinfo
    bevyMinimal Bevy application rendering a static sprite
    bevy-demoMinimal 2d Bevy application with a controlable sprite and some audio
    dioxusHello world Dioxus example
    eguiFull egui + winit + wgpu example based on agdk-egui example
    wgpuwgpu-rs triangle example
    winitwinit window example
    wryMinimal wry project

    Note: Using the wry template pack provides a project that runs out-of-the-box on desktop and mobile.

  6. Build and run Dioxus apps on iOS simulators and devices

    dev

    Depending on your hardware and target, use the following commands to build and run your Dioxus application on iOS:

    For M1/Apple Silicon users (Simulator)

    If you are using an M1 chip and want to run the app in a simulator, you must target the x86_64 architecture:

    cargo build --target x86_64-apple-ios

    For Physical iOS Devices

    To run the application on an actual iOS device, use the standard cargo apple command:

    cargo apple run
  7. Run wry apps on iOS simulator or device

    dev

    Depending on your hardware and target, use the following commands to run your wry application on iOS:

    Running on iOS Simulator (M1/Apple Silicon users)

    If you are using an M1 Mac and want to target the simulator, you must explicitly build for the x86_64-apple-ios target instead of using the standard cargo apple build command:

    cargo build --target x86_64-apple-ios

    Running on an actual iOS device

    To run the application on a physical iOS device, use the standard command:

    cargo apple run
    cargo build --target x86_64-apple-ios
    # or
    cargo apple run