報錯:👇👇
The layout "activity_main" in layout has no declaration in the base layout folder; this can lead to crashes when the resource is queried in a configuration that does not match this qualifier.
詳情:
If a resource is only defined in folders with qualifiers like -land or -en, and there is no default declaration in the base folder (layout or values etc), then the app will crash if that resource is accessed on a device where the device is in a configuration missing the given qualifier. As a special case, drawables do not have to be specified in the base folder; if there is a match in a density folder (such as drawable-mdpi) that image will be used and scaled. Note however that if you only specify a drawable in a folder like drawable-en-hdpi, the app will crash in non-English locales. There may be scenarios where you have a resource, such as a -fr drawable, which is only referenced from some other resource with the same qualifiers (such as a -fr style), which itself has safe fallbacks. However, this still makes it possible for somebody to accidentally reference the drawable and crash, so it is safer to create a default dummy fallback in the base folder. Alternatively, you can suppress the issue by adding tools:ignore="MissingDefaultResource" on the element. (This scenario frequently happens with string translations, where you might delete code and the corresponding resources, but forget to delete a translation. There is a dedicated issue id for that scenario, with the id ExtraTranslation.) Issue id: MissingDefaultResource
翻譯:
如果資源僅在具有-land或-en等限定符的文件夾中定義,並且基本文件夾(布局或值等)中沒有默認聲明,則如果在設備所在的設備上訪問該資源,則應用程序將崩潰在配置中缺少給定的限定符。
作為特殊情況,不必在基礎文件夾中指定drawable;如果密度文件夾(例如drawable-mdpi)中存在匹配,則將使用和縮放圖像。但請注意,如果您只在drawable-en-hdpi等文件夾中指定drawable,則應用程序將在非英語語言環境中崩潰。
在某些情況下,您可能會擁有一個資源,例如-fr drawable,它僅從具有相同限定符的某些其他資源(例如-fr樣式)引用,該資源本身具有安全回退。但是,這仍然可以讓某人意外地引用drawable和crash,因此在基礎文件夾中創建默認的虛擬回退更安全。或者,您可以通過在元素上添加工具:ignore =“MissingDefaultResource”來解決此問題。
(這種情況經常發生在字符串翻譯中,您可能會刪除代碼和相應的資源,但忘記刪除翻譯。該方案有一個專用的問題ID,ID為ExtraTranslation。)
解決方法:👇👇👇
添加
tools:ignore="MissingDefaultResource"
有前輩說重啟即可。遇到相同問題的小伙伴可以試一下昂~
不知道會不會有后遺症,后續若有解決方法來此編輯~望有大佬指示。
