Skip to content

fix(cli, breaking): Align Android applicationId with user's bundle.identifier #4103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/build/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ We checked the folder: {}
) -> Result<()> {
let apk_path = self.build.debug_apk_path();
let session_cache = self.build.session_cache_dir();
let full_mobile_app_name = self.build.full_mobile_app_name();
let application_id = self.build.bundle_identifier();
let adb = self.build.workspace.android_tools()?.adb.clone();

// Start backgrounded since .open() is called while in the arm of the top-level match
Expand Down Expand Up @@ -1194,7 +1194,7 @@ We checked the folder: {}

// eventually, use the user's MainActivity, not our MainActivity
// adb shell am start -n dev.dioxus.main/dev.dioxus.main.MainActivity
let activity_name = format!("{}/dev.dioxus.main.MainActivity", full_mobile_app_name,);
let activity_name = format!("{}/dev.dioxus.main.MainActivity", application_id,);

if let Err(e) = Command::new(&adb)
.arg("shell")
Expand Down
34 changes: 15 additions & 19 deletions packages/cli/src/build/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ session_cache_dir: {}"#,
android_bundle: Option<crate::AndroidSettings>,
}
let hbs_data = AndroidHandlebarsObjects {
application_id: self.full_mobile_app_name(),
application_id: self.bundle_identifier(),
app_name: self.bundled_app_name(),
android_bundle: self.config.bundle.android.clone(),
};
Expand Down Expand Up @@ -2731,30 +2731,26 @@ session_cache_dir: {}"#,
kept_features
}

pub(crate) fn mobile_org(&self) -> String {
let identifier = self.bundle_identifier();
let mut split = identifier.splitn(3, '.');
let sub = split
.next()
.expect("Identifier to have at least 3 periods like `com.example.app`");
let tld = split
.next()
.expect("Identifier to have at least 3 periods like `com.example.app`");
format!("{}.{}", sub, tld)
}

pub(crate) fn bundled_app_name(&self) -> String {
use convert_case::{Case, Casing};
self.executable_name().to_case(Case::Pascal)
}

pub(crate) fn full_mobile_app_name(&self) -> String {
format!("{}.{}", self.mobile_org(), self.bundled_app_name())
}

pub(crate) fn bundle_identifier(&self) -> String {
if let Some(identifier) = self.config.bundle.identifier.clone() {
return identifier.clone();
if let Some(identifier) = &self.config.bundle.identifier {
if identifier.contains('.')
&& !identifier.starts_with('.')
&& !identifier.ends_with('.')
&& !identifier.contains("..")
{
return identifier.clone();
} else {
// The original `mobile_org` function used `expect` directly.
// Maybe it's acceptable for the CLI to panic directly when this error occurs.
// And if we change it to a Result type, the `client_connected` function in serve/runner.rs does not return a Result and cannot call `?`,
// We also need to handle the error in place, otherwise it will expand the scope of modifications further.
panic!("Invalid bundle identifier: {identifier:?}. E.g. `com.example`, `com.example.app`");
}
}

format!("com.example.{}", self.bundled_app_name())
Expand Down
Loading