Error:(9) No resource identifier found for attribute 'XXXXX' in package 'XXXXX.

Error:(9) No resource identifier found for attribute ‘XXXX’ in package ‘XXXXXX’

studio编译报错,具体报错原因如下:

Information:Gradle tasks [:app:assembleDebug]
Error:(23) No resource identifier found for attribute 'halfVisibleItemCount' in package 'com.example.cb.test'
Error:(9) No resource identifier found for attribute 'halfVisibleItemCount' in package 'com.example.cb.test'
Information:BUILD FAILED in 2s
Error:org.gradle.process.internal.ExecException: Process 'command 'F:\sdk\build-tools\26.0.2\aapt.exe'' finished with non-zero exit value 1
Error:(16) No resource identifier found for attribute 'halfVisibleItemCount' in package 'com.example.cb.test'
Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing process F:\sdk\build-tools\26.0.2\aapt.exe with arguments {package -f --no-crunch -I F:\sdk\platforms\android-26\android.jar -M \\?\F:\studioworkpalce\Test\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S F:\studioworkpalce\Test\app\build\intermediates\res\merged\debug -m -J \\?\F:\studioworkpalce\Test\app\build\generated\source\r\debug -F F:\studioworkpalce\Test\app\build\intermediates\res\debug\resources-debug.ap_ --custom-package com.example.cb.test -0 apk --preferred-density xhdpi --output-text-symbols \\?\F:\studioworkpalce\Test\app\build\intermediates\symbols\debug --no-version-vectors}
Error:(16) No resource identifier found for attribute 'halfVisibleItemCount' in package 'com.example.cb.test'
F:\studioworkpalce\Test\app\build\intermediates\res\merged\debug\layout\layout_date.xml
Error:(23) No resource identifier found for attribute 'halfVisibleItemCount' in package 'com.example.cb.test'
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
F:\studioworkpalce\Test\Library\build\intermediates\bundles\debug\res\layout\layout_date.xml
Error:(9) No resource identifier found for attribute 'halfVisibleItemCount' in package 'com.example.cb.test'
Error:com.android.ide.common.process.ProcessException: Error while executing process F:\sdk\build-tools\26.0.2\aapt.exe with arguments {package -f --no-crunch -I F:\sdk\platforms\android-26\android.jar -M \\?\F:\studioworkpalce\Test\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S F:\studioworkpalce\Test\app\build\intermediates\res\merged\debug -m -J \\?\F:\studioworkpalce\Test\app\build\generated\source\r\debug -F F:\studioworkpalce\Test\app\build\intermediates\res\debug\resources-debug.ap_ --custom-package com.example.cb.test -0 apk --preferred-density xhdpi --output-text-symbols \\?\F:\studioworkpalce\Test\app\build\intermediates\symbols\debug --no-version-vectors}

根据提示,大概知道原因是应该自定义属性导致的,提示找不到自定义属性,下面就来讲我解决的过程。

1) 统一下build的版本,如compileSdkVersion,targetSdkVersion,v4,v7
2)查找自定义属性是否真的有报错信息里面的attribute “XXX”,没有的话从哪拷贝的就到原项目的attr.xml中拷贝过来。
3)确定下你的自定义属性是否指定了format类型,如果未指定就会报上面的错。(我报错的原因就是这个导致的)

 <declare-styleable name="HourAndMinutePicker">
        <attr name="halfVisibleItemCount" />
        <attr name="itemTextSize" />
        <attr name="itemTextColor" />
        <attr name="textGradual" />
        <attr name="selectedTextColor" />
        <attr name="selectedTextSize" />
        <attr name="itemWidthSpace" />
        <attr name="itemHeightSpace" />
        <attr name="zoomInSelectedItem" />
        <attr name="wheelCyclic" />
        <attr name="wheelCurtain" />
        <attr name="wheelCurtainColor" />
        <attr name="wheelCurtainBorder" />
        <attr name="wheelCurtainBorderColor" />
    </declare-styleable>

如上自定义属性,如果不指定format=“XXX”就会报错(studio3.0)以下版本好像没事,我升级3。0后才出现这样的问题。
既然不能少format类型,那就给它加上就可以了,如下

<declare-styleable name="HourAndMinutePicker">
       <attr name="halfVisibleItemCount" format="integer"/>
    <attr name="itemTextSize" format="dimension"/>
    <attr name="itemMaximumWidthText" format="string"/>
    <attr name="itemTextColor" format="color"/>
    <attr name="textGradual" format="boolean"/>
    <attr name="selectedTextColor" format="color"/>
    <attr name="selectedTextSize" format="dimension"/>
    <attr name="currentItemPosition" format="integer"/>
    <attr name="itemWidthSpace" format="dimension"/>
    <attr name="itemHeightSpace" format="dimension"/>
    <attr name="zoomInSelectedItem" format="boolean"/>
    <attr name="wheelCyclic" format="boolean"/>
    <attr name="wheelCurtain" format="boolean"/>
    <attr name="wheelCurtainColor" format="color"/>
    <attr name="wheelCurtainBorder" format="boolean"/>
    <attr name="wheelCurtainBorderColor" format="color"/>
    <attr name="indicatorText" format="string"/>
    <attr name="indicatorTextSize" format="dimension"/>
    <attr name="indicatorTextColor" format="color"/>
    </declare-styleable>

还有一个attrs.xml中最好只有一个name,如果有两个自定义属性有相同的name也可能会报错。

猜你喜欢

转载自blog.csdn.net/caobin_study/article/details/79612527