androidcustom-keyboardandroid-input-method

XmlPullParserException: Meta-data does not start with input-method tag (Android custom keyboard)


While working on another project, I noticed an exception pop up in logcat for a previous test keyboard I had made (based on the Going On section of this answer). It is installed on my phone, but it was not the project I was currently running.

XmlPullParserException: Meta-data does not start with input-method tag

I retested the keyboard and it still works, so it doesn't seem to be a big problem. However I don't like to leave errors if I can help it.

I couldn't find any other SO questions related to this but I did find where it is called in the source code for InputMethodInfo:

String nodeName = parser.getName();
if (!"input-method".equals(nodeName)) {
    throw new XmlPullParserException(
            "Meta-data does not start with input-method tag");
}

What would cause this error to happen?

Supplemental Code

InputMethodService

public class WodeInputMethodService extends InputMethodService implements ImeContainer.OnSystemImeListener {

    @Override
    public View onCreateInputView() {
        LayoutInflater inflater = getLayoutInflater();
        ImeContainer jianpan = (ImeContainer) inflater.inflate(R.layout.jianpan_yangshi,
                null, false);
        jianpan.showSystemKeyboardsOption("ᠰᠢᠰᠲ᠋ᠧᠮ");
        jianpan.setOnSystemImeListener(this);

        return jianpan;
    }

    @Override
    public InputConnection getInputConnection() {
        return getCurrentInputConnection();
    }

    @Override
    public void onChooseNewSystemKeyboard() {
        InputMethodManager im = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        if (im == null) return;
        im.showInputMethodPicker();
    }
}

The error is probably hiding deeper than this (like in the custom keyboard view or the library keyboard that it is inherited from), but because of the amount of code involved, I am asking a basic question first. If I find the answer or more relevant code, I will post an update.

Stack trace

04-26 10:30:13.466 855-880/? A/InputMethodManagerService: Unable to load input method ComponentInfo{net.studymongolian.jianpan/net.studymongolian.jianpan.WodeInputMethodService}
    org.xmlpull.v1.XmlPullParserException: Meta-data does not start with input-method tag
        at android.view.inputmethod.InputMethodInfo.<init>(InputMethodInfo.java:162)
        at com.android.server.InputMethodManagerService.buildInputMethodListLocked(InputMethodManagerService.java:2732)
        at com.android.server.InputMethodManagerService$MyPackageMonitor.onSomePackagesChanged(InputMethodManagerService.java:554)
        at com.android.internal.content.PackageMonitor.onReceive(PackageMonitor.java:402)
        at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:863)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.os.HandlerThread.run(HandlerThread.java:61)

Notes

This unfortunately isn't an MCVE question because I can't reproduce the problem. I also don't know the exact part of the code that is causing the problem. I am still asking the question, though, because someone familiar with the error could describe a specific situation that causes it.


Solution

  • I had the same problem, the correct way is to have a 'subtype' keyword in the method.xml, but it has to be the first element in the xml: before 'subclass' or 'settings'.

    <input-method xmlns:android="http://schemas.android.com/apk/res/android">
    
      <subtype android:label="French (FR)"
        android:imeSubtypeLocale="fr_FR"
        android:imeSubtypeMode="keyboard" />
    
      <!-- Specify the class name of the custom keyboard -->
      <subclass android:name=".MyKeyboard" />
    
      <!-- Specify the settings activity (optional) -->
      <settings android:activity="com.example.customkeyboard.KeyboardSettingsActivity" />
    
    </input-method>