When I include an <xliff:g>
tag in a string used for a menu item title, I get the following crash on release builds when selecting the menu item:
java.lang.IllegalArgumentException: Invalid payload item type
at android.util.EventLog.writeEvent(EventLog.java)
at android.app.Activity.onMenuItemSelected(Activity.java:2610)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(SourceFile:372)
at android.support.v7.app.ActionBarActivity.superOnMenuItemSelected(SourceFile:244)
at android.support.v7.app.ActionBarActivityDelegateICS.onMenuItemSelected(SourceFile:164)
at android.support.v7.app.ActionBarActivity.onMenuItemSelected(SourceFile:130)
at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.onMenuItemSelected(SourceFile:308)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1059)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:156)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1287)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3078)
at android.widget.AbsListView$1.run(AbsListView.java:4161)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
I've seen similar questions about this issue and I see that this is a bug in Android (https://stackoverflow.com/a/23125023) which was fixed by commit 332944f8a0a001c1754ce3298edbb4246e53c8fb
.
While investigating the issue on an Android 4.0.4 device, during a development build I discovered that the crash does not occur when including an <xliff:g>
tag in a menu item title string, but it does occur during a release build. If I add HTML markup, such as <b>
, to a menu item title, the crash occurs on both development and release builds.
Since I'm including the <xliff:g>
tag in the menu item title string for translation purposes, I'd like to keep it there. The fact that the crash does not occur on development builds gives me hope that there is a workaround for the issue for release builds.
Is there some kind of processing done to remove <xliff:g>
tags from strings during a development build that does not get run during a release build? Or is there something else going on?
Update
I just discovered that if I run a release build twice, the crash does not occur. Steps to reproduce:
./gradlew clean
./gradlew assembleRelease
At this point, the crash occurs when tapping a menu item that has a title with an <xliff:g>
tag in it.
./gradlew assembleRelease
At this point, the crash does not occur. The resulting APK after the second release build is about 20k smaller than the first release build. Obviously the size difference will vary, but the point is there's a significant size difference. Running subsequent release builds produces a new APK with only a few bytes difference in size.
Can you file a tools bug for this in http://b.android.com ?