My app has minSdk = 21 and targetSdk = 26
I wanted to set up the app shortcuts
I've added the <meta-data> tag to the first activity that's launched when the app starts.
<activity android:name=".SignInActivity"
            android:theme="@style/SubscriptionsTheme.NoActionBar">
            <intent-filter>
                <category android:name="android.intent.category.LAUNCHER" />
                <action android:name="android.intent.action.MAIN"/>
            </intent-filter>
            <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
        </activity>
Then I created the xml-v25 directory and within it this shortcuts.xml file:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
    <shortcut
        android:shortcutId="test"
        android:icon="@drawable/plus"
        android:shortcutShortLabel="test"
        android:shortcutLongLabel="long test" >
        <intent
            android:action="android.intent.action.VIEW"
            android:targetPackage="com.xxxxx.xxxxx.xxxxx"
            android:targetClass="com.xxxxx.xxxxx.xxxxxx.main" />
    </shortcut>
</shortcuts> 
when I try to build the app I get the following errors:
Error:error: 'long test' is incompatible with attribute android:shortcutLongLabel (attr) reference. Error:error: 'test' is incompatible with attribute android:shortcutShortLabel (attr) reference. Error:'long test' is incompatible with attribute android:shortcutLongLabel (attr) reference.
Hope this helps.
strings.xml
 <string name="long_shortcut">long test</string>
  <string name="short_shortcut">test</string>
Use reference of this strings in Manifest.xml
<shortcut
        android:shortcutId="test"
        android:icon="@drawable/plus"
        android:shortcutShortLabel="@string/short_shortcut"
        android:shortcutLongLabel="@string/long_shortcut" >
In java you can also assign this by using  setLongLabel (CharSequence longLabel) and  setShortLabel(CharSequence) of ShortcutInfo.Builder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With