Plain Java library in Android Studio giving compile error inside the editor: Cannot access 'java.io.Serializable' which is a supertype of

Viewed 1051

I started working on an Android project in kotlin using clean architecture with a data and a domain layer, the domain layer is a plain java-library (no android dependencies)

This is the Domain module relevant gradle conf:

plugins {
    id("java-library")
    id("kotlin")
    id("kotlin-kapt")
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
    api(kotlin("stdlib-jdk8"))
    // ....
}

If I run a build from command line or within android studio it finish SUCCESSFULLY!

BUT Android Studio gives me lot of weird errors in the EDITOR only for this module:

Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.Double'. Check your module classpath for missing or conflicting dependencies
Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.String'. Check your module classpath for missing or conflicting dependencies
Cannot access 'java.io.Serializable' which is a supertype of 'java.util.Locale'. Check your module classpath for missing or conflicting dependencies
Cannot access 'java.io.Serializable' which is a supertype of 'java.math.BigDecimal'. Check your module classpath for missing or conflicting dependencies
Cannot access 'java.io.Serializable' which is a supertype of 'java.time.OffsetDateTime'. Check your module classpath for missing or conflicting dependencies

Here, look: enter image description here

You get the picture. They are all in red in the Editor. However, if I execute compile: no error, and the project work as expected.

I want to stress this out:

--> It is just a problem in the Editor BUT it is annoying <--

Cause it hides real errors I might need to see.

The other Dev in the project has no such issues.

I'm running on the last Android Studio Beta:

Android Studio Arctic Fox | 2020.3.1 Beta 3
Build #AI-203.7717.56.2031.7395685, built on May 25, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.8.0-53-generic
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin, com.intellij.lang.jsgraphql, org.intellij.plugins.markdown
Current Desktop: ubuntu:GNOME

I'm on Linux as you see, Ubuntu 20.04.02 LTS to be precise. The other Dev have a mac.

Android studio is set to use Embedded JDK (which is version 11).

If I edit my settings and instead of using the Embedded JDK I switch to my system openjdk version 11 the errors go away

When I change it, however, I start to have some preview issues in compose and, anyway, the Embedded JDK is recommended by Google. I'd rather stick to it, quoting:

A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.

Can anyone give any insight or help in getting rid of the above mentioned errors?

1 Answers

The same issue with you. When I create a use a separate module, it has this visual error. It's gone when not use a module.

Related