Android resource compilation failed in v3.2

血红的双手。 提交于 2019-11-27 16:00:50

问题


So I updated my Android Studio to v3.2. When I tried compiling the project, build fails. Below is the error:

Android resource compilation failed
    Output:  C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:900: error: <item> inner element must either be a resource reference or empty.

    Command: C:\Users\Ashish\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\7f1fbe9171e916e5044000cd76b749c8\aapt2-3.2.0-4818971-windows\aapt2.exe compile --legacy \
            -o \
            C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\res\merged\debug \
            C:\Users\Ashish\AndroidStudioProjects\StartUp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml
    Daemon:  AAPT2 aapt2-3.2.0-4818971-windows Daemon #0

Please do tell if there is any more information required. Any help will be appreciated.


回答1:


I was facing this issue today after updating gradle from 3.1.4 to 3.2.0. I don't know why, but the build started to throw that exception. i deleted the build folder, and deleted the gradle caches folder but nothing worked, so i looked at the merged values.xml and turns out that my ids.xml was defining a wrong id that was being merged to the values.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="downloading_package" type="id">Baixando pacote de sincronização</item>
</resources>

And apparently this was working before the update... for my case i deleted the ids.xml file (it was useless in the project)

I wish i could know why before the update everything was working




回答2:


the <item> in values.xml at line 900 ...might be of resource-type id.

the correct syntax would be (just as the error message tells):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item type="id" name="id_name" />
</resources>

see the documentation.




回答3:


I'm just finishing this issue a few minutes ago, try to modify or delete id.xml, if you think you don't have it, try to find in another module in your app. I change my value resource from <item name="header_view" type="id">header_view</item> to <item name="header_view" type="id"/> and it worked for me.




回答4:


i also meet the problem,you just need to find where the values in,and update it from <item type="id" name="id_name" >id_name</item> to <item type="id" name="id_name" />,now it's ok.




回答5:


in your build gradle(Project:name) do it like that

classpath 'com.android.tools.build:gradle:3.+'

then rebuild your project .. after that it will show message to update your gradle from 4.6 to 4.10




回答6:


In my case

<?xml version="1.0" encoding="utf-8"?>

is repeated twice in the XML. Make sure it should be one per a file at the top of the XML.




回答7:


This is what worked for me:

In my build.gradle file > dependencies, I was implementing a newer version of appcompat library

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:support-v4:21.0.3'
   implementation 'com.android.support:appcompat-v7:21.0.3'
   implementation 'androidx.appcompat:appcompat:1.0.2'}

After commenting //implementation 'androidx.appcompat:appcompat:1.0.2' It worked fine. I would suggest, even if it's a different library, Please check the version you are using.




回答8:


For me I had the layout width and layout height in the layout view and the LinearLayout view for databinding. and this threw a duplicate error. I fixed this by removing the set of attributes in the ''. layout file used for databinding



来源:https://stackoverflow.com/questions/52503768/android-resource-compilation-failed-in-v3-2

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