style attribute 'attr/progressDrawable ' not find

風吹過wu發表於2018-10-22

Android Studio 升級到3.2.1版本,今天自定義ProgressBar的style的時候,我按照往常的方式編寫程式碼,但是始終編譯不過。下圖是錯誤日誌

Android resource linking failed
Output:  D:\workspaceAS\ScanAll\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:4148: error: style attribute 'attr/progressDrawable (aka com.wujie.scanall:attr/progressDrawable)' not found.
error: failed linking references.

Command: C:\Users\Administrator\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\697631d1c7974971c371d1bf31e811db\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
        D:\software\sdk\sdk\platforms\android-28\android.jar\
        --manifest\
        D:\workspaceAS\ScanAll\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
        -o\
        D:\workspaceAS\ScanAll\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
        -R\
        @D:\workspaceAS\ScanAll\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
        --auto-add-overlay\
        --java\
        D:\workspaceAS\ScanAll\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
        --custom-package\
        com.wujie.scanall\
        -0\
        apk\
        --output-text-symbols\
        D:\workspaceAS\ScanAll\app\build\intermediates\symbols\debug\R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0
複製程式碼

解決方法: 在attrs.xml中編寫如下程式碼即可

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="Theme">
        <attr name="progressDrawable" format="reference"/>
        <attr name="indeterminateDrawable" format="reference"/>
    </declare-styleable>

</resources>

複製程式碼

相關文章