在Android Studio中对不同的applicationId使用不同的构建变体时,自定义视图会给出膨胀错误

问题描述

我的代码中没有几个自定义视图,并且正在布局文件中使用它们。对于此处的ExpandableAppBarBehavior,请参见AppBArLayout

  <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:expanded="false"
        android:background="#1CF2F2"
        app:layout_behavior=".views.ExpandableAppBarBehavior"
        >

到目前为止,它仍然可以正常工作,但是当我使用新的applicationId com.example.flavor1创建新的样式时,它开始在运行时出现错误

要包含我放置的认软件包中的资源

javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["resourcePackageName": "com.example"]
            }
        }

在build.gradle

但是在运行时会出现错误

java.lang.RuntimeException: Could not inflate BehavIoUr subclass com.example.flavor1.views.ExpandableAppBarBehavior

您能告诉我我在做什么错吗?

解决方法

只是为了帮助某人,如果有人遇到相同的问题,我会通过提供Custom类的完整路径来解决它

 <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:expanded="false"
        android:background="#1CF2F2"
        app:layout_behavior="com.example.views.ExpandableAppBarBehavior"
        >

请记住,我们必须提供默认的applicationId。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...