@@ -2575,7 +2575,7 @@ impl BuildRequest {
2575
2575
// Get the project directory for ejected assets
2576
2576
let project_dir = self . workspace . workspace_root ( ) ;
2577
2577
let ejected_android_dir = project_dir. join ( "android" ) ;
2578
-
2578
+
2579
2579
tracing:: info!( dx_src = ?crate :: logging:: TraceSrc :: Dev , "Project directory: {}" , project_dir. display( ) ) ;
2580
2580
tracing:: info!( dx_src = ?crate :: logging:: TraceSrc :: Dev , "Checking for ejected Android assets at: {}" , ejected_android_dir. display( ) ) ;
2581
2581
@@ -2624,9 +2624,12 @@ impl BuildRequest {
2624
2624
let hbs = handlebars:: Handlebars :: new ( ) ;
2625
2625
2626
2626
// 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 < ( ) > {
2628
2631
let ejected_path = ejected_android_dir. join ( rel_path) ;
2629
-
2632
+
2630
2633
if ejected_path. exists ( ) {
2631
2634
tracing:: info!( dx_src = ?crate :: logging:: TraceSrc :: Dev , "Using ejected Android asset: {}" , ejected_path. display( ) ) ;
2632
2635
std:: fs:: copy ( & ejected_path, dest_path) ?;
@@ -2636,22 +2639,23 @@ impl BuildRequest {
2636
2639
}
2637
2640
Ok ( ( ) )
2638
2641
} ;
2639
-
2642
+
2640
2643
// 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 < ( ) > {
2642
2648
let ejected_path = ejected_android_dir. join ( rel_path) ;
2643
-
2649
+
2644
2650
if ejected_path. exists ( ) {
2645
2651
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
+ } ) ?;
2648
2655
write ( dest_path, content) ?;
2649
2656
} else {
2650
2657
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) ?) ?;
2655
2659
}
2656
2660
Ok ( ( ) )
2657
2661
} ;
@@ -2662,25 +2666,25 @@ impl BuildRequest {
2662
2666
& root. join ( "build.gradle.kts" ) ,
2663
2667
include_bytes ! ( "../../assets/android/gen/build.gradle.kts" ) ,
2664
2668
) ?;
2665
-
2669
+
2666
2670
copy_ejected_or_use_template (
2667
2671
"gen/gradle.properties" ,
2668
2672
& root. join ( "gradle.properties" ) ,
2669
2673
include_bytes ! ( "../../assets/android/gen/gradle.properties" ) ,
2670
2674
) ?;
2671
-
2675
+
2672
2676
copy_ejected_or_use_template (
2673
2677
"gen/gradlew" ,
2674
2678
& root. join ( "gradlew" ) ,
2675
2679
include_bytes ! ( "../../assets/android/gen/gradlew" ) ,
2676
2680
) ?;
2677
-
2681
+
2678
2682
copy_ejected_or_use_template (
2679
2683
"gen/gradlew.bat" ,
2680
2684
& root. join ( "gradlew.bat" ) ,
2681
2685
include_bytes ! ( "../../assets/android/gen/gradlew.bat" ) ,
2682
2686
) ?;
2683
-
2687
+
2684
2688
copy_ejected_or_use_template (
2685
2689
"gen/settings.gradle" ,
2686
2690
& root. join ( "settings.gradle" ) ,
@@ -2693,7 +2697,7 @@ impl BuildRequest {
2693
2697
& wrapper. join ( "gradle-wrapper.properties" ) ,
2694
2698
include_bytes ! ( "../../assets/android/gen/gradle/wrapper/gradle-wrapper.properties" ) ,
2695
2699
) ?;
2696
-
2700
+
2697
2701
copy_ejected_or_use_template (
2698
2702
"gen/gradle/wrapper/gradle-wrapper.jar" ,
2699
2703
& wrapper. join ( "gradle-wrapper.jar" ) ,
@@ -2706,95 +2710,67 @@ impl BuildRequest {
2706
2710
& app. join ( "build.gradle.kts" ) ,
2707
2711
include_str ! ( "../../assets/android/gen/app/build.gradle.kts.hbs" ) ,
2708
2712
) ?;
2709
-
2713
+
2710
2714
copy_ejected_or_use_template (
2711
2715
"gen/app/proguard-rules.pro" ,
2712
2716
& app. join ( "proguard-rules.pro" ) ,
2713
2717
include_bytes ! ( "../../assets/android/gen/app/proguard-rules.pro" ) ,
2714
2718
) ?;
2715
2719
2716
- // Handle AndroidManifest.xml
2720
+ // Handle AndroidManifest.xml with special case for config-specified manifest
2717
2721
let manifest_dest = app. join ( "src" ) . join ( "main" ) . join ( "AndroidManifest.xml" ) ;
2718
2722
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 ( ) {
2721
2725
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) ?;
2724
2727
} else if let Some ( manifest) = self . config . application . android_manifest . as_deref ( ) {
2725
2728
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) ?;
2728
2733
} else {
2729
2734
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" ) ;
2747
2735
write (
2748
- & main_activity_dest ,
2736
+ & manifest_dest ,
2749
2737
hbs. render_template (
2750
- include_str ! ( "../../assets/android/MainActivity.kt .hbs" ) ,
2738
+ include_str ! ( "../../assets/android/gen/app/src/main/AndroidManifest.xml .hbs" ) ,
2751
2739
& hbs_data,
2752
2740
) ?,
2753
2741
) ?;
2754
2742
}
2755
2743
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
+
2756
2753
// Write the res folder, containing stuff like default icons, colors, and menubars.
2757
2754
let res = app_main. join ( "res" ) ;
2758
2755
create_dir_all ( & res) ?;
2759
2756
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" ) ,
2794
2768
include_bytes ! ( "../../assets/android/gen/app/src/main/res/values/colors.xml" ) ,
2795
2769
) ?;
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" ) ,
2798
2774
include_bytes ! ( "../../assets/android/gen/app/src/main/res/values/styles.xml" ) ,
2799
2775
) ?;
2800
2776
@@ -2807,57 +2783,69 @@ impl BuildRequest {
2807
2783
) ?;
2808
2784
2809
2785
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" ) ,
2812
2791
include_bytes ! (
2813
2792
"../../assets/android/gen/app/src/main/res/drawable/ic_launcher_background.xml"
2814
2793
) ,
2815
2794
) ?;
2816
2795
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" ) ,
2819
2801
include_bytes ! (
2820
2802
"../../assets/android/gen/app/src/main/res/drawable-v24/ic_launcher_foreground.xml"
2821
2803
) ,
2822
2804
) ?;
2823
2805
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" ) ,
2826
2809
include_bytes ! (
2827
2810
"../../assets/android/gen/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml"
2828
2811
) ,
2829
2812
) ?;
2830
2813
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" ) ,
2833
2817
include_bytes ! (
2834
2818
"../../assets/android/gen/app/src/main/res/mipmap-hdpi/ic_launcher.webp"
2835
2819
) ,
2836
2820
) ?;
2837
2821
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" ) ,
2840
2825
include_bytes ! (
2841
2826
"../../assets/android/gen/app/src/main/res/mipmap-mdpi/ic_launcher.webp"
2842
2827
) ,
2843
2828
) ?;
2844
2829
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" ) ,
2847
2833
include_bytes ! (
2848
2834
"../../assets/android/gen/app/src/main/res/mipmap-xhdpi/ic_launcher.webp"
2849
2835
) ,
2850
2836
) ?;
2851
2837
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" ) ,
2854
2841
include_bytes ! (
2855
2842
"../../assets/android/gen/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp"
2856
2843
) ,
2857
2844
) ?;
2858
2845
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" ) ,
2861
2849
include_bytes ! (
2862
2850
"../../assets/android/gen/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp"
2863
2851
) ,
@@ -3230,8 +3218,22 @@ impl BuildRequest {
3230
3218
3231
3219
Platform :: Ios => {
3232
3220
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
+ }
3235
3237
}
3236
3238
3237
3239
// AndroidManifest.xml
@@ -3791,9 +3793,9 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
3791
3793
/// and return the path to the ejected assets directory if found
3792
3794
pub ( crate ) fn ejected_assets_dir ( & self ) -> Option < PathBuf > {
3793
3795
use crate :: build:: EjectedAssets ;
3794
-
3796
+
3795
3797
let workspace_dir = self . workspace_dir ( ) ;
3796
-
3798
+
3797
3799
match self . platform {
3798
3800
Platform :: Android => EjectedAssets :: android_assets_dir ( & workspace_dir) ,
3799
3801
Platform :: Ios => EjectedAssets :: ios_assets_dir ( & workspace_dir) ,
@@ -3806,7 +3808,7 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
3806
3808
if let Some ( ejected_dir) = self . ejected_assets_dir ( ) {
3807
3809
return ejected_dir;
3808
3810
}
3809
-
3811
+
3810
3812
// If no ejected assets, use the default asset directory
3811
3813
match self . platform {
3812
3814
Platform :: MacOS => self
0 commit comments