Merge pull request #202 from breez/savage-android-flutter

Flutter android build
This commit is contained in:
Ross Savage
2024-05-21 13:14:46 +02:00
committed by GitHub
5 changed files with 61 additions and 8 deletions

10
cli/Cargo.lock generated
View File

@@ -179,6 +179,9 @@ name = "anyhow"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3"
dependencies = [
"backtrace",
]
[[package]]
name = "atomic"
@@ -397,6 +400,7 @@ dependencies = [
"boltz-client",
"elements",
"flutter_rust_bridge",
"glob",
"log",
"lwk_common",
"lwk_signer",
@@ -989,6 +993,12 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "h2"
version = "0.3.26"

1
lib/Cargo.lock generated
View File

@@ -504,6 +504,7 @@ dependencies = [
"boltz-client",
"elements",
"flutter_rust_bridge",
"glob",
"log",
"lwk_common",
"lwk_signer",

View File

@@ -19,11 +19,11 @@ rustup target add \
# Build the android libraries in the jniLibs directory
cargo ndk -o $JNI_DIR \
--manifest-path ../../../Cargo.toml \
-t armeabi-v7a \
-t arm64-v8a \
-t x86 \
-t x86_64 \
--manifest-path ../../../core/Cargo.toml \
-t aarch64-linux-android \
-t armv7-linux-androideabi \
-t i686-linux-android \
-t x86_64-linux-android \
build "$@"
# Archive the dynamic libs

View File

@@ -7,6 +7,10 @@ version.workspace = true
name = "breez_liquid_sdk"
crate-type = ["lib", "cdylib", "staticlib"]
[features]
default = ["frb"]
frb = ["dep:flutter_rust_bridge"]
[dependencies]
anyhow = { workspace = true }
bip39 = { version = "2.0.0", features = ["serde"] }
@@ -31,6 +35,6 @@ elements = "0.24.1"
tempdir = "0.3.7"
uuid = { version = "1.8.0", features = ["v4"] }
[features]
default = ["frb"]
frb = ["dep:flutter_rust_bridge"]
[build-dependencies]
anyhow = { version = "1.0.79", features = ["backtrace"] }
glob = "0.3.1"

38
lib/core/build.rs Normal file
View File

@@ -0,0 +1,38 @@
use anyhow::*;
use glob::glob;
use std::env;
use std::result::Result::Ok;
/// Adds a temporary workaround for an issue with the Rust compiler and Android
/// in x86_64 devices: https://github.com/rust-lang/rust/issues/109717.
/// The workaround comes from: https://github.com/smartvaults/smartvaults/blob/827805a989561b78c0ea5b41f2c1c9e9e59545e0/bindings/smartvaults-sdk-ffi/build.rs
fn setup_x86_64_android_workaround() {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
if target_arch == "x86_64" && target_os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME not set");
let build_os = match env::consts::OS {
"linux" => "linux",
"macos" => "darwin",
"windows" => "windows",
_ => panic!(
"Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
),
};
let linux_x86_64_lib_pattern = format!(
"{android_ndk_home}/toolchains/llvm/prebuilt/{build_os}-x86_64/lib*/clang/**/lib/linux/"
);
match glob(&linux_x86_64_lib_pattern).unwrap().last() {
Some(Ok(path)) => {
println!("cargo:rustc-link-search={}", path.to_string_lossy());
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
},
_ => panic!("Path not found: {linux_x86_64_lib_pattern}. Try setting a different ANDROID_NDK_HOME."),
}
}
}
fn main() -> Result<()> {
setup_x86_64_android_workaround();
Ok(())
}