Romain Huber
Romain Huber

Reputation: 207

import kotlinx.android.synthetic failed : Android studio doesn't find it but I can run the app

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!

Upvotes: 3

Views: 3595

Answers (1)

Romain Huber
Romain Huber

Reputation: 207

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

Upvotes: 5

Related Questions