Pergunta

I'm attempting to add action bar action buttons to my action bar in my android app. Every time I add an action button to res/menu/(some xml file) I keep getting the error aapt:Return code 138. So even though eclipse says the error isn't because of my code, it must be because of my code. As whenever I add an action button to the xml files I created in the "menu" directory, the error pops up. According to this it has to do with not declaring my string in res/values/strings.xml. But even when I do declare my strings there, the error still pops up! This is simply infuriating. I'm going to include my menu and strings xml files below, in case their's something wrong their. If you need more information or have another question, feel free to ask.

strings.xml file

<resources>

        <string name="app_name">Beacon Portal</string>
    <string name="action_settings">Settings</string>
    <string name = "edit_item">Action Bar Icon Edit</string>
        <string name="hello_world">Hello world!</string>
        <string name="Fragment1">This is where the schedule goes when I get around to making that because it seems like some people want that</string>
        <string name="FragmentTab1">This is ViewPager Fragment Tab 1</string>
        <string name="FragmentTab2">This is ViewPager Fragment Tab 2</string>
        <string name="drawer_open">Open navigation drawer</string>
        <string name="drawer_close">Close navigation drawer</string>


        <!-- Nav Drawer Menu Items -->
        <string-array name="nav_drawer_items">
            <item >Schedule</item>
            <item >Homework Due</item>
            <item >Logout</item>

        </string-array>

        <!-- Nav Drawer List Item Icons -->
        <!-- Keep them in order as the titles are in -->
        <array name="nav_drawer_icons">
            <item>@drawable/ic_action_go_to_today</item>
            <item>@drawable/ic_action_duehomework</item>
            <item>@drawable/ic_action_logout</item>

        </array>

        <!-- Content Description -->
        <string name="desc_list_item_icon">Item Icon</string>

         <!-- general stuff -->

        <string name="userid_label">OpenMinds</string>

        <!-- titles -->
        <string name="title_activity_actionview">ActionView</string>
        <string name="title_activity_about">About</string>

        <!-- ActionBar -->
        <string name="edit">Edit Schedule</string>
        <string name="apply">Apply Edits</string>


      </resources>

menu_fragment_apply.xml (in res/menu/ )

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/actionViewApply"
        android:icon="@drawable/ic_action_agree"
        app:showAsAction="ifRoom"
        android:title="@string/apply"/>

</menu>
Foi útil?

Solução

The problem is

app:showAsAction="ifRoom"

That should be

android:showAsAction="ifRoom"

instead. Use app:showAsAction when you're using the app compat library, which I'm assuming you're not using here.

Outras dicas

I just resolved this issue.

It was caused by me deleting an image from the drawable folder when I still had a layout.xml file that referred to the deleted image.

I resolved the issue by performing a project wide search for the name of the deleted icon and removed all references to the missing icon. I then rebuilt the project and the error was gone.

Getting this error means your Android installation is likely corrupted in some way. Typically this error will occur on projects in particular cases such as generating a new icon or adding a new xml file. If you see this error in your "Problems" window after a clean, try closing and reopening Eclipse first, then try doing a Project => Clean.

If the same message persists, you may need to do a complete reinstallation of the ADT Bundle which includes Eclipse. You should delete the entire existing ADT bundle from your computer (including Eclipse and SDK folder) and re-download the bundle, extract the contents and re-setup from scratch. Users rarely experience this error after a total reinstall.

Reference: github.com wiki

So I never really figured out what the problem was, but a temporary fix I figured out was each time I added a new menu file, I would have to delete all the menu files including the new one and then clean and refresh. After that I would have to add all the menu files again and then clean and refresh and the error was gone. Really annoying, but at least this worked for me.

I was having this error because I defined a menu resource in a library project instead of in the main android app project.

Yet another reason why it might happen, is the Project Build Target (in Project Settings -> Android) set to a version too low, so the XML is incompatible with the tool that handles it.

I have just had this problem, manifest was minSdkVersion=9, targetSdkVersion=19, so Eclipse set the build target to 9. Resetting it to 14 made the problem disappear -- by then I had already made my subordinates look hard for some XML out of version control or some wrong ID ;)

I just met this issue these days in ADT for mac. Can't generate R file cause return code 138, and finally I resolve it by finding that a string is missing in String.xml files, and it's called in other code. Maybe you can try...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top