Skip to content

Cannot access class 'kotlinx.datetime.Instant'. Check your module classpath for missing or conflicting dependencies #198

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

Closed
dusiema opened this issue May 4, 2022 · 7 comments

Comments

@dusiema
Copy link

dusiema commented May 4, 2022

I updated a bunch of dependencies in my multiplatform App project (Kotlin to 1.6.20, KotlinxSerialization to 1.3.2, ...) and after it the Android app started to have the problem:
Cannot access class 'kotlinx.datetime.Instant'. Check your module classpath for missing or conflicting dependencies
This error message is from Android Studio - I also updated Android Studio.

Strange enough it does compile ok for the iOS App with gradle createXCFramework. But my test scheme in xCode also doesn't find the Instant Kotlin class anymore.

I wonder if this is only me or if anyone else has experienced this?

@cedrickcooke
Copy link

cedrickcooke commented May 5, 2022

There's some extra configuration required for Android projects because old Android uses Java 1.6, but java.time.Instant is a type provided by Java 1.8. See https://github.com/Kotlin/kotlinx-datetime#using-in-your-projects and https://developer.android.com/studio/write/java8-support#library-desugaring for more details.

@dusiema
Copy link
Author

dusiema commented May 6, 2022

Thank you for your comment.
My minSDK is 21 (and this has not been changed). And I only updated a fairly new project (e.g. Kotlin from 1.6.0 to 1.6.20). So I'm not 100% sure but it seems that it has not to do with desugaring 1.8 Java language features? (I tried it anyways but it did not make a difference).

I also followed the "Using in your projects" guide and set java.mainToolchainVersion to 8. But also without any luck.

@dkhalanskyjb
Copy link
Collaborator

It doesn't look like an Android issue, since it's the kotlinx.datetime.Instant class that can't be found, not java.time.Instant. Maybe there's just no runtime dependency on kotlinx-datetime now and there was one (transitively) before? Did you try explicitly adding

                 implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")

to your dependencies and resyncing the Gradle project?

@dusiema
Copy link
Author

dusiema commented May 12, 2022

Unfortunately the dependency has already been explicitly specified like that.
Imho, it seems to be an Android Studio / Intellij issue and having to do with the Java Module Path (opposed to classpath).
So I guess it might not be directly related to kotlinx-datetime.

I was just wondering if anybody else experienced this.
Looking for a module-info.java I found this PR #135 which adds a module-info.java to kotlinx-datetime. But I don't know if and how it is related. Or if the issue is just on the Android Studio/Intellij side.

@dusiema
Copy link
Author

dusiema commented Jun 15, 2022

I ran the build again but on command line with ./gradlew installDebug and it had the same problem.
Reading some about gradle build and classpath I learned that api and implementation affect the classpath. So I just gave

api("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")

a try and then it compiled. I certainly do not fully oversee all implications that api has over implementation.
And the documentation on kotlinx-datetime says to use implementation. But I guess I stick with api for now.

(Sorry for kind of miss-using a bug ticket for this. Feel free to close this ticket anytime. I might sooner or later close this ticket myself if there are no other problems/ideas/comments.)

@dkhalanskyjb
Copy link
Collaborator

api roughly means "this is a dependency of this project, but its users also should be able to reference it". So, if you're writing a library that exposes our types, then yes, api is the proper choice. implementation, on the other hand, is better suited for libraries that only use the datetime library internally (so our types are not exposed in the API) or for applications.

@dusiema
Copy link
Author

dusiema commented Jun 16, 2022

Thanks for the explanation. I'm not writing a library and I'm not exposing anything from kotlinx-datetime. I'm actually just using Instant. After changing it to api I can change it back to implementation and it still works.
There must be some kind of dependency resolution / classpath problem elsewhere. Anyways.

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

No branches or pull requests

3 participants