Skip to content

Commit caf6814

Browse files
committed
It builds and run
1 parent 0d18334 commit caf6814

File tree

3 files changed

+181
-115
lines changed

3 files changed

+181
-115
lines changed

packages/cli/src/build/request.rs

Lines changed: 103 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ impl BuildRequest {
25752575
// Get the project directory for ejected assets
25762576
let project_dir = self.workspace.workspace_root();
25772577
let ejected_android_dir = project_dir.join("android");
2578-
2578+
25792579
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Project directory: {}", project_dir.display());
25802580
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Checking for ejected Android assets at: {}", ejected_android_dir.display());
25812581

@@ -2624,9 +2624,12 @@ impl BuildRequest {
26242624
let hbs = handlebars::Handlebars::new();
26252625

26262626
// Helper function to check for ejected file and use it if it exists
2627-
let copy_ejected_or_use_template = |rel_path: &str, dest_path: &std::path::Path, template_content: &[u8]| -> Result<()> {
2627+
let copy_ejected_or_use_template = |rel_path: &str,
2628+
dest_path: &std::path::Path,
2629+
template_content: &[u8]|
2630+
-> Result<()> {
26282631
let ejected_path = ejected_android_dir.join(rel_path);
2629-
2632+
26302633
if ejected_path.exists() {
26312634
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using ejected Android asset: {}", ejected_path.display());
26322635
std::fs::copy(&ejected_path, dest_path)?;
@@ -2636,22 +2639,23 @@ impl BuildRequest {
26362639
}
26372640
Ok(())
26382641
};
2639-
2642+
26402643
// Helper function for handlebars templates
2641-
let render_ejected_or_use_template = |rel_path: &str, dest_path: &std::path::Path, template_path: &str| -> Result<()> {
2644+
let render_ejected_or_use_template = |rel_path: &str,
2645+
dest_path: &std::path::Path,
2646+
template_path: &str|
2647+
-> Result<()> {
26422648
let ejected_path = ejected_android_dir.join(rel_path);
2643-
2649+
26442650
if ejected_path.exists() {
26452651
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using ejected Android asset: {}", ejected_path.display());
2646-
let content = std::fs::read_to_string(&ejected_path)
2647-
.with_context(|| format!("Failed to read ejected file: {}", ejected_path.display()))?;
2652+
let content = std::fs::read_to_string(&ejected_path).with_context(|| {
2653+
format!("Failed to read ejected file: {}", ejected_path.display())
2654+
})?;
26482655
write(dest_path, content)?;
26492656
} else {
26502657
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using internal Android asset template for: {}", rel_path);
2651-
write(
2652-
dest_path,
2653-
hbs.render_template(template_path, &hbs_data)?,
2654-
)?;
2658+
write(dest_path, hbs.render_template(template_path, &hbs_data)?)?;
26552659
}
26562660
Ok(())
26572661
};
@@ -2662,25 +2666,25 @@ impl BuildRequest {
26622666
&root.join("build.gradle.kts"),
26632667
include_bytes!("../../assets/android/gen/build.gradle.kts"),
26642668
)?;
2665-
2669+
26662670
copy_ejected_or_use_template(
26672671
"gen/gradle.properties",
26682672
&root.join("gradle.properties"),
26692673
include_bytes!("../../assets/android/gen/gradle.properties"),
26702674
)?;
2671-
2675+
26722676
copy_ejected_or_use_template(
26732677
"gen/gradlew",
26742678
&root.join("gradlew"),
26752679
include_bytes!("../../assets/android/gen/gradlew"),
26762680
)?;
2677-
2681+
26782682
copy_ejected_or_use_template(
26792683
"gen/gradlew.bat",
26802684
&root.join("gradlew.bat"),
26812685
include_bytes!("../../assets/android/gen/gradlew.bat"),
26822686
)?;
2683-
2687+
26842688
copy_ejected_or_use_template(
26852689
"gen/settings.gradle",
26862690
&root.join("settings.gradle"),
@@ -2693,7 +2697,7 @@ impl BuildRequest {
26932697
&wrapper.join("gradle-wrapper.properties"),
26942698
include_bytes!("../../assets/android/gen/gradle/wrapper/gradle-wrapper.properties"),
26952699
)?;
2696-
2700+
26972701
copy_ejected_or_use_template(
26982702
"gen/gradle/wrapper/gradle-wrapper.jar",
26992703
&wrapper.join("gradle-wrapper.jar"),
@@ -2706,95 +2710,67 @@ impl BuildRequest {
27062710
&app.join("build.gradle.kts"),
27072711
include_str!("../../assets/android/gen/app/build.gradle.kts.hbs"),
27082712
)?;
2709-
2713+
27102714
copy_ejected_or_use_template(
27112715
"gen/app/proguard-rules.pro",
27122716
&app.join("proguard-rules.pro"),
27132717
include_bytes!("../../assets/android/gen/app/proguard-rules.pro"),
27142718
)?;
27152719

2716-
// Handle AndroidManifest.xml
2720+
// Handle AndroidManifest.xml with special case for config-specified manifest
27172721
let manifest_dest = app.join("src").join("main").join("AndroidManifest.xml");
27182722
let ejected_manifest = ejected_android_dir.join("gen/app/src/main/AndroidManifest.xml");
2719-
2720-
let manifest_xml = if ejected_manifest.exists() {
2723+
2724+
if ejected_manifest.exists() {
27212725
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using ejected AndroidManifest.xml: {}", ejected_manifest.display());
2722-
std::fs::read_to_string(&ejected_manifest)
2723-
.with_context(|| format!("Failed to read ejected AndroidManifest.xml: {}", ejected_manifest.display()))?
2726+
let _ = std::fs::copy(&ejected_manifest, &manifest_dest)?;
27242727
} else if let Some(manifest) = self.config.application.android_manifest.as_deref() {
27252728
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using custom AndroidManifest.xml from config");
2726-
std::fs::read_to_string(self.package_manifest_dir().join(manifest))
2727-
.context("Failed to locate custom AndroidManifest.xml")?
2729+
let custom_manifest =
2730+
std::fs::read_to_string(self.package_manifest_dir().join(manifest))
2731+
.context("Failed to locate custom AndroidManifest.xml")?;
2732+
write(&manifest_dest, custom_manifest)?;
27282733
} else {
27292734
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using internal AndroidManifest.xml template");
2730-
hbs.render_template(
2731-
include_str!("../../assets/android/gen/app/src/main/AndroidManifest.xml.hbs"),
2732-
&hbs_data,
2733-
)?
2734-
};
2735-
2736-
write(&manifest_dest, manifest_xml)?;
2737-
2738-
// Write the main activity
2739-
let main_activity_dest = self.wry_android_kotlin_files_out_dir().join("MainActivity.kt");
2740-
let ejected_main_activity = ejected_android_dir.join("MainActivity.kt");
2741-
2742-
if ejected_main_activity.exists() {
2743-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using ejected MainActivity.kt: {}", ejected_main_activity.display());
2744-
std::fs::copy(&ejected_main_activity, &main_activity_dest)?;
2745-
} else {
2746-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using internal MainActivity.kt template");
27472735
write(
2748-
&main_activity_dest,
2736+
&manifest_dest,
27492737
hbs.render_template(
2750-
include_str!("../../assets/android/MainActivity.kt.hbs"),
2738+
include_str!("../../assets/android/gen/app/src/main/AndroidManifest.xml.hbs"),
27512739
&hbs_data,
27522740
)?,
27532741
)?;
27542742
}
27552743

2744+
// Write the main activity using the render helper
2745+
render_ejected_or_use_template(
2746+
"MainActivity.kt",
2747+
&self
2748+
.wry_android_kotlin_files_out_dir()
2749+
.join("MainActivity.kt"),
2750+
include_str!("../../assets/android/MainActivity.kt.hbs"),
2751+
)?;
2752+
27562753
// Write the res folder, containing stuff like default icons, colors, and menubars.
27572754
let res = app_main.join("res");
27582755
create_dir_all(&res)?;
27592756
create_dir_all(res.join("values"))?;
2760-
2761-
// Check for ejected strings.xml file
2762-
let strings_xml_path = res.join("values").join("strings.xml");
2763-
let ejected_strings_path = ejected_android_dir.join("gen/app/src/main/res/values/strings.xml");
2764-
2765-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Checking for ejected strings.xml at: {}", ejected_strings_path.display());
2766-
2767-
if ejected_strings_path.exists() {
2768-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Found ejected strings.xml: {}", ejected_strings_path.display());
2769-
2770-
// Read and log the content of the ejected file
2771-
let content = std::fs::read_to_string(&ejected_strings_path).unwrap_or_else(|_| "<Failed to read file>".to_string());
2772-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Ejected strings.xml content: {}", content);
2773-
2774-
// Copy the ejected strings.xml file directly
2775-
std::fs::copy(&ejected_strings_path, &strings_xml_path)?;
2776-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Copied ejected strings.xml to: {}", strings_xml_path.display());
2777-
2778-
// Verify the copied file
2779-
let copied_content = std::fs::read_to_string(&strings_xml_path).unwrap_or_else(|_| "<Failed to read file>".to_string());
2780-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Copied strings.xml content: {}", copied_content);
2781-
} else {
2782-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "No ejected strings.xml found, using internal template");
2783-
let template_content = hbs.render_template(
2784-
include_str!("../../assets/android/gen/app/src/main/res/values/strings.xml.hbs"),
2785-
&hbs_data,
2786-
)?;
2787-
2788-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Generated template content: {}", template_content);
2789-
write(&strings_xml_path, &template_content)?;
2790-
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Generated strings.xml from template at: {}", strings_xml_path.display());
2791-
}
2792-
write(
2793-
res.join("values").join("colors.xml"),
2757+
2758+
// Handle strings.xml with the render helper
2759+
render_ejected_or_use_template(
2760+
"gen/app/src/main/res/values/strings.xml",
2761+
&res.join("values").join("strings.xml"),
2762+
include_str!("../../assets/android/gen/app/src/main/res/values/strings.xml.hbs"),
2763+
)?;
2764+
// Handle colors.xml with the copy helper
2765+
copy_ejected_or_use_template(
2766+
"gen/app/src/main/res/values/colors.xml",
2767+
&res.join("values").join("colors.xml"),
27942768
include_bytes!("../../assets/android/gen/app/src/main/res/values/colors.xml"),
27952769
)?;
2796-
write(
2797-
res.join("values").join("styles.xml"),
2770+
// Handle styles.xml with the copy helper
2771+
copy_ejected_or_use_template(
2772+
"gen/app/src/main/res/values/styles.xml",
2773+
&res.join("values").join("styles.xml"),
27982774
include_bytes!("../../assets/android/gen/app/src/main/res/values/styles.xml"),
27992775
)?;
28002776

@@ -2807,57 +2783,69 @@ impl BuildRequest {
28072783
)?;
28082784

28092785
create_dir_all(res.join("drawable"))?;
2810-
write(
2811-
res.join("drawable").join("ic_launcher_background.xml"),
2786+
2787+
// Handle ic_launcher_background.xml with the copy helper
2788+
copy_ejected_or_use_template(
2789+
"gen/app/src/main/res/drawable/ic_launcher_background.xml",
2790+
&res.join("drawable").join("ic_launcher_background.xml"),
28122791
include_bytes!(
28132792
"../../assets/android/gen/app/src/main/res/drawable/ic_launcher_background.xml"
28142793
),
28152794
)?;
28162795
create_dir_all(res.join("drawable-v24"))?;
2817-
write(
2818-
res.join("drawable-v24").join("ic_launcher_foreground.xml"),
2796+
2797+
// Handle ic_launcher_foreground.xml with the copy helper
2798+
copy_ejected_or_use_template(
2799+
"gen/app/src/main/res/drawable-v24/ic_launcher_foreground.xml",
2800+
&res.join("drawable-v24").join("ic_launcher_foreground.xml"),
28192801
include_bytes!(
28202802
"../../assets/android/gen/app/src/main/res/drawable-v24/ic_launcher_foreground.xml"
28212803
),
28222804
)?;
28232805
create_dir_all(res.join("mipmap-anydpi-v26"))?;
2824-
write(
2825-
res.join("mipmap-anydpi-v26").join("ic_launcher.xml"),
2806+
copy_ejected_or_use_template(
2807+
"gen/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml",
2808+
&res.join("mipmap-anydpi-v26").join("ic_launcher.xml"),
28262809
include_bytes!(
28272810
"../../assets/android/gen/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml"
28282811
),
28292812
)?;
28302813
create_dir_all(res.join("mipmap-hdpi"))?;
2831-
write(
2832-
res.join("mipmap-hdpi").join("ic_launcher.webp"),
2814+
copy_ejected_or_use_template(
2815+
"gen/app/src/main/res/mipmap-hdpi/ic_launcher.webp",
2816+
&res.join("mipmap-hdpi").join("ic_launcher.webp"),
28332817
include_bytes!(
28342818
"../../assets/android/gen/app/src/main/res/mipmap-hdpi/ic_launcher.webp"
28352819
),
28362820
)?;
28372821
create_dir_all(res.join("mipmap-mdpi"))?;
2838-
write(
2839-
res.join("mipmap-mdpi").join("ic_launcher.webp"),
2822+
copy_ejected_or_use_template(
2823+
"gen/app/src/main/res/mipmap-mdpi/ic_launcher.webp",
2824+
&res.join("mipmap-mdpi").join("ic_launcher.webp"),
28402825
include_bytes!(
28412826
"../../assets/android/gen/app/src/main/res/mipmap-mdpi/ic_launcher.webp"
28422827
),
28432828
)?;
28442829
create_dir_all(res.join("mipmap-xhdpi"))?;
2845-
write(
2846-
res.join("mipmap-xhdpi").join("ic_launcher.webp"),
2830+
copy_ejected_or_use_template(
2831+
"gen/app/src/main/res/mipmap-xhdpi/ic_launcher.webp",
2832+
&res.join("mipmap-xhdpi").join("ic_launcher.webp"),
28472833
include_bytes!(
28482834
"../../assets/android/gen/app/src/main/res/mipmap-xhdpi/ic_launcher.webp"
28492835
),
28502836
)?;
28512837
create_dir_all(res.join("mipmap-xxhdpi"))?;
2852-
write(
2853-
res.join("mipmap-xxhdpi").join("ic_launcher.webp"),
2838+
copy_ejected_or_use_template(
2839+
"gen/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp",
2840+
&res.join("mipmap-xxhdpi").join("ic_launcher.webp"),
28542841
include_bytes!(
28552842
"../../assets/android/gen/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp"
28562843
),
28572844
)?;
28582845
create_dir_all(res.join("mipmap-xxxhdpi"))?;
2859-
write(
2860-
res.join("mipmap-xxxhdpi").join("ic_launcher.webp"),
2846+
copy_ejected_or_use_template(
2847+
"gen/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp",
2848+
&res.join("mipmap-xxxhdpi").join("ic_launcher.webp"),
28612849
include_bytes!(
28622850
"../../assets/android/gen/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp"
28632851
),
@@ -3230,8 +3218,22 @@ impl BuildRequest {
32303218

32313219
Platform::Ios => {
32323220
let dest = self.root_dir().join("Info.plist");
3233-
let plist = self.info_plist_contents(self.platform)?;
3234-
std::fs::write(dest, plist)?;
3221+
3222+
// Check for ejected iOS Info.plist
3223+
let project_dir = self.workspace_dir();
3224+
let ejected_ios_dir = project_dir.join("ios");
3225+
let ejected_plist_path = ejected_ios_dir.join("Info.plist");
3226+
3227+
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Checking for ejected iOS Info.plist at: {}", ejected_plist_path.display());
3228+
3229+
if ejected_plist_path.exists() {
3230+
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using ejected iOS Info.plist: {}", ejected_plist_path.display());
3231+
let _ = std::fs::copy(&ejected_plist_path, &dest)?;
3232+
} else {
3233+
tracing::info!(dx_src = ?crate::logging::TraceSrc::Dev, "Using internal iOS Info.plist template");
3234+
let plist = self.info_plist_contents(self.platform)?;
3235+
std::fs::write(dest, plist)?;
3236+
}
32353237
}
32363238

32373239
// AndroidManifest.xml
@@ -3791,9 +3793,9 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
37913793
/// and return the path to the ejected assets directory if found
37923794
pub(crate) fn ejected_assets_dir(&self) -> Option<PathBuf> {
37933795
use crate::build::EjectedAssets;
3794-
3796+
37953797
let workspace_dir = self.workspace_dir();
3796-
3798+
37973799
match self.platform {
37983800
Platform::Android => EjectedAssets::android_assets_dir(&workspace_dir),
37993801
Platform::Ios => EjectedAssets::ios_assets_dir(&workspace_dir),
@@ -3806,7 +3808,7 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
38063808
if let Some(ejected_dir) = self.ejected_assets_dir() {
38073809
return ejected_dir;
38083810
}
3809-
3811+
38103812
// If no ejected assets, use the default asset directory
38113813
match self.platform {
38123814
Platform::MacOS => self

0 commit comments

Comments
 (0)