Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

android - Data binding class not generated in latest studio 3.6

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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' //<--
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...