Synthetic not available in new KMM example project

Hi!

I’m trying to use the new KMM example project , but it seems that is impossible to import textView with Synthetic

Is this available on kmm?

Thanks

1 Like

Hi Francesco, welcome to the Kotlin forum!

May you please explain in details what Syntetic means in your case?

Hi Alex,

the import of kotlinx.android.synthetic is not working. Unresolved reference: synthetic… for example:
import kotlinx.android.synthetic.main.activity_main.*
so I can’t bind the view and I must use findViewById(). is kotlin android extensions not working in the example project?

Thanks

1 Like

@alex.anisimov any news about that?

Hi @francescogatto,
Sorry for us making you wait so long we had needed time to understand the problem to the full.

Synthetic type of extension have not been adopted to KMM so they might be not robust enough while used with KMM. We recommend to use View Binding extensions instead, they are fully supported by KMM

1 Like

Thanks @alex.anisimov,

I hope it would be supported soon, because is necessary for existing projects that would be move to KMM

Any idea when its going to be available?

Why it seems so hard to include in the next release?? Also I found a work around but not sure if it applicable at this point.

Add this code in .iml file

<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>

Is there any plan to implement synthetic in KMM in the next time?

@omeryounus
This problem occurs through kotlin.mpp.enableGranularSourceSetsMetadata=true . See https://youtrack.jetbrains.com/issue/KT-41866

If I set it to false then it works perfectly.

I think you had better use View Binding library instead of Synthetic. It’s safer and be suggested by Google.