2

I found a lot of things about the subject, but not enough to fix it, so here I go.

I just arrived on a new project and they have a heavy problem :

import kotlinx.android.synthetic

is unresolved by Android Studio. The project runs, and there is no problem during the build, but Android Studio shows me a lot of errors in the code because it does not recognize the layout. Which means no shortcut for the layout/components.

We have, I think, already import the correct plugin :

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.jetbrains.kotlin.android.extensions'

I tried removing apply plugin: 'org.jetbrains.kotlin.android.extensions', but it doesn't help. We also have classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" in our buildscript dependencies.

Not an expert in Gradle but open for any help!

Shalu T D
  • 3,921
  • 2
  • 26
  • 37
Romain Huber
  • 205
  • 4
  • 14
  • So it seems to be only a problem in Android Studio's cache. Try restaring the IDE, if that does not help do "invalidate caches and restart" – Thommy Jul 03 '20 at 11:18
  • Already does that twice. Notice that I'm not the only one in the team having this issue – Romain Huber Jul 03 '20 at 12:05

1 Answers1

4

So after searching on an issue opened in the google forum, I found that I need to add by myself the following facet in each module_name.iml. It's a bug that only appear in multi module project and there is no fix yet.

<facet type="kotlin-language" name="Kotlin">
  <configuration version="3" platform="JVM 1.8" allPlatforms="JVM [1.8]" useProjectSettings="false">
    <compilerSettings />
    <compilerArguments>
      <option name="jvmTarget" value="1.8" />
      <option name="pluginOptions">
        <array>
          <option value="plugin:org.jetbrains.kotlin.android:enabled=true" />
          <option value="plugin:org.jetbrains.kotlin.android:defaultCacheImplementation=hashMap" />
        </array>
      </option>
    </compilerArguments>
  </configuration>
</facet>

Found it here : https://issuetracker.google.com/issues/145888144

Romain Huber
  • 205
  • 4
  • 14