Repository: DioxusLabs/dioxus

Issue #1158: `unbounded_send` in core scheduler hangs in Android
Created: 2023-07-05T23:05:46Z
Problem
Android is broken for me :(
For whatever reason the unbounded_send method on futures-channel just hangs.
All the dioxus stuff on android works fine, but I can't for the life of me debug why that's happening.
It means we can handle events, but we can't seem to call "needs_update" - or any number of other methods. use_future also just hangs the rendering entirely.
Maybe someone with more android knowledge knows more than me here? Do people ship Rust on Android and not run into this?
Environment:

Dioxus version: [master]
Rust version: [1.70]
OS info: [macOS]
App platform: [android]

Questionnaire


 I'm interested in fixing this myself but don't know where to start
 I would like to fix and I have a solution
 I don't have time to fix this right now, but maybe later

Duplicate issue #1850: Android app freezes on text input
Created: 2024-01-19T22:06:43Z
Problem
App freezes on Android 13 after writing in input field. Same code works as intended on Linux laptop with Wayland and Gnome.
When the app is first started, it runs fine, but soon after I have entered a few letters in the input field, the whole app stops responding to touch events/freezes, even the virtual keyboard locks.
It seem odd as the app is a super basic view with one input field, one button, and one loop listing all previously added values.
Steps To Reproduce
Steps to reproduce the behavior:

Follow the guide on https://dioxuslabs.com/learn/0.4/getting_started/mobile to setup an Android build target.
Use the below lib.rs code
Deploy to a connected Android phone with $ cargo android run

Expected behavior
The app should handle input elements as on every other web page, it should be possible to type in them.
Screenshots
src/lib.rs
use anyhow::Result;
use dioxus::prelude::*;
#[cfg(target_os = "android")]
use wry::android_binding;

#[cfg(target_os = "android")]
fn init_logging() {
    android_logger::init_once(
        android_logger::Config::default()
            .with_min_level(log::Level::Trace)
            .with_tag("dioxus-android-test2"),
    );
}

#[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().unwrap());
}

#[no_mangle]
#[inline(never)]
#[cfg(any(target_os = "android", target_os = "ios"))]
pub extern "C" fn start_app() {
    #[cfg(target_os = "android")]
    android_binding!(com_example, dioxus_android_test2, _start_app);
    #[cfg(target_os = "ios")]
    _start_app()
}

pub fn main() -> Result<()> {
    init_logging();

    dioxus_desktop::launch_cfg(
        app,
        dioxus_desktop::Config::default().with_custom_index(r#"<!DOCTYPE html>
        <html>
          <head>
            <title>Dioxus app</title>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
          </head>
          <body>
            <div id="main"></div>
          </body>
        </html>
       "#.into()),
    );

    Ok(())
}

fn app(cx: Scope) -> Element {
    let items = use_state(cx, Vec::new);
    let number = use_state(cx, || 0.0);

    cx.render(rsx! {
        h1 { "Numbers"}
        form {
            onsubmit: move |_| {
                if number.get() <= &0.0 {
                    return;
                }

                items.modify(|items| {
                    let mut items = items.clone();
                    items.push(*number.get());
                    number.set(0.0);
                    items
                });
            },
            input {
                r#type: "number",
                name: "text",
                value: "{number}",
                oninput: move |ev| {
                    if let Ok(value) = ev.value.parse() {
                        number.set(value);
                    }
                }
            }
            button { r#type: "submit", value: "Save", "Save" }
        }

        for item in items.iter() {
            div { "- {item}" }
        }
    })
}
Cargo.toml
[package]
name = "dioxus-android-test"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["staticlib", "cdylib", "rlib"]

[[bin]]
name = "dioxus-android-test-desktop"
path = "gen/bin/desktop.rs"

[package.metadata.cargo-android]
app-activity-name = "com.example.dioxus_android_test.MainActivity"
app-dependencies = [
    "androidx.webkit:webkit:1.6.1",
    "androidx.appcompat:appcompat:1.6.1",
    "com.google.android.material:material:1.8.0",
]
project-dependencies = ["org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"]
app-plugins = ["org.jetbrains.kotlin.android"]
app-permissions = ["android.permission.INTERNET"]
app-theme-parent = "Theme.MaterialComponents.DayNight.DarkActionBar"
vulkan-validation = false

[package.metadata.cargo-android.env-vars]
WRY_ANDROID_PACKAGE = "com.example.dioxus_android_test"
WRY_ANDROID_LIBRARY = "dioxus_android_test"
WRY_ANDROID_KOTLIN_FILES_OUT_DIR = "<android-project-dir>/app/src/main/kotlin/com/example/dioxus_android_test"

[package.metadata.cargo-apple.ios]
frameworks = ["WebKit"]

[dependencies]
anyhow = "1.0.56"
dioxus = "0.4.3"
dioxus-desktop = "0.4.3"
log = "0.4.11"
wry = "0.28.3"

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13.3"
jni = "0.21.1"
paste = "1.0"

[target.'cfg(not(target_os = "android"))'.dependencies]
env_logger = "0.11.0"

[target.'cfg(target_os = "ios")'.dependencies]
core-foundation = "0.9.3"
Environment:

Dioxus version: 0.4.3
Rust version: 1.75.0
OS info: Android 13, built on Arch Linux with kernel 6.7.0
App platform: mobile

Questionnaire


 I'm interested in fixing this myself but don't know where to start
 I would like to fix and I have a solution
 I don't have time to fix this right now, but maybe later

Closing comment (2024-01-20T14:13:47Z): This looks very similar to #1158. If it is the same issue, you can follow this version of the guide which uses the git version of dioxus to fix it DioxusLabs/docsite#191