<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><span id="mailbox-conversation"><div>Hi, I’m still working on the deployment and JNI side of SwiftAndroid (github.com/SwiftAndroid). After success with some basic tests I’ve started fleshing out a “Swifty” JNI interface and connected to some existing Swift library code I want to try out. Now I’m stuck and I hope someone with more experience can lend some wisdom on the matter:</div>
<div><br></div>
<div>libicu doesn’t come packaged for Android, so the source needs to be downloaded, compiled and then icui18n and icuuc linked into libswiftCore and libswiftRuntime during the stdlib build process. After that, if I copy the libicui18n and libicuuc.so files into the system library path on the Android emulator, the Swift code links with swiftCore and executes fine there.</div>
<div><br></div>
<div>What I haven’t yet figured out is how to get these icu libraries dynamically linking at runtime on a non-rooted device. For some reason, and seemingly no matter what I do the runtime linker complains of missing symbols.</div>
<div><br></div>
<div>I’ve tried loading the libraries in various ways with no luck: the same way I’m loading everything else (my own program's swift module, the stdlib, etc.), as an explicit dependency of libswiftCore (in Android.mk), and at runtime in Java via System.loadLibrary(). All of these result in the same fatal error: that a certain libicu symbol is missing (nm tells me it’s present in icui18n) and therefore libswiftCore couldn’t be loaded.</div>
<div><br></div>
<div>Based on</div>
<div>a) the above issues,</div>
<div>b) the fact that the icu libraries are large (as big as the swift stdlib itself), and that seemingly only a very small amount of them is actually used,</div>
<div>c) the fact that the swift ABI is not yet set in stone anyway (I understand swiftCore is still packaged alongside every Swift iOS app, for example, which as far as I understand negates any benefit of dynamic linking for now)</div>
<div><br></div>
<div>.. it would make sense to me to just statically link the libicu dependencies into the stdlib for Android, or even just forego dynamic linking altogether on Android, except for the system libs.</div>
<div><br></div>
<div>Assuming static linking makes sense for Android (please correct me if my reasoning so far is wrong - this is all very new for me), here’s where I’m stuck at the moment. I’ve tried building swift via</div>
<div><br></div>
<div> ./utils/build-script -R --no-assertions -b -p --extra-swift-args build-swift-static-stdlib=1</div>
<div><br></div>
<div>but changing this static-stdlib flag seems to have no effect at all on the build output. As more of a longshot I also tried adding</div>
<div><br></div>
<div> list(APPEND swift_runtime_compile_flags</div>
<div> "-Bstatic”)</div>
<div><br></div>
<div>to stdlib/public/runtime/CMakeLists.txt just before add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE. Neither of these seemed to do anything whatsoever. I wish it would at least break so I don’t get my hopes up waiting for the stdlib to recompile :)</div>
<div><br></div>
<div>I’m a bit lost in all the different components of the build system to be honest, so any input on these issues would be greatly appreciated!</div>
<div><br></div>
<div>Thanks</div>
<div>-Geordie</div></span></body></html>