Skip to content

Commit

Permalink
Merge pull request #207 from cunarist/disable-reqwest-on-android
Browse files Browse the repository at this point in the history
Disable `reqwest` on Android
  • Loading branch information
temeddix authored Nov 3, 2023
2 parents 7b7376a + e759f53 commit 6190b91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion flutter_ffi_plugin/example/native/sample_crate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
13 changes: 12 additions & 1 deletion flutter_ffi_plugin/example/native/sample_crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ pub fn get_current_time() -> DateTime<offset::Local> {
}

// `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 app '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
Expand Down

0 comments on commit 6190b91

Please sign in to comment.