我的主题是否延伸Theme.MaterialComponents
?哦,是的,而且自从我开始使用任何新的 Material UI 东西以来就一直如此。如果这里的所有这些答案对您和对我一样无济于事,请做好准备:该This component requires that you specify a valid android:textAppearance attribute
错误可能与指定与您正在使用的主题同名的外部库有关,Android 根据随机决定使用哪一个android:theme
你的 build.gradle。就我而言,罪魁祸首在Mobile FFmpeg内部。
我在工作一周后开始遇到这个错误,而构建变体被设置为不同的产品风格,然后切换回原来的风格。同时发生了什么变化?经过彻底调查后,我发现构建在我一分为implementation 'com.arthenica:mobile-ffmpeg-min:4.2.2.LTS'
二之后就崩溃了,对于我实际使用它的每种产品风味,如下所示:
videoImplementation 'com.arthenica:mobile-ffmpeg-min:4.2.2.LTS'
mainImplementation 'com.arthenica:mobile-ffmpeg-min:4.2.2.LTS'
这足以触发This component requires that you specify a valid android:textAppearance attribute
风味main
,同时又能很好地提高风味video
。每个main
构建都崩溃了,因为我的应用程序的主题被命名AppTheme
并且 Mobile FFmpeg 清单也指定android:theme="@style/AppTheme"
了(这会影响到 4.2.2 的所有版本)。所以我重命名了我的主题,但这导致了一个与此处非常相似的构建错误:
https ://github.com/tanersener/mobile-ffmpeg/issues/206
Attribute application@theme value=(@style/ScryptedTheme) from AndroidManifest.xml:37:9-45
is also present at [com.arthenica:mobile-ffmpeg-https:4.2.LTS] AndroidManifest.xml:17:9-40 value=(@style/AppTheme).
Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:31:5-95:19 to override.
添加 say 后tools:replace="android:theme"
,一切都恢复了,原来的 MaterialComponents 错误消失了。
但是为什么一种口味可以,另一种口味不行呢?完全不知道。这要归功于 Google 倾向于将最疯狂的错误添加到“稳定”版本中。至少可以通过一些重构很容易地解决。
TL;博士
这就是问题所在:https ://github.com/tanersener/mobile-ffmpeg/issues/206
再加上当两个合并的清单指定具有相同名称的不同主题时,Android 将根据您的内容随机选择一个build.gradle
.
解决方案:将 a 添加tools:replace="android:theme"
到清单的<application>
标签并更改主题的名称。