1

My app crashes immediately with the error:

android.view.InflateException: Binary XML file line #11: Error inflating class android.support.text.emoji.widget.EmojiTextView

But this error only appears when I run my app on certain SDKs - works fine on SDKs that are >24

Kevin Toner
  • 11
  • 1
  • 5
  • Possible duplicate of [InflateException: Binary XML file line #8: Error inflating class ImageView](https://stackoverflow.com/questions/37621934/inflateexception-binary-xml-file-line-8-error-inflating-class-imageview) – Kai Mar 08 '19 at 23:43
  • Ok, fixed - I was concentrating too much on emojitextview (nothing to do with it). The issue was that my background resources were in drawable-24, so wouldn't work for APIs less than 24. Solution was simply to copy all resources and paste them into the plain drawable - ".../main/res/drawable" – Kevin Toner Mar 10 '19 at 22:39

2 Answers2

2

Am also faced same issue, now its fixed and working as expected in older devices.

Step - 1 : Need to add dependencies' as below :

implementation 'androidx.emoji:emoji:1.1.0'
implementation 'androidx.emoji:emoji-appcompat:1.1.0'
implementation 'androidx.emoji:emoji-bundled:1.1.0'

Step - 2 : Create Application class and add below code in your onCreate() method of Application class and add Application class into AndroidManifest.xml

// add below code in onCreate() method
val emojiConfig = BundledEmojiCompatConfig(this)
        emojiConfig.setReplaceAll(true)
            .registerInitCallback(object : InitCallback() {
                override fun onInitialized() {
                    Timber.d( "EmojiCompat initialized")
                }

                override fun onFailed(throwable: Throwable?) {
                    Timber.d("EmojiCompat initialization failed $throwable" )
                }
        })
    EmojiCompat.init(emojiConfig)

Step - 3 : Now you can add View in xml :

                   <androidx.emoji.widget.EmojiAppCompatTextView
                    android:id="@+id/tvEmoji"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:singleLine="true"
                    android:text="@string/str_following"
                    android:textColor="@color/colorLabelUse"
                    android:textSize="14sp" />

Step - 4 : Now you can create instance of view and its support all the emoji with backward compatibility. you can add as a emoji as string like below :

    private static final String EMOJI = "\uD83D\uDC69\u200D\uD83D\uDCBB";//‍
    // TextView variant provided by EmojiCompat library
    EmojiAppCompatTextView emojiTextView = findViewById(R.id.tvEmoji);
    emojiTextView.setText(getString(R.string.emoji_text_view, EMOJI));
    emojiTextView.setText(String.format("Emoji EditText %s",EMOJI));


==================ENJOY========================
Sathish Gadde
  • 1,453
  • 16
  • 28
-1

Just Add these after super.onCreate(...) whenever you usse EmojiTextView or EmojiEditText:

FontRequest fontRequest = new FontRequest(
  "com.google.android.gms.fonts",
  "com.google.android.gms",
  "Noto Color Emoji Compat",
  R.array.com_google_android_gms_fonts_certs);
EmojiCompat.Config config = new FontRequestEmojiCompatConfig(this, fontRequest);
EmojiCompat.init(config);