Skip to content

Conversation

@sidepelican
Copy link
Contributor

Motivation

When shipping Swift libraries for Android applications, minimizing the binary size is highly desirable.
Currently, the runtime requirements for SwiftJava include several libraries that appear to be excessive.

This PR aims to reduce the number of dependencies to make the library more lightweight.

Changes

  • Updated some implementations to depend only on FoundationEssentials where possible, avoiding the heavier full Foundation framework.
  • Removed SwiftJavaConfigurationShared dependency, it was not being utilized within the target.

Results

By applying these changes, we have successfully reduced the number of required shared libraries (notably removing libdispatch, libswiftDispatch, libFoundation and libFoundationInternationalization).

  • Original
root@14ca194994da:/swift-java# readelf -d .build/debug/libSwiftJava.so | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libswiftSwiftOnoneSupport.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswiftCore.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswift_Concurrency.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswift_StringProcessing.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswift_RegexParser.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswift_Builtin_float.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswift_math.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswiftAndroid.so]
 0x0000000000000001 (NEEDED)             Shared library: [libBlocksRuntime.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdispatch.so]
 0x0000000000000001 (NEEDED)             Shared library: [libswiftDispatch.so]
 0x0000000000000001 (NEEDED)             Shared library: [libFoundation.so]
 0x0000000000000001 (NEEDED)             Shared library: [libFoundationEssentials.so]
 0x0000000000000001 (NEEDED)             Shared library: [libFoundationInternationalization.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc++_shared.so]
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]
  • This PR
root@14ca194994da:/swift-java# readelf -d .build/debug/libSwiftJava.so | grep NEEDED
0x0000000000000001 (NEEDED)             Shared library: [libswiftSwiftOnoneSupport.so]
0x0000000000000001 (NEEDED)             Shared library: [libswiftCore.so]
0x0000000000000001 (NEEDED)             Shared library: [libswift_Concurrency.so]
0x0000000000000001 (NEEDED)             Shared library: [libswift_StringProcessing.so]
0x0000000000000001 (NEEDED)             Shared library: [libswift_RegexParser.so]
0x0000000000000001 (NEEDED)             Shared library: [libswift_Builtin_float.so]
0x0000000000000001 (NEEDED)             Shared library: [libswift_math.so]
0x0000000000000001 (NEEDED)             Shared library: [libswiftAndroid.so]
0x0000000000000001 (NEEDED)             Shared library: [libFoundationEssentials.so]
0x0000000000000001 (NEEDED)             Shared library: [libm.so]
0x0000000000000001 (NEEDED)             Shared library: [libc++_shared.so]
0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
0x0000000000000001 (NEEDED)             Shared library: [libc.so]

with: ".",
options: .regularExpression
)
let regex = try! Regex(#"(?<=\w)\$"#)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run tests when you develop patches, this will crash with: SwiftJava/String+Extensions.swift:37: Fatal error: 'try!' expression unexpectedly raised an error: lookbehind is not currently supported

Happy to take the change but please make sure the tests are passing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry for such a basic mistake.
I was only checking the swift-testing results and missed the failures in XCTest.

@sidepelican
Copy link
Contributor Author

Fixed to not use lookbehind.
I noticed test_wrapJava_genericMethodTypeErasure_ofNullableOptional_staticMethods fails locally, but it also fails on main, so I'm assuming it's unrelated to these changes.

@ktoso
Copy link
Collaborator

ktoso commented Jan 9, 2026

Thanks! I'll check what's up with that other test

@ktoso ktoso merged commit f16496b into swiftlang:main Jan 9, 2026
49 checks passed
@ktoso
Copy link
Collaborator

ktoso commented Jan 9, 2026

Thank you, let's take this change :)

@sidepelican sidepelican deleted the less_runtime_deps branch January 9, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants