fix: pass off env vars to android apps (#3621)
* fix: pass off env vars to android apps * move to jni_onload * fix clippy
This commit is contained in:
1 parent
ce2b223af9
commit
03c2d6711d
7 files changed
+65
-10
No files matched your search
@@ -292,8 +292,8 @@ impl AppHandle {
|
||||
// If the emulator is android, we need to copy the asset to the device with `adb push asset /data/local/tmp/dx/assets/filename.ext`
|
||||
if self.app.build.build.platform() == Platform::Android {
|
||||
if let Some(bundled_name) = bundled_name.as_ref() {
|
||||
let target = format!("/data/local/tmp/dx/{}", bundled_name.display());
|
||||
tracing::debug!("Pushing asset to device: {target}");
|
||||
let target = dioxus_cli_config::android_session_cache_dir().join(bundled_name);
|
||||
tracing::debug!("Pushing asset to device: {target:?}");
|
||||
let res = tokio::process::Command::new(DioxusCrate::android_adb())
|
||||
.arg("push")
|
||||
.arg(&changed_file)
|
||||
@@ -699,6 +699,7 @@ We checked the folder: {}
|
||||
|
||||
async fn open_android_sim(&self, envs: Vec<(&'static str, String)>) {
|
||||
let apk_path = self.app.apk_path();
|
||||
let session_cache = self.app.build.krate.session_cache_dir();
|
||||
let full_mobile_app_name = self.app.build.krate.full_mobile_app_name();
|
||||
|
||||
// Start backgrounded since .open() is called while in the arm of the top-level match
|
||||
@@ -717,6 +718,27 @@ We checked the folder: {}
|
||||
tracing::error!("Failed to install apk with `adb`: {e}");
|
||||
};
|
||||
|
||||
// Write the env vars to a .env file in our session cache
|
||||
let env_file = session_cache.join(".env");
|
||||
let contents: String = envs
|
||||
.iter()
|
||||
.map(|(key, value)| format!("{key}={value}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
_ = std::fs::write(&env_file, contents);
|
||||
|
||||
// Push the env file to the device
|
||||
if let Err(e) = tokio::process::Command::new(DioxusCrate::android_adb())
|
||||
.arg("push")
|
||||
.arg(env_file)
|
||||
.arg(dioxus_cli_config::android_session_cache_dir().join(".env"))
|
||||
.output()
|
||||
.await
|
||||
.context("Failed to push asset to device")
|
||||
{
|
||||
tracing::error!("Failed to push .env file to device: {e}");
|
||||
}
|
||||
|
||||
// eventually, use the user's MainAcitivty, not our MainAcitivty
|
||||
// adb shell am start -n dev.dioxus.main/dev.dioxus.main.MainActivity
|
||||
let activity_name = format!("{}/dev.dioxus.main.MainActivity", full_mobile_app_name,);
|
||||
@@ -727,7 +749,6 @@ We checked the folder: {}
|
||||
.arg("start")
|
||||
.arg("-n")
|
||||
.arg(activity_name)
|
||||
.envs(envs)
|
||||
.stderr(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.output()
|
||||
|
||||
@@ -355,6 +355,9 @@ impl WebServer {
|
||||
pub fn displayed_address(&self) -> Option<SocketAddr> {
|
||||
let mut address = self.server_address()?;
|
||||
|
||||
// Set the port to the devserver port since that's usually what people expect
|
||||
address.set_port(self.devserver_port);
|
||||
|
||||
if self.devserver_bind_ip == IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)) {
|
||||
address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), address.port());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user