8

So happenned that I have a main app module

build.gradle

    dynamicFeatures = [":myFeature"]

    viewBinding {
        enabled = true
    }

AdroidManifest.xml

package="com.mydomain.testproject"

With some common layouts which I'm using across the app eq: app/res/error_view.xml

And I have the dynamic feature files

build.gradle

    viewBinding {
        enabled = true
    }

AdroidManifest.xml

package="com.mydomain.testproject.myFeature"

myfeature_fragment.xml

    <include
        android:id="@+id/error_view"
        layout="@layout/error_view"
        android:visibility="gone" />

MyFeatureFragment.kt

binding = MyFeatureFragmentBinding.bind(view)

and here comes the problem . When i try to access the binding.errorView AS shows an error Cannot access class 'com.mydomain.testproject.myFeature.databinding.ErrorViewBinding'. Check your module classpath for missing or conflicting dependencies

The strange thing is when I check the generated MyFeatureFragmentBinding class it contains the following

  @NonNull
  public final View errorView;

So I guess AS knows more than it shows for me. Also I found in the main module's generated classes the original ErrorViewBinding and OFC it's working flawlessly from there.

Someone managed to reference a common layout from another feature-module ?
or how can I enforce the type of the generated common view binding?

Stumi
  • 572
  • 5
  • 8

1 Answers1

0

I faced the same problem after applying this plugin inside the dynamic module Gradle file

apply plugin: 'kotlin-kapt'

then inside android block enable data binding like this

dataBinding.enabled = true

for who are using gradle.kts files like me

plugins {
id("kotlin-kapt")
}

and inside android block enable data binding like this

// enable data binding inside module
dataBinding.apply {
    isEnabled = true
}
Mostafa Anter
  • 3,445
  • 24
  • 26