DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
21.64k stars 833 forks source link

It looks like the Android tutorial is not working properly. #3249

Open victor138128 opened 1 day ago

victor138128 commented 1 day ago

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:

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:

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.

oparkshinels commented 1 day ago

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

victor138128 commented 1 day ago

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