(Partial) Nightlies for android SDK

Thank you!

Downloading cacert.pem and setting path into environment variable URLSessionCertificateAuthorityInfoFile seems helps.


File certificatesFile = this.getCachedAsset(this, "cacert.pem");
Os.setenv("URLSessionCertificateAuthorityInfoFile", certificatesFile.getAbsolutePath(), true);

// Or alternative !!!unsafe!!! way.
Os.setenv("URLSessionCertificateAuthorityInfoFile", "INSECURE_SSL_NO_VERIFY", true);

But now I am getting another error:

A/SwiftRuntime: Fatal error: Unexpected ubrk_open failure: file /ToolChain/Sources/swift/stdlib/public/core/ThreadLocalStorage.swift, line 165

The related code in file ThreadLocalStorage.swift:

@_silgen_name("_stdlib_createTLS")
internal func _createThreadLocalStorage()
  -> UnsafeMutablePointer<_ThreadLocalStorage>
{
  // Allocate and initialize a UBreakIterator and UText.
  var err = __swift_stdlib_U_ZERO_ERROR
  let newUBreakIterator = __swift_stdlib_ubrk_open(
      /*type:*/ __swift_stdlib_UBRK_CHARACTER, /*locale:*/ nil,
      /*text:*/ nil, /*textLength:*/ 0, /*status:*/ &err)
  _precondition(err.isSuccess, "Unexpected ubrk_open failure")

  // utext_openUTF8 needs a valid pointer, even though we won't read from it
  var a: Int8 = 0x41
  let newUText = __swift_stdlib_utext_openUTF8(
      /*ut:*/ nil, /*s:*/ &a, /*len:*/ 1, /*status:*/ &err)

  _precondition(err.isSuccess, "Unexpected utext_openUTF8 failure")

  let tlsPtr: UnsafeMutablePointer<_ThreadLocalStorage>
    = UnsafeMutablePointer<_ThreadLocalStorage>.allocate(
      capacity: 1
  )
  tlsPtr.initialize(to: _ThreadLocalStorage(
    _uBreakIterator: newUBreakIterator, _uText: newUText))

  return tlsPtr
}

Seems like it is something addressed UBreakIterator from ICU.

File: stdlib/public/stubs/UnicodeNormalization.cpp

swift::__swift_stdlib_UBreakIterator *swift::__swift_stdlib_ubrk_open(
    swift::__swift_stdlib_UBreakIteratorType type, const char *locale,
    const __swift_stdlib_UChar *text, int32_t textLength,
    __swift_stdlib_UErrorCode *status) {
  return ptr_cast<swift::__swift_stdlib_UBreakIterator>(
      ubrk_open(static_cast<UBreakIteratorType>(type), locale,
                reinterpret_cast<const UChar *>(text), textLength,
                ptr_cast<UErrorCode>(status)));
}

Maybe ICU is not properly configured on runtime (i.e. environment variables)?

Check the size of libicudataswift.so (or similar name, but one that says data). If it is small (some few KiB), the ICU installation is missing the data library, if it is around 20 MiB (IIRC), then you should be fine. In you have a big library, you might want to check that the locale that's being picked up is correct (try to use a simpler locale first, like en-US, if possible).
If you are using GitHub - SwiftAndroid/libiconv-libicu-android: Port of libiconv and libicu to Android to compile those libraries, you probably want to apply Generate the ICU data into a library. by drodriguez · Pull Request #13 · SwiftAndroid/libiconv-libicu-android · GitHub and recompile, to get the library with the data inside.

1 Like

Thank you @drodriguez !!!

I didn't noticed the following warning in configure output when building ICU:

Data Packaging: library
 This means: ICU data will be linked with ICU.
 A shared data library will be built.
 To locate data: ICU will use the linked data library.
 If linked with the stub library located in stubdata/,
 the application can use udata_setCommonData() or set a data path to override.
 
...

## Note: you have disabled ICU's tools.
   This ICU cannot build its own data or tests. <<<<<<<<<<<<<<<<
## Expect build failures in the 'data', 'test', and other directories.

The problem was in configure setting --enable-tools=no. After removing that setting the size of libicudataswift.so inreased from few kilobytes to 29mb.

Now URLSession APIs start working on Android:

1565624365.340 9543-9583/com.home.hello_ndk I/SwiftAndroid: ANDROID: Response: <HTTPURLResponse 0x00007a52ea633b20> { URL: https://www.google.com }{ status: 200, headers {
       "Set-Cookie" = 1P_JAR=2019-08-12-15; expires=Wed, 11-Sep-2019 15:39:25 GMT; path=/; domain=.google.com, NID=188=DArUrHOL-SU6U47lVX9jHrh_gNdderAdyfxUAU7FfnZRmqZLJ4R-QSCN_Ohjd4oOD9-62EmKp5w15hAAlz6SZzznfeIedAZQIoRPSwL9NelhyYQQoLpRPMxIfsBC_jMw5c195GVtUdD6N40xpLwhjs123a_Ig_PbE5z4jp-8-Fw; expires=Tue, 11-Feb-2020 15:39:25 GMT; path=/; domain=.google.com; HttpOnly;
       "Date" = Mon, 12 Aug 2019 15:39:25 GMT;
       "Content-Encoding" = gzip;
       "X-Frame-Options" = SAMEORIGIN;
       "P3P" = CP="This is not a P3P policy! See g.co/p3phelp for more info.";
       "Transfer-Encoding" = chunked;
       "Content-Type" = "text/html; charset=ISO-8859-1";
       "Alt-Svc" = quic=":443"; ma=2592000; v="46,43,39";
       "Server" = gws;
       "X-XSS-Protection" = 0;
       "Expires" = -1;
       "Cache-Control" = private, max-age=0;
    } }
1565624365.340 9543-9583/com.home.hello_ndk I/SwiftAndroid: ANDROID: Data: 11928 bytes
1565624365.340 9543-9543/com.home.hello_ndk I/SwiftAndroid: ANDROID: URL Task Completed
4 Likes