最新Studio 3.6中未生成数据绑定类 [英] Data binding class not generated in latest studio 3.6

查看:113
本文介绍了最新Studio 3.6中未生成数据绑定类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我已将Android Studio 3.5.3更新为3.6.现在,我无法生成任何数据绑定类. Android Studio会自行生成数据绑定-iml文件.

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

项目级gradle文件:

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

应用级gradle文件:

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

以下是我的活动和XML文件: 活动:

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>

官方解决方案:

Google已解决此问题.使用android studio 3.6.2的新补丁更新后,我可以创建具有多个源集的数据绑定类

推荐答案

这也发生在我身上.绑定类实际上是生成的.该项目建设良好.只有Android Studio 3.6.1(或我不在乎的底层Gradle构建系统)存在错误,无法看到这些类.

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

如上文史蒂夫(Steve)所指出:同时,我们必须耐心等待Google对其进行修复...

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

编辑

我刚刚意识到它比我预期的多了许多错误,布局也被破坏了:

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

我希望Google尽快解决此问题...

I hope Google will fix this mess soon...

编辑2

我再次意识到,Android Studio 3.6甚至比上面描述的还要麻烦.

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

现有的Espresso测试的执行也被破坏了.

The execution of existing Espresso tests is broken too.

我强烈劝阻所有人不要升级到Android Studio 3.6.

I strongly discourage everyone from upgrading to Android Studio 3.6.

同时,我们可能会降级到Android Studio 3.5.

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

这篇关于最新Studio 3.6中未生成数据绑定类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆