Mehta
Mehta

Reputation: 1226

Databinding class not generated for multiple layout folders

In Android studio 3.6, after creating new project, I am not able to created binding generated class for multiple folders.

I have multiple layout folders:

res/layout
res/layouts/dashboard
res/layouts/notifications

I am able to created binding class for

res/layout

but its not working for other layout folders.

App gradle file:

dataBinding{
        enabled = true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            res.srcDirs =
                    [
                            'src/main/res/layouts/notification',
                            'src/main/res/layout/dashboard',
                            'src/main/res/layouts',
                            'src/main/res/layout',
                            'src/main/res'
                    ]
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
        }
    }

Resource folder structure:

enter image description here

I have attached sample project which I have created in android studio 3.6. Source code link

Upvotes: 5

Views: 918

Answers (2)

mgray88
mgray88

Reputation: 385

Quick fix until this is fixed in Android Studio:

Add the output of the generated binding files to your gradle file (this works for both view binding and data binding):

android {
    sourceSets {
        main {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/debug/out'## Heading ##
        }
    }
}

Thanks to https://stackoverflow.com/a/60521114/792853

Upvotes: 0

SungHwan
SungHwan

Reputation: 11

It's a bug in android studio, It has been fixed in android studio 4.0 beta and 4.1 canary. And google will release hotfix for 3.6 to fix it.

Upvotes: 1

Related Questions