[英]Custom Views giving inflation error when using different build variants with different applicationId in Android Studio
I have few custom views in my code and I am using them in layout files.我的代码中几乎没有自定义视图,我在布局文件中使用它们。 For ex- ExpandableAppBarBehavior here in AppBArLayout对于 AppBArLayout 中的前 ExpandableAppBarBehavior
<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"
>
It was working fine till now, but when I created a new flavor with new applicationId com.example.flavor1 then it started giving error at runtime.到目前为止它工作正常,但是当我使用新的 applicationId com.example.flavor1 创建一个新的 flavor 时,它开始在运行时出错。
To include resources from default package I have put要包含来自默认 package 的资源,我已将
javaCompileOptions {
annotationProcessorOptions {
arguments = ["resourcePackageName": "com.example"]
}
}
in build.gradle在 build.gradle
But in runtime its giving an error:但在运行时它给出了一个错误:
java.lang.RuntimeException: Could not inflate Behaviour subclass com.example.flavor1.views.ExpandableAppBarBehavior
Could you please tell me what I am doing wrong here?你能告诉我我在这里做错了什么吗?
Just to help someone, if someone got stuck with same issue, I resolve it by providing full path of Custom class只是为了帮助某人,如果有人遇到同样的问题,我通过提供自定义 class 的完整路径来解决它
<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"
>
Here to keep in mind, we have to provide default applicationId.这里要记住,我们必须提供默认的 applicationId。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.