Android Studio 3.0 issue

I just upgraded to Android Studio 3.0 mid-way through chapter 13, after completing listing 13.7. Now I get a build error related to fragment_crime_list.xml:

Error:error: attribute 'res-auto:showAsAction' not found.
Error:attribute 'res-auto:showAsAction' not found.
Error:failed linking file resources.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
Failed to execute aapt

This is the relevant code:
<?xml version="1.0" encoding="utf-8"?>

    <item
        android:id="@+id/new_crime"
        android:icon="@drawable/ic_menu_add"
        android:title="@string/new_crime"
        app:showAsAction="ifRoom|withText"
        />
</menu>

I found a bunch of suggested fixes on S.O. but nothing that really solves or explains why this is happening. Any ideas?

I think, this line is your problem.

failed linking file resources.

AAPT (Android Asset Packaging Tool ) can compile resources. I think you should look at this.
I assume that your gradle is version 3.0.0. You can try,

android.enableAapt2=false in your gradle.properties file and restarting the Gradle.

I’m using android studio 3.0. But I don’t use the above code.Because I didn’t encounter this the problem.
Or you can check newly released.
And check this and this.

I tried setting enableAapt2 to false, and it still had errors.

Then I looked back at the code and realized I had made a mistake in the XML. What I typed:
xmlns:app="http://schemas.android.com/apk/res/res-auto"

And the correct way:
xmlns:app="http://schemas.android.com/apk/res-auto"

Thanks for the response :slight_smile:

Thanks a lottttttttttttttttttttttttttttttttttt…
Saved my hours…
it’s work for me…
it’s correct answer of aapt error…

Even though this has been solved already, I will still like to write about my general solution just to help others with similar issues

This error sometimes also comes as “Android resource linking failed” is another frequent and vague error in Android Studio. The solution sometimes could be quite boring and painful but I assure you, this error is absolutely nothing serious.

The Cause
The error shows up when Gradle encounters an error (Usually a syntax or typo error) in one or more of your XML files.

Most of the XML files are located in the res folder, however, you might still find some outside the res folder. For example, the AndroidManifest.xml located in “/src/main/AndroidManifest.xml”. Here is an example of a layout file that would give the “Error: failed linking file resources” error.

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient
        android:angle="90"
        android:centerColor="@color/colorPrimaryDark"
        android:endColor="@color/colorPrimaryDark"
        android:startColor="@color/colorPrimaryDark"
        android:endCollor="@color/colorPrimaryDark"
        android:type="linear" />
    <corners
        android:radius="10dp"/>
</shape>

Note the “android:endCollor” attribute.

Solution
The solution to the error is obvious, right? All you have to do is go through each of your XML files to figure out where the error might be. This could sometimes be time-consuming but be rest assured that the error will disappear as soon as you find and fix the problem XML.

Tips to finding the problem XML quickly

If you have a lot of XML files and it would be just too difficult to go through them one after the other, you could use the following tips to make the process easier:

  1. Undo: Most times, you are already halfway through a project before you experience this issue. Meaning that it was a recent change to one of your XML files that caused the issue. If that is the case, you can try to undo your recent change to the XML files. To undo, simply use the key combination: Ctrl+Z.

Some useful links