19

When I updated compileSdkVersion to 30 then it starts showing error in my LoginActivity at the line where I called setContentView(See logs below)

2020-06-22 13:43:21.205 14538-14538/com.gravty.everyday W/gravty.everyda: Accessing hidden method Landroid/graphics/FontFamily;->()V (greylist-max-q, reflection, denied) 2020-06-22 13:43:21.206 14538-14538/com.gravty.everyday E/TypefaceCompatApi26Impl: Unable to collect necessary methods for class java.lang.NoSuchMethodException java.lang.NoSuchMethodException: android.graphics.FontFamily. [] at java.lang.Class.getConstructor0(Class.java:2332) at java.lang.Class.getConstructor(Class.java:1728) at androidx.core.graphics.TypefaceCompatApi26Impl.obtainFontFamilyCtor(TypefaceCompatApi26Impl.java:321) at androidx.core.graphics.TypefaceCompatApi26Impl.(TypefaceCompatApi26Impl.java:84) at androidx.core.graphics.TypefaceCompatApi28Impl.(TypefaceCompatApi28Impl.java:36) at androidx.core.graphics.TypefaceCompat.(TypefaceCompat.java:47) at androidx.core.graphics.TypefaceCompat.findFromCache(TypefaceCompat.java:76) at androidx.core.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:393) at androidx.core.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:361) at androidx.core.content.res.ResourcesCompat.getFont(ResourcesCompat.java:339) at androidx.appcompat.widget.TintTypedArray.getFont(TintTypedArray.java:119) at androidx.appcompat.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:430) at androidx.appcompat.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:204) at androidx.appcompat.widget.AppCompatTextView.(AppCompatTextView.java:105) at androidx.appcompat.widget.AppCompatTextView.(AppCompatTextView.java:95) at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182) at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103) at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407) at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457) at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1261) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1117) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082) at android.view.LayoutInflater.inflate(LayoutInflater.java:680) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.view.LayoutInflater.inflate(LayoutInflater.java:479) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161) at com.gravty.everyday.views.activities.LoginActivity.onCreate(LoginActivity.java:53) at android.app.Activity.performCreate(Activity.java:7989) at android.app.Activity.performCreate(Activity.java:7978)

Ankur Chitranshi
  • 395
  • 1
  • 4
  • 10
  • 1
    Show your code, and put error message into `code` brackets, please. – SkypeDogg Jun 22 '20 at 12:52
  • Same here. I know solution is to update, but I cannot do this (right now). Did you experience any negative impact? I don't see anything misbehave right now. (I know updating is the solution, but not possible atm) – AndyB Nov 02 '21 at 16:11

3 Answers3

38

I was also facing same error of FontFamily's method not found. Reason was

TypefaceCompatApi26Impl.class //it's library was missing

By adding stable version of core library implementation 'androidx.core:core:1.3.0' (https://developer.android.com/jetpack/androidx/releases/core) in gradle build file. It got fixed for me.

UPDATE: Those who are using Appcompat library instead core library can use stable version of Appcompat library i.e. androidx.appcompat:appcompat:1.3.1 (https://developer.android.com/jetpack/androidx/releases/appcompat#version_131_3) as mentioned by @Thiago

Ashish
  • 997
  • 6
  • 20
  • 2
    Any alternatives ?, for those who didn't migrate to androidx. – RaffMag Aug 25 '20 at 09:19
  • 1
    @Garci if you are facing same TypefaceCompatApi26Impl.class missing, then you can try adding 'com.android.support:support-compat:28.0.0' in your gradle file as per docs https://developer.android.com/topic/libraries/support-library/packages#v4, otherwise you need to debug to find missing class file. – Ashish Aug 26 '20 at 06:25
10

By upgrading the appCompat library to:

implementation 'androidx.appcompat:appcompat:1.2.0'

Has fixed my issue (same as yours)

Ryan Payne
  • 5,249
  • 4
  • 28
  • 69
Thiago
  • 12,778
  • 14
  • 93
  • 110
1

In my case I was forgotten my IDE in "Offline Mode" and the cache was cleared. So on app load custom fonts were missing and couldn't downloaded. By openning Offline Mode from Gradle -> Toggle Offline Mode, I was able to run my app successfully.