Unable to solve incompatible with attribute error in android

久未见 提交于 2019-12-02 18:11:55

问题


I have a following error andI have no clue why this is happening.All I did was add the flag called "mon" and tried to add it to the custom view in the xml. flags other than "mon" works well. What is the meaning of this error? I would love to hear from you.

Android resource linking failed
Output:  samp/app/src/main/res/layout/layout_mon.xml:2: error: 'mon' is incompatible with attribute mon_type (attr) flags [sol=1, dan=4, tin=2] [weak].
error: failed linking file resources.

Command: /Users/me/.gradle/caches/transforms-1/files-1.1/aapt2-3.2.1-4818971-osx.jar/0c6f710daca8a09e3/aapt2-3.2.1-4818971-osx/aapt2 link -I\
        /Users/me/Library/Android/sdk/platforms/android-26/android.jar\
        --manifest\
      /Users/me/Documents/samp/app/build/intermediates/instant_run_merged_manifests/_stagingDebug/process_stagingDebugManifest/instant-run/AndroidManifest.xml\
        -o\
        /Users/me/Documents/samp/app/build/intermediates/processed_res/_stagingDebug/process_stagingDebugResources/out/resources-_stagingDebug.ap_\
        -R\
        @/Users/me/Documents/samp/app/build/intermediates/incremental/process_stagingDebugResources/resources-list-for-resources-_stagingDebug.ap_.txt\
        --auto-add-overlay\
        --java\
        /Users/me/Documents/samp/app/build/generated/not_namespaced_r_class_sources/_stagingDebug/process_stagingDebugResources/r\
        --custom-package\
        jp.aeonretail.aeon.kidsrepublic\
        -0\
        apk\
        --preferred-density\
        xxhdpi\
        --output-text-symbols\
        /Users/me/Documents/samp/app/build/intermediates/symbols/_st/debug/R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.1-4818971-osx Daemon #0

//inside the attrs

<declare-styleable name="MonView">
    <attr name="mon_type">
        <flag name="sol" value="0x01"/>
        <flag name="dan" value="0x02"/>
        <flag name="tin" value="0x04"/>
        <flag name="mon" value="0x06"/>
    </attr>
</declare-styleable>

//view

<?xml version="1.0" encoding="utf-8"?>
<example.MonView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mon_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:mon_type="mon"
</example.MonView>

回答1:


You declared the name of property but the type of input is not specified change your attrs to

<declare-styleable name="MonView">
<attr name="mon_type" format="flags">
    <flag name="sol" value="0x01"/>
    <flag name="dan" value="0x02"/>
    <flag name="tin" value="0x04"/>
    <flag name="mon" value="0x06"/>
</attr></declare-styleable>

Hope it helps :)




回答2:


I believe, you have a custom view of some kind that uses this attributes, something like MonView. Could you please provide the code of this View as well? It should be either a java or kotlin class. It seems that when you get your attributes on the runtime in your view that utilises them, it will try to map received attribute value to some preset array position or enum type inside you custom view type. Since you've only added the new attribute to the xml, but haven't updated the array (or enum, or just some logic with a switch/case, however it's implemented) you get this error. Hope, this will help. I'll be able to tell you more if there is a right code snippet. Cheers.



来源:https://stackoverflow.com/questions/53096484/unable-to-solve-incompatible-with-attribute-error-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!