Clock.System.now() fails on Android SDK less than 26

See original GitHub issue

Hi! Call of Clock.System.now() fails with java.lang.NoClassDefFoundError: kotlinx.datetime.Instant() on Android 7 and earlier because Instant() was added to SDK in version 26.

Should I provide platform-specific implementation instead?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
dekar91commented, Feb 1, 2021

WeSeems I’ve found a solution:

  1. Add coreLibraryDesugator by official documentation,
  2. Add kotlinx.datetime to android dependencies.

Android 6 does not crash anymore. Thank you for your help. This issue can be closed.

0reactions
dekar91commented, Feb 1, 2021

Well, I reproduces the problem a little bit incorrecly. There is full stacktrace from my main project:

E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    Process: ru.rest, PID: 6345
    java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/Instant;
        at kotlinx.datetime.Instant.<clinit>(Instant.kt:78)
        at kotlinx.datetime.Clock$System.now(Clock.kt:17)
     
     ....
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Instant" on path: DexPathList[[zip file "/data/app/ru.test-1/base.apk"],nativeLibraryDirectories=[/data/app/ru.test.scanner-1/lib/x86_64, /vendor/lib64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at kotlinx.datetime.Instant.<clinit>(Instant.kt:78) 
        at kotlinx.datetime.Clock$System.now(Clock.kt:17) 
       ...
       
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) 
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665) 
    	Suppressed: java.lang.ClassNotFoundException: java.time.Instant
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        		... 17 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
V/FA: Recording user engagement, ms: 11913
Disconnected from the target VM, address: 'localhost:61815', transport: 'socket'

I see, the same supressed Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.Instant", but explicitly added kotlinx.datetime` to android gradle does not solve the problem.

Update tried to add kotlinx.datetime explicitly at github I provided does not fix the problem as well. Probably, I’ve imported the library incorrectly?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "Call requires API level 26 (current min is 25) ...
You need to use https://github.com/JakeWharton/ThreeTenABP to be able using LocalDateTime with Android API < 26. Add the dependencies to ...
Read more >
Migrating to Android 8.0
If your app receives location updates from a background service, it receives less frequent updates on Android 8.0 (API level 26) compared to...
Read more >
Emulator release notes | Android Developers
Linux emulator now uses KVM paravirtualized clock when the guest kernel version is >= 5.4 (R system images or later). Emulator now uses...
Read more >
Android 8.0 Behavior Changes
These behavior changes apply to all apps when they run on the Android 8.0 (API level 26) platform, regardless of the API level...
Read more >
<uses-sdk> | Android Developers
The Android system will prevent the user from installing the application if the system's API Level is lower than the value specified in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found