-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement kotlinx-datetime for the Android native targets #344
Conversation
161a864
to
bf09f25
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder would it be possible to restructure native sources later, so that the source tree resembled source set tree more?
E.g.
native
-- tzfile
---- tzdbOnFilesystem
------ darwin
------ linux
---- androidNative
-- windows
So,
? Looks a bit strange to me. But I agree that the directory structure is too cumbersome now. |
To test, run an Android emulator, and then, in the command line, ./gradlew androidNativeArm64TestBinaries && adb push core/build/bin/androidNativeArm64/debugTest/test.kexe /data/local/tmp/ && adb shell /data/local/tmp/test.kexe Change `Arm64` to another platfom (`X86`, `X64`, or `Arm32`) as needed.
For some reason, even though the code itself compiles and works, metadata couldn't compile. This is fixed by more carefully separating which code is compiled for each target, so unneeded code doesn't get included in the Native Android implementation.
bf09f25
to
972ee00
Compare
for (path in listOf( | ||
Path.fromString("/system/usr/share/zoneinfo/tzdata"), // immutable fallback tzdb | ||
Path.fromString("/apex/com.android.tzdata/etc/tz/tzdata"), // an up-to-date tzdb, may not exist | ||
)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the immutable fallback be last in list? @dkhalanskyjb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@natario1, why? On line 42, the last put
to execute will determine what gets used in the end. So, for Europe/London
, for example, first, the map will receive the value from the fallback, but then, the value will be overwritten by the up-to-date timezone database. No?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, sorry for bothering then! It just felt wrong, I'm used to see 'fallbacks' at the end of lists. Thanks for working on this 🙏
Unrelated to the actual changes but there is also a new API to run android emulator tests by using Gradle: https://developer.android.com/studio/test/gradle-managed-devices |
@hfhbd, it would be very nice to have tests for the Android native targets, but aren't these Android tests for the JVM version? |
@dkhalanskyjb Honestly, I don't know! They do work for the JVM version (of course) and you can bundle your c/native code in a |
@hfhbd, if you want to dive deep into this and discover a way to test native Android code on the emulator, we'll gladly accept your PR. I'd advise not spending time on this, though. If my intuitive understanding is correct, this would be a lot of work. The way Kotlin/Native builds tests is by compiling them into a separate executable, and you'd need to write some JVM wrapper to call that executable and check the test results. |
In case it helps, I built https://github.com/deepmedia/multiplatform-testing a few years ago, when trying to push for androidNative support in kotlinx repos (lack of testing was said to be one of the blockers). It can download Android tools, create and spin up matching emulators, and run Android Native tests as a linux executable. At the time, I found a couple of bugs in atomicfu and k/n runtime thanks to it. |
To test, run an Android emulator, and then, in the command line, ./gradlew androidNativeArm64TestBinaries && adb push core/build/bin/androidNativeArm64/debugTest/test.kexe /data/local/tmp/ && adb shell /data/local/tmp/test.kexe
Change
Arm64
to another platfom (X86
,X64
, orArm32
) as needed.Fixes #311