dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

It looks like the Android tutorial is not working properly.

Open victor138128 opened this issue 1 year ago • 2 comments

Problem

I've tried running the mobile example from both the DOC: https://dioxuslabs.com/learn/0.5/reference/mobile. but It looks like the Android Tutorial is not working properly.

Steps To Reproduce

Steps to reproduce the behavior:

  • cargo new dioxus-mobile-test
  • cd dioxus-mobile-test
  • cargo install --git https://github.com/tauri-apps/cargo-mobile2
  • cargo mobile init
  • cargo android open
  • cargo android run

Expected behavior

The Android tutorial works normally and the following mobile screen appears. 스크린샷 2024-11-24 16-42-09

Screenshots The app terminates abnormally with the following error log. 스크린샷 2024-11-24 16-44-05

Environment:

  • Dioxus version: 0.6.0-alpha.4
  • Rust version: 1.81.0
  • OS info: Ubuntu 22.04
  • App platform: android

Questionnaire this is my lib.rs code.

use dioxus::prelude::*;

#[cfg(target_os = "android")]
fn init_logging() {
    android_logger::init_once(
        android_logger::Config::default()
            .with_max_level(log::LevelFilter::Trace)
            .with_tag("dioxus-mobile-test"),
    );
}

#[cfg(not(target_os = "android"))]
fn init_logging() {
    env_logger::init();
}

#[cfg(any(target_os = "android", target_os = "ios"))]
fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T {
    match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
        Ok(t) => t,
        Err(err) => {
            eprintln!("attempt to unwind out of `rust` with err: {:?}", err);
            std::process::abort()
        }
    }
}

#[cfg(any(target_os = "android", target_os = "ios"))]
fn _start_app() {
    stop_unwind(|| main());
}

#[inline(never)]
#[cfg(any(target_os = "android", target_os = "ios"))]
pub extern "C" fn start_app() {
    #[cfg(target_os = "android")]
    {
        tao::android_binding!(
            com_example,
            dioxus_mobile_test,
            WryActivity,
            wry::android_setup, // pass the wry::android_setup function to tao which will invoke when the event loop is created
            _start_app
        );
        wry::android_binding!(com_example, dioxus_mobile_test);
    }

    #[cfg(target_os = "ios")]
    _start_app()
}

pub fn main() {
    init_logging();
    
    dioxus::launch(app);
}

fn app() -> Element {
    let mut items = use_signal(|| vec![1, 2, 3]);

    log::debug!("Hello from the app");

    rsx! {
        div {
            h1 { "Hello, Mobile"}
            div { margin_left: "auto", margin_right: "auto", width: "200px", padding: "10px", border: "1px solid black",
                button {
                    onclick: move|_| {
                        println!("Clicked!");
                        let mut items_mut = items.write();
                        let new_item = items_mut.len() + 1;
                        items_mut.push(new_item);
                        println!("Requested update");
                    },
                    "Add item"
                }
                for item in items.read().iter() {
                    div { "- {item}" }
                }
            }
        }
    }
}

I tried to do it step by step based on the tutorial, and when I ran it through cargo android run, it ended abnormally with the above error log. However, it doesn't seem to be a settings issue, so I'm contacting the issue ticket. Is there anything I can do additionally? If you give me an answer, I will try to fix it if it is something I can fix.

victor138128 avatar Nov 24 '24 07:11 victor138128

Mobile App Development on Windows for Android Platform Using Rust and Dioxus Library https://github.com/DioxusLabs/dioxus/discussions/3234

oparkshinels avatar Nov 24 '24 10:11 oparkshinels

@oparkshinels I'm using Linux not windows. Can I proceed with the tutorial based on Linux as well?

victor138128 avatar Nov 24 '24 10:11 victor138128

We no longer suggest cargo mobile for development and have updated the docs for 0.6 accordingly. dx serve now supports mobile natively for serve, build, and bundle.

jkelleyrtp avatar Jan 07 '25 20:01 jkelleyrtp