My Android app using Crosswalk and Cordova is causing an exception during long-press events, caused by onCreateActionMode
in the Crosswalk bundled version of Chromium not finding a value for R.string.actionbar_textselection_title
.
In order to create a long-press context menu, Chromium is looking up the string associated with R.string.actionbar_textselection_title, which at that point is set to 0, which defined, and we get this exception on long-press:
W/ResourceType: No package identifier when getting value for resource number 0x00000000
W/System.err: android.content.res.Resources$NotFoundException: String resource ID #0x0
W/System.err: at android.content.res.Resources.getText(Resources.java:1137)
W/System.err: at android.content.res.Resources.getString(Resources.java:1231)
W/System.err: at android.content.Context.getString(Context.java:363)
W/System.err: at org.chromium.content.browser.WebActionModeCallback.onCreateActionMode(WebActionModeCallback.java:138)
W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2694)
W/System.err: at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2619)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
W/System.err: at android.view.View.startActionMode(View.java:4738)
W/System.err: at org.chromium.content.browser.ContentViewCore.startDefaultActionMode(ContentViewCore.java:2167)
W/System.err: at org.chromium.content.browser.ContentViewCore.startActionMode(ContentViewCore.java:2163)
W/System.err: at org.chromium.content.browser.ContentViewCore.showSelectActionMode(ContentViewCore.java:2133)
W/System.err: at org.chromium.content.browser.ContentViewCore.onSelectionEvent(ContentViewCore.java:2239)
W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:39)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err: at android.os.Looper.loop(Looper.java:146)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5487)
W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
W/System.err: at dalvik.system.NativeStart.main(Native Method)
A/chromium: [FATAL:jni_android.cc(233)] Check failed: false. Please include Java exception stack in crash report
A/libc: Fatal signal 6 (SIGABRT) at 0x00006c77 (code=-6), thread 27767
This is where the getString is done, in org/chromium/content/browser/WebActionModeCallback.java:
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setTitle(DeviceFormFactor.isTablet(getContext())
? getContext().getString(R.string.actionbar_textselection_title)
: null);
mode.setSubtitle(null);
mEditable = mActionHandler.isSelectionEditable();
mIsPasswordType = mActionHandler.isSelectionPassword();
mIsInsertion = mActionHandler.isInsertion();
createActionMenu(mode, menu);
return true;
}
During startup my app sometimes (not always) has these errors:
W/XWalkInternalResources: org.xwalk.core.R$styleableis not found.
W/XWalkInternalResources: org.xwalk.core.R$styleis not found.
W/XWalkInternalResources: org.xwalk.core.R$stringis not found.
W/XWalkInternalResources: org.xwalk.core.R$rawis not found.
W/XWalkInternalResources: org.xwalk.core.R$menuis not found.
W/XWalkInternalResources: org.xwalk.core.R$layoutis not found.
W/XWalkInternalResources: org.xwalk.core.R$idis not found.
W/XWalkInternalResources: org.xwalk.core.R$drawableis not found.
W/XWalkInternalResources: org.xwalk.core.R$dimenis not found.
W/XWalkInternalResources: org.xwalk.core.R$coloris not found.
W/XWalkInternalResources: org.xwalk.core.R$attris not found.
The main question is: why does R.string.actionbar_textselection_title not have a value? The string is defined in res/values/android_content_strings.xml:
<string name="actionbar_textselection_title">"Text selection"</string>
In my onCreate, this resource is available, so it's clearly being loaded:
getResources().getText(R.string.actionbar_textselection_title)
Log.d("FOO", (String) foo);
D/FOO: Text selection
Is this exception related to the context in which Chromium is trying to access the resource? Is there a remedy for this?
Pertinent information: Using Android API 22, build tools 23.0.3, embedding xwalk_core_library_java.jar 20.50.533.12 build as a dependency in Gradle, libxwalkcore.so under jniLibs for ARM and X86 devices, Crosswalk plugin files for Cordova in src/org/crosswalk/engine.
I have a sprawling app that grew organically over several years, containing a lot of code I can't share, so I can only supply bite-sized portions of code and config files.