From 7190c31b431d882fedc5176961f36821e4cd9635 Mon Sep 17 00:00:00 2001 From: DongHyun Kim Date: Sat, 4 Nov 2023 04:04:43 +0900 Subject: [PATCH 1/2] Disable `reqwest` on Android --- .../example/native/sample_crate/Cargo.toml | 4 +++- .../example/native/sample_crate/src/lib.rs | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/flutter_ffi_plugin/example/native/sample_crate/Cargo.toml b/flutter_ffi_plugin/example/native/sample_crate/Cargo.toml index 24339e21..ce45d317 100755 --- a/flutter_ffi_plugin/example/native/sample_crate/Cargo.toml +++ b/flutter_ffi_plugin/example/native/sample_crate/Cargo.toml @@ -6,8 +6,10 @@ edition = "2021" [target.'cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))'.dependencies] machineid-rs = "1.2.4" +[target.'cfg(not(any(target_os = "android")))'.dependencies] +reqwest = "0.11.22" + [dependencies] num = "0.4" image = "0.24.3" chrono = "0.4.31" -reqwest = "0.11.22" diff --git a/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs b/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs index 50be78b0..645f7d6c 100755 --- a/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs +++ b/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs @@ -35,7 +35,18 @@ pub fn get_current_time() -> DateTime { } // `reqwest` supports all platforms, including web. - +// However, compiling it for Android on Windows can be challenging +// due to its dependency on the `openssl-sys` crate, +// which requires the corresponding C library to be installed on the system. +// Compiling `reqwest` for Android is possible with the right system setup, +// but it's intentionally disabled in our sample crate +// to ensure that the example 'just works'. + +#[cfg(any(target_os = "android"))] +pub async fn fetch_from_web_api(url: &str) -> String { + String::from("API fetching is disabled on this platform.") +} +#[cfg(not(any(target_os = "android")))] pub async fn fetch_from_web_api(url: &str) -> String { reqwest::get(url) .await From e759f539ce7807e57adfdafd513848430d1e1062 Mon Sep 17 00:00:00 2001 From: DongHyun Kim Date: Sat, 4 Nov 2023 04:08:14 +0900 Subject: [PATCH 2/2] Fix a comment sentence --- flutter_ffi_plugin/example/native/sample_crate/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs b/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs index 645f7d6c..e8c98ba6 100755 --- a/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs +++ b/flutter_ffi_plugin/example/native/sample_crate/src/lib.rs @@ -40,7 +40,7 @@ pub fn get_current_time() -> DateTime { // which requires the corresponding C library to be installed on the system. // Compiling `reqwest` for Android is possible with the right system setup, // but it's intentionally disabled in our sample crate -// to ensure that the example 'just works'. +// to ensure that the example app 'just works'. #[cfg(any(target_os = "android"))] pub async fn fetch_from_web_api(url: &str) -> String {