@@ -460,18 +460,6 @@ fn doInstallApk(apk: *Apk) Allocator.Error!*Step.InstallFile {
460460 @panic (b .fmt ("artifact[{d}] has no 'target' set" , .{artifact_index }));
461461 };
462462
463- // NOTE(jae): 2026-02-01
464- // If not explicitly set in users build, default to using LLVM and LLD for Android builds
465- // as that's the same toolchain that the Android SDK uses.
466- //
467- // This also can resolve issues with Zigs linker not yet supporting certain compression schemes/etc
468- if (artifact .use_llvm == null ) {
469- artifact .use_llvm = true ;
470- }
471- if (artifact .use_lld == null ) {
472- artifact .use_lld = true ;
473- }
474-
475463 // https://developer.android.com/ndk/guides/abis#native-code-in-app-packages
476464 const so_dir : []const u8 = switch (target .result .cpu .arch ) {
477465 .aarch64 = > "arm64-v8a" ,
@@ -530,18 +518,14 @@ fn doInstallApk(apk: *Apk) Allocator.Error!*Step.InstallFile {
530518 // - To know where C header /lib files are via setLibCFile and linkLibC
531519 // - Provide path to additional libraries to link to
532520 {
533- if (artifact .linkage ) | linkage | {
534- if (linkage == .dynamic ) {
535- updateSharedLibraryOptions (artifact );
536- }
521+ if (artifact .root_module .link_libc == null ) {
522+ artifact .root_module .link_libc = true ;
537523 }
538- apk .setLibCFile (artifact );
539- apk .addLibraryPaths (artifact .root_module );
540- artifact .root_module .link_libc = true ;
524+ apk .updateArtifact (artifact , so_dir , apk_files );
541525
542526 // Apply workaround for Zig 0.14.0 stable
543527 //
544- // This *must* occur after " apk.updateLinkObjects" for the root package otherwise
528+ // This *must* occur after apk.updateArtifact (apk. updateLinkObjects) for the root package otherwise
545529 // you may get an error like: "unable to find dynamic system library 'c++abi_zig_workaround'"
546530 apk .applyLibLinkCppWorkaroundIssue19 (artifact );
547531 }
@@ -787,33 +771,55 @@ fn setLibCFile(apk: *Apk, compile: *Step.Compile) void {
787771 compile .setLibCFile (android_libc_path );
788772}
789773
774+ fn updateArtifact (apk : * Apk , artifact : * Step.Compile , so_dir : []const u8 , raw_top_level_apk_files : * Step.WriteFile ) void {
775+ // If you have a library that is being built as an *.so then install it
776+ // alongside your library.
777+ //
778+ // This was initially added to support building SDL2 with Zig.
779+ if (artifact .linkage ) | linkage | {
780+ if (linkage == .dynamic ) {
781+ updateSharedLibraryOptions (artifact );
782+ _ = raw_top_level_apk_files .addCopyFile (artifact .getEmittedBin (), apk .b .fmt ("lib/{s}/lib{s}.so" , .{ so_dir , artifact .name }));
783+ }
784+ }
785+
786+ // NOTE(jae): 2026-02-01
787+ // If not explicitly set in users build, default to using LLVM and LLD for Android builds
788+ // as that's the same toolchain that the Android SDK uses.
789+ //
790+ // This also can resolve issues with Zigs linker not yet supporting certain compression schemes/etc
791+ if (artifact .use_lld == null ) {
792+ artifact .use_lld = true ;
793+ }
794+ if (artifact .use_llvm == null ) {
795+ artifact .use_llvm = true ;
796+ }
797+
798+ // NOTE(jae): 2026-04-12
799+ // Android should default to using fPIC to avoid compilation issues.
800+ if (artifact .root_module .pic == null ) {
801+ artifact .root_module .pic = true ;
802+ }
803+
804+ // If library is built using C or C++ then setLibCFile
805+ if (artifact .root_module .link_libc == true or
806+ artifact .root_module .link_libcpp == true )
807+ {
808+ apk .setLibCFile (artifact );
809+ }
810+
811+ // Add library paths to find "android", "log", etc
812+ apk .addLibraryPaths (artifact .root_module );
813+ }
814+
790815fn updateLinkObjects (apk : * Apk , root_artifact : * Step.Compile , so_dir : []const u8 , raw_top_level_apk_files : * Step.WriteFile ) void {
791- const b = apk .b ;
792816 for (root_artifact .root_module .link_objects .items ) | link_object | {
793817 switch (link_object ) {
794818 .other_step = > | artifact | {
795819 switch (artifact .kind ) {
796820 .lib = > {
797- // If you have a library that is being built as an *.so then install it
798- // alongside your library.
799- //
800- // This was initially added to support building SDL2 with Zig.
801- if (artifact .linkage ) | linkage | {
802- if (linkage == .dynamic ) {
803- updateSharedLibraryOptions (artifact );
804- _ = raw_top_level_apk_files .addCopyFile (artifact .getEmittedBin (), b .fmt ("lib/{s}/lib{s}.so" , .{ so_dir , artifact .name }));
805- }
806- }
807-
808- // If library is built using C or C++ then setLibCFile
809- if (artifact .root_module .link_libc == true or
810- artifact .root_module .link_libcpp == true )
811- {
812- apk .setLibCFile (artifact );
813- }
814-
815- // Add library paths to find "android", "log", etc
816- apk .addLibraryPaths (artifact .root_module );
821+ // Update updateSharedLibraryOptions, libCFile, addLibraryPaths
822+ apk .updateArtifact (artifact , so_dir , raw_top_level_apk_files );
817823
818824 // Update libraries linked to this library
819825 apk .updateLinkObjects (artifact , so_dir , raw_top_level_apk_files );
0 commit comments