Data binding class not generated in latest studio 3.6
Asked Answered
I

13

15

Today I have updated my android studio 3.5.3 to 3.6. Now, I am not able to generate any data binding class. Android studio it self generating data-binding-iml file.

Does any one faced such issue?

Gradle wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

Project level gradle file:

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
}

App level gradle file:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
android {
 dataBinding {
        enabled = true
    }
    // Using Lambda Expressions
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

gradle.properties:

kotlin.code.style=official
android.databinding.enableV2=true
kotlin.incremental=true
kapt.incremental.apt=true

Below is my Activity and XML files: Activity:

class ActivityMain : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        var binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <data>
        <import type="android.view.View" />
     <!--   <variable
            name="loading"
            type="Boolean" />-->
        <variable
            name="bottomMenu"
            type="Boolean" />
        <variable
            name="clickListener"
            type="com.ecom.side_menu.SideMenuClickHandler" />
    </data>
    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:fitsSystemWindows="false"
        android:layout_height="match_parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <include
                android:id="@+id/layToolbar"
                layout="@layout/layout_toolbar"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.fragment.app.FragmentContainerView
                android:id="@+id/splash_host"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:background="@android:color/white"
                app:defaultNavHost="true"
                app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/layToolbar"
                app:navGraph="@navigation/splash_graph" />

            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/bottomNavigationView"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="0dp"
                android:layout_marginEnd="0dp"
                android:background="@color/colorPrimary"
                android:visibility="@{safeUnbox(bottomMenu) ? View.VISIBLE : View.GONE}"
                app:itemBackground="@color/colorPrimary"
                app:itemIconTint="@android:color/white"
                app:itemTextColor="@android:color/white"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:menu="@menu/menu_navigation_dashboard" />


         <!--   <include
                android:id="@+id/progressLayoutId"
                layout="@layout/layout_progress"
                android:visibility="@{safeUnbox(loading) ? View.VISIBLE : View.GONE}"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" />-->

        </androidx.constraintlayout.widget.ConstraintLayout>

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigationView"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="@android:color/white"
            android:fitsSystemWindows="true"
            android:visibility="visible">
            <include
                android:id="@+id/customDrawerList"
                app:clickListener="@{clickListener}"
                layout="@layout/drawer_list" />
        </com.google.android.material.navigation.NavigationView>

    </androidx.drawerlayout.widget.DrawerLayout>

</layout>

Official solution:

Google has resolved this issue. After updating with new patch of android studio 3.6.2, I am able to create databinding class with multiple source set

Icebound answered 25/2, 2020 at 11:46 Comment(13)
I also update studio today itself && also use data binding classes.. it's working nicely broColpotomy
just invalidate caches and restart your studio ;)Colpotomy
@Niceumang I have tried invalidate caches and restart, along with I tried to delete build folder too.. But still same errorIcebound
will you show your XML and class where you create binding class?Colpotomy
@Niceumang class and XML added in questionIcebound
@Icebound facing the same issue. Seems like AS 3.6 doesn't work with databinding or viewbinding altogether, even with a new project. Only the bindingImpl classes are generated. Have tried every plausible solution/fix. Downgrading to AS 3.5 for the moment.Taffrail
@ArunL: In my project, I am not using viewbinding. in studio 3.6, only bindingImpl classes are generated for existing project. as of now, I have also downgraded to 3.5Icebound
@Icebound I'm experiencing the same. Only bindingImpl classes are being generated. Have tried to switch to ViewBinding by removing <layout> tags and enabling ViewBinding in gradle. However, even the bindingImpl classes aren't being generated in this case.Taffrail
When you have include tags, you need to add <layout> around your "layout_toolbar" xml file. I fixed this problem with this solution : https://mcmap.net/q/497273/-view-binding-not-work-with-quot-include-quot-incompatible-types-progressbarlayoutbinding-cannot-be-converted-to-viewdatabindingUproot
finally got a workaround. Refer to thisBombproof
@Steve: it's not working for me.Icebound
Try : https://mcmap.net/q/823401/-android-app-runtime-crash-after-update-gradle-plugin-3-6-duplicateDisputable
@InsaneCat: not working for meIcebound
M
6

This happened to me as well. The binding classes are actually generated. The project builds fine. Only Android Studio 3.6.1 (or underlying Gradle build system, I do not care) is buggy and cannot see these classes.

As an intermediate solution, I just hacked the source sets (please note that build variants in the fragment below are specific to my project, you need to rewrite it).

android {
    ...
    sourceSets {
        demoDebug {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/demoDebug/out'
        }
        fullDebug {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/fullDebug/out'
        }
        espressoDebug {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/espressoDebug/out'
        }
        demoRelease {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/demoRelease/out'
        }
        fullRelease {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/fullRelease/out'
        }
        espressoRelease {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/espressoRelease/out'
        }
    }
    ...
}

As pointed by Steve above: In the mean time, we have to patiently wait for Google to fix it...

EDIT

I have just realised it is MUCH more buggy than I expected, the layouts are broken too:

Please please dear Google: Do not release unstable intermediate versions to us"

I hope Google will fix this mess soon...

EDIT 2

I have realized again that Android Studio 3.6 is even more buggy than described above.

The execution of existing Espresso tests is broken too.

I strongly discourage everyone from upgrading to Android Studio 3.6.

I the mean time, we will probably downgrade back to Android Studio 3.5.

Manganese answered 3/3, 2020 at 8:7 Comment(3)
thanks.. This hack is working fine.. Now I am able to create Binding class.Icebound
but still binding variable are not accessible properly in xmlIcebound
Unfortunately, as mentioned in my EDIT above :(Housen
R
8

I am using android studio 3.6.1 the problem solved after adding viewBinding.enabled = true to android{ in build.gradle :

android {

...
    dataBinding {
        enabled = true
    }
    viewBinding.enabled = true

Update: Make sure you add apply plugin: 'kotlin-android-extensions' in top of App Module gradle file :

  plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'kotlin-android-extensions' //<--
  }
Radiocommunication answered 15/3, 2020 at 14:5 Comment(1)
It works!! i had missing the dataBinding { enabled = true }Seiber
M
6

This happened to me as well. The binding classes are actually generated. The project builds fine. Only Android Studio 3.6.1 (or underlying Gradle build system, I do not care) is buggy and cannot see these classes.

As an intermediate solution, I just hacked the source sets (please note that build variants in the fragment below are specific to my project, you need to rewrite it).

android {
    ...
    sourceSets {
        demoDebug {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/demoDebug/out'
        }
        fullDebug {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/fullDebug/out'
        }
        espressoDebug {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/espressoDebug/out'
        }
        demoRelease {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/demoRelease/out'
        }
        fullRelease {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/fullRelease/out'
        }
        espressoRelease {
            java.srcDirs += 'build/generated/data_binding_base_class_source_out/espressoRelease/out'
        }
    }
    ...
}

As pointed by Steve above: In the mean time, we have to patiently wait for Google to fix it...

EDIT

I have just realised it is MUCH more buggy than I expected, the layouts are broken too:

Please please dear Google: Do not release unstable intermediate versions to us"

I hope Google will fix this mess soon...

EDIT 2

I have realized again that Android Studio 3.6 is even more buggy than described above.

The execution of existing Espresso tests is broken too.

I strongly discourage everyone from upgrading to Android Studio 3.6.

I the mean time, we will probably downgrade back to Android Studio 3.5.

Manganese answered 3/3, 2020 at 8:7 Comment(3)
thanks.. This hack is working fine.. Now I am able to create Binding class.Icebound
but still binding variable are not accessible properly in xmlIcebound
Unfortunately, as mentioned in my EDIT above :(Housen
D
5

Just update your Gradle version to the latest. Go to:

File > Project Structure > Gradle Version

And select the latest stable version (currently 6.3). Check also your Android Gradle Plugin Version if it's also pointing to the latest.

Drinkable answered 25/3, 2020 at 7:50 Comment(2)
Thanks, this help in my case! +1Abukir
Great answer, appreciate the menu pointers...this DID solve my problem too. I spent MANY hours on this (so obvious in hindsight).Fazeli
R
3

For AndroidStudio 3.6.1, You can add below code in to app level build.gradle(:app). My problem is solved by adding this line, hope your's too.

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

Richter answered 4/3, 2020 at 7:38 Comment(1)
as suggested by Jiří Křivánek & you, I have added mentioned solution but now, every variables are displaying with red underline.. not able to accessIcebound
K
2

It does appear there's a bug in the latest Android data binding library. Cleaning the project did not work. Rebuilding the project did not work. Invalidating caches and restarting did not work.

The ONLY solution that worked for me was rolling back the data binding version from version 2 (which is the new default in Android Studio 3.6.1 and higher) to version 1. To do this, you don't have to roll back ALL of Android Studio. Instead you can add the following line to gradle.properties:

android.databinding.enableV2=false

TLDR; I'm wondering whether Google has decided to completely revamp the way we're supposed to do data binding with their latest data binding compiler. It wouldn't be surprising if the team was working to provide YAS (yet another syntax). After all, DataBindingUtil.inflate<MyClassBindingImpl> has got to be one of the most bizarre usage patterns in all of computer programming, requiring the compiler to auto-generate a concrete implementation of a generic data binding class BEFORE you can reference the auto-generated class in your code. BTW, this is why tools like Make Project exist. I half-expect a complete overhaul to the data binding syntax to arrive shortly.

Kries answered 26/3, 2020 at 20:38 Comment(0)
U
1

i had this problem cause i had separate my layouts into several directory and define them in gradle like bellow

sourceSets {
    main {
        res.srcDirs =
                [
                        'src/main/res', 'src/main/drawable/button_icons', 'src/main/res/drawable/button_icons',

                        'src/main/res', 'src/main/layouts/user', 'src/main/res/layouts/user',
                        'src/main/res/layouts', 'src/main/layouts/user', 'src/main/res/layouts/user/register',
                        'src/main/res/layouts', 'src/main/layouts/user', 'src/main/res/layouts/user/login',
                        'src/main/res/layouts', 'src/main/layouts/user', 'src/main/res/layouts/user/profile',
                        'src/main/res/layouts', 'src/main/layouts/user', 'src/main/res/layouts/user/wallet',

                        'src/main/res/layouts/splash_layouts', 'src/main/res/layouts', 'src/main/res',

                        'src/main/res/layouts/main_layouts', 'src/main/res/layouts', 'src/main/res',
                        'src/main/res/layouts/main_layouts/sellers', 'src/main/res/layouts/main_layouts', 'src/main/res/layouts',

                        'src/main/res/layouts/dashboard_layouts', 'src/main/res/layouts', 'src/main/res',

                        'src/main/res/layouts/basket_layouts', 'src/main/res/layouts', 'src/main/res',
                        'src/main/res/layouts/factor_layouts', 'src/main/res/layouts', 'src/main/res',

                        'src/main/res/layouts/setting_layouts', 'src/main/res/layouts', 'src/main/res',
                ]
    }

}

So I put all the layouts in the main layout directory and delete other sub layout directories

Undershoot answered 19/3, 2020 at 21:11 Comment(0)
O
1

This seems to be fixed with Android studio 3.6.3. Although

viewBinding.enabled = true

worked for me as well instead of

viewBinding {
    enabled = true
}
Overgrowth answered 18/4, 2020 at 9:9 Comment(2)
Please give some context to this. What is this code. Where does it go?Slicker
In your gradle file, in android block android { ... }Overgrowth
A
1

the important thing that google doesn't refer in its websiet is you must convert your layout to data binding layout like this :

enter image description here

also you'd better visit this website https://developer.android.com/codelabs/android-databinding#2

Aeromechanics answered 26/6, 2021 at 20:47 Comment(1)
I had this problem with auto-generated activity: the layout files were just not generated with this tag and thus the databinding class was not generated in the right place. Since I also generated the activity in a submodule, I had to correct the paths to the auto-generated binding classes (remove submodule path)Indocile
R
0

Try re-building project and see whether data binding folder is available in generated files

Revise answered 25/2, 2020 at 11:51 Comment(0)
B
0

Also happened to me. This is because in AS 3.6.0, we can't access binding from another module if we use include tag with android:id. I think this error is from the IDE because i can run the project successfully. The only thing to do is wait for the fix or just ignore the error.

Bombproof answered 26/2, 2020 at 11:40 Comment(0)
U
0

It happened to me too. I just upgraded Graddle version to 3.6.0 on project build.graddle file and now it's working again.

Unskilled answered 27/2, 2020 at 10:28 Comment(0)
P
0

be sure you add the following tag in the XML file:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">

<ImageView
    android:id="@+id/userIMG"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_gravity="center"
    android:scaleType="fitCenter"
    android:layout_centerInParent="true"
    android:src="@drawable/logo"/>


    </LinearLayout>
     </layout>
Pedagogics answered 18/8, 2021 at 12:41 Comment(0)
J
-1

Starting from Android Gradle Plugin 4.0.0-alpha05 there is a new block called buildFeatures to enable build features.

buildFeatures {
    dataBinding true
    viewBinding true // for view binding:
}

and you need viewBinding true to solve your problem.

Jalisajalisco answered 15/9, 2020 at 9:14 Comment(1)
I'm also facing some issue with ViewBinding, it would be great if you can check and suggest me something here #66872090Peninsula

© 2022 - 2024 — McMap. All rights reserved.