Allow specifying min_sdk_version in dioxus config for Android. (#4549)

* allow specifying min_sdk_version inside dioxus config

* rustfmt
This commit is contained in:
Rhaskia authored and GitHub committed 2025-08-14 20:05:26 -07:00
1 parent 593945ecce
commit 2a0f328c42
4 files changed
+29 -16

No files matched your search

+21 -4
View File
@@ -733,7 +733,12 @@ impl BuildRequest {
// If no custom linker is set, then android falls back to us as the linker // If no custom linker is set, then android falls back to us as the linker
if custom_linker.is_none() && bundle == BundleFormat::Android { if custom_linker.is_none() && bundle == BundleFormat::Android {
custom_linker = Some(workspace.android_tools()?.android_cc(&triple)); let min_sdk_version = config.application.android_min_sdk_version.unwrap_or(24);
custom_linker = Some(
workspace
.android_tools()?
.android_cc(&triple, min_sdk_version),
);
} }
let target_dir = std::env::var("CARGO_TARGET_DIR") let target_dir = std::env::var("CARGO_TARGET_DIR")
@@ -2568,9 +2573,10 @@ impl BuildRequest {
let mut env_vars: Vec<(Cow<'static, str>, String)> = vec![]; let mut env_vars: Vec<(Cow<'static, str>, String)> = vec![];
let min_sdk_version = self.min_sdk_version_or_default();
let tools = self.workspace.android_tools()?; let tools = self.workspace.android_tools()?;
let linker = tools.android_cc(&self.triple); let linker = tools.android_cc(&self.triple, min_sdk_version);
let min_sdk_version = tools.min_sdk_version();
let ar_path = tools.ar_path(); let ar_path = tools.ar_path();
let target_cc = tools.target_cc(); let target_cc = tools.target_cc();
let target_cxx = tools.target_cxx(); let target_cxx = tools.target_cxx();
@@ -4274,7 +4280,10 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
/// will do its best to fill in the missing bits by exploring the sdk structure /// will do its best to fill in the missing bits by exploring the sdk structure
/// IE will attempt to use the Java installed from android studio if possible. /// IE will attempt to use the Java installed from android studio if possible.
async fn verify_android_tooling(&self) -> Result<()> { async fn verify_android_tooling(&self) -> Result<()> {
let linker = self.workspace.android_tools()?.android_cc(&self.triple); let linker = self
.workspace
.android_tools()?
.android_cc(&self.triple, self.min_sdk_version_or_default());
tracing::debug!("Verifying android linker: {linker:?}"); tracing::debug!("Verifying android linker: {linker:?}");
@@ -4564,6 +4573,14 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
.into() .into()
} }
/// Returns the min sdk version set in config. If not set 24 is returned as a default.
pub(crate) fn min_sdk_version_or_default(&self) -> u32 {
self.config
.application
.android_min_sdk_version
.unwrap_or(24)
}
pub(crate) async fn start_simulators(&self) -> Result<()> { pub(crate) async fn start_simulators(&self) -> Result<()> {
if self.device { if self.device {
return Ok(()); return Ok(());
+3 -12
View File
@@ -157,19 +157,15 @@ impl AndroidTools {
/// "~/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/ld" /// "~/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/bin/ld"
/// ///
/// However, for our purposes, we only go through the cc driver and not the linker directly. /// However, for our purposes, we only go through the cc driver and not the linker directly.
pub(crate) fn android_cc(&self, triple: &Triple) -> PathBuf { pub(crate) fn android_cc(&self, triple: &Triple, sdk_version: u32) -> PathBuf {
let suffix = if cfg!(target_os = "windows") { let suffix = if cfg!(target_os = "windows") {
".cmd" ".cmd"
} else { } else {
"" ""
}; };
self.android_tools_dir().join(format!( self.android_tools_dir()
"{}{}-clang{}", .join(format!("{}{}-clang{}", triple, sdk_version, suffix))
triple,
self.min_sdk_version(),
suffix
))
} }
pub(crate) fn sysroot(&self) -> PathBuf { pub(crate) fn sysroot(&self) -> PathBuf {
@@ -191,11 +187,6 @@ impl AndroidTools {
self.sdk().join("emulator").join("emulator") self.sdk().join("emulator").join("emulator")
} }
// todo(jon): this should be configurable
pub(crate) fn min_sdk_version(&self) -> u32 {
24
}
pub(crate) fn clang_folder(&self) -> PathBuf { pub(crate) fn clang_folder(&self) -> PathBuf {
// The clang folder is usually located in the NDK under: // The clang folder is usually located in the NDK under:
// "~/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/lib/clang/<version>" // "~/Library/Android/sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/darwin-x86_64/lib/clang/<version>"
+4
View File
@@ -38,4 +38,8 @@ pub(crate) struct ApplicationConfig {
/// Use this file for the MainActivity.kt associated with the Android app. /// Use this file for the MainActivity.kt associated with the Android app.
#[serde(default)] #[serde(default)]
pub(crate) android_main_activity: Option<PathBuf>, pub(crate) android_main_activity: Option<PathBuf>,
/// Specified minimum sdk version for gradle to build the app with.
#[serde(default)]
pub(crate) android_min_sdk_version: Option<u32>,
} }
+1
View File
@@ -22,6 +22,7 @@ impl Default for DioxusConfig {
ios_info_plist: None, ios_info_plist: None,
android_manifest: None, android_manifest: None,
android_main_activity: None, android_main_activity: None,
android_min_sdk_version: None,
macos_info_plist: None, macos_info_plist: None,
ios_entitlements: None, ios_entitlements: None,
macos_entitlements: None, macos_entitlements: None,