Android 日志中充斥着关于“资源<地址"、条目索引(<数字>)超出类型 entryCount(<数字>)"的警告. [英] Android log is littered with warnings regarding "resource <address>, entry index(<number>) is beyond type entryCount(<number>)"
问题描述
在编译(使用 Android Studio 4.1.1/Gradle 6.5/Android Gradle Plugin 4.1.0)并运行我的 Android 应用程序后,日志中充斥着如下警告:
After compiling (with Android Studio 4.1.1 / Gradle 6.5 / Android Gradle Plugin 4.1.0) and running my Android app the log is littered with warnings such as the following:
...
12-19 12:16:01.239 10869 10869 W ResourceType: For resource 0x7f12016b, entry index(363) is beyond type entryCount(184)
12-19 12:16:01.239 10869 10869 W ResourceType: For resource 0x7f12016c, entry index(364) is beyond type entryCount(184)
12-19 12:16:01.239 10869 10869 W ResourceType: For resource 0x7f120275, entry index(629) is beyond type entryCount(184)
12-19 12:16:01.239 10869 10869 W ResourceType: For resource 0x7f120274, entry index(628) is beyond type entryCount(184)
12-19 12:16:01.250 10869 10869 W ResourceType: For resource 0x7f120248, entry index(584) is beyond type entryCount(184)
...
使用命令 "C:\AndroidSDK\build-tools\29.0.2\aapt2 转储作为 .apk 文件一部分的
允许我将这些十六进制地址映射到实际资源名称.映射上面显示的这些地址表明以下资源是这些警告的来源:resource.arsc
文件的内容.exe"转储资源 myApp.apk >myApp.resources.txt
Dumping the content of the resource.arsc
file that is part of the .apk file using the command "C:\AndroidSDK\build-tools\29.0.2\aapt2.exe" dump resources myApp.apk > myApp.resources.txt
allows me to map those hex addresses to actual resource names. Mapping those addresses shown above reveals that the following resources are the source of those warnings:
...
resource 0x7f12016b -> style/TextAppearance.AppCompat.SearchResult.Subtitle
resource 0x7f12016c -> style/TextAppearance.AppCompat.SearchResult.Title
resource 0x7f120275 -> style/Widget.AppCompat.Toolbar.Button.Navigation
resource 0x7f120274 -> style/Widget.AppCompat.Toolbar
resource 0x7f120248 -> style/Widget.AppCompat.Light.ActionBar.Solid
...
因此,由于 Google 的 androidx.appcompat
库,这些资源最终会出现在我的应用中.
So, these are resources that end up in my app due to Google's androidx.appcompat
library.
检查 resources.txt 文件作为构建的一部分写入的内容显示了有关这些资源的以下条目:
Checking the resources.txt file that gets written as part of a build reveals the following entries about those resources:
...
Marking style:TextAppearance_AppCompat_SearchResult_Subtitle:2131886443 used because its prefix matches string pool constant TextAppearance
Marking style:TextAppearance_AppCompat_SearchResult_Title:2131886444 used because its prefix matches string pool constant TextAppearance
style:Base_Widget_AppCompat_Toolbar_Button_Navigation:2131886298 => [attr:controlBackground:2130968810]
style:Widget_AppCompat_Toolbar:2131886708 => [style:Base_Widget_AppCompat_Toolbar:2131886297]
style:Widget_AppCompat_Light_ActionBar_Solid:2131886664 => [style:Base_Widget_AppCompat_Light_ActionBar_Solid:2131886269]
...
为了确保所有资源实际上都是 .apk 文件的一部分,我使用 Android Studio 的 APK 分析器,但我看不出任何可疑之处.
And just to be really sure that all resources are actually part of the .apk file I inspected the .apk file using Android Studio's APK Analyzer but I could see nothing suspicious.
因此,我检查了我在 Android 源代码中可以找到的内容,并发现了以下内容 Android C++ 源代码:
So, I checked what I could find in the Android source code and came across the following Android C++ source code:
// Check that the entry idx is within range of the declared entry count (ResTable_typeSpec).
// Particular types (ResTable_type) may be encoded with sparse entries, and so their
// entryCount do not need to match.
if (static_cast<size_t>(realEntryIndex) >= typeSpec->entryCount) {
ALOGW("For resource 0x%08x, entry index(%d) is beyond type entryCount(%d)",
Res_MAKEID(packageGroup->id - 1, typeIndex, entryIndex),
entryIndex, static_cast<int>(typeSpec->entryCount));
// We should normally abort here, but some legacy apps declare
// resources in the 'android' package (old bug in AAPT).
continue;
}
但是,我不确定该代码的上下文,或者它或它的注释试图告诉我什么.
However, I'm not sure about the context of that code or what it or its comment are trying to tell me.
作为参考,以下 build.gradle
设置用于构建应用程序:
For reference, the following build.gradle
settings are used to build the app:
android
{
compileSdkVersion 29
buildToolsVersion "29.0.2"
...
defaultConfig
{
minSdkVersion 16
targetSdkVersion 29
...
}
...
}
有没有人知道如何处理这个警告?我知道这只是一个警告而不是错误,我可以忽略它.但它不必要地向 Android 的日志发送垃圾邮件,这就是我想摆脱它的原因.
Does anyone have any idea what to do about this warning? I know that it is just a warning and not an error and that I could ignore it. But it needlessly spams Android's log which is why I want to get rid of it.
这个问题并不新鲜.在此处和此处提出了类似问题a> 但可用的答案并不能解决这个问题.
That problem is not new. Similar questions have been asked here and here but the available answers don't resolve this problem.
推荐答案
我之前遇到过这个问题,真的很烦
I had this problem before is really annoying
我看到当我构建一个调试apk(不是应用程序包),并直接从手机(不是从android studio)安装它时,我没有在logcat中收到该警告消息,所以我认为这一定是一个问题构建捆绑包
I saw that when I built a debug apk (not an app bundle), and installed it directly from the phone (not from android studio) I didnt get that warning message in the logcat, so I thought it must be a problem with building a bundle
对我有用的解决方案是:
The solution that worked for me is:
- 在 Android Studio 中转到运行"->编辑配置"
- 在常规选项卡的安装选项中,将部署选项更改为默认 APK"
- 照常运行您的应用
希望这也能解决您的问题
Hope this solves your problem too
这篇关于Android 日志中充斥着关于“资源<地址"、条目索引(<数字>)超出类型 entryCount(<数字>)"的警告.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!