Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash on Android 10 (InflateException in layout/abc_screen_simple line #17)

Update Calligraphy to newest version to solve this problem: Link: https://github.com/InflationX/Calligraphy/issues/35

More specifically, both Calligraphy and ViewPump need to be updated:

implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'

Migrating from Calligraphy 2 to 3 requires some code changes; see examples in Calligraphy 3 README.


You need to update calligraphy version and change code according to new version

You need to change repository in dependencies from

implementation "uk.co.chrisjenx:calligraphy:$caligraphyVersion"

to

implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'

You need to change usage of import from

import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

to

import io.github.inflationx.calligraphy3.CalligraphyConfig;

Calligraphy config from

CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
               .setDefaultFontPath(getResources().getString(R.string.bariol))
               .setFontAttrId(R.attr.fontPath)
                .build())) 
                .build());

to

ViewPump.init(ViewPump.builder()
            .addInterceptor(new CalligraphyInterceptor(
                    new CalligraphyConfig.Builder()
                            
            .setDefaultFontPath(getResources().getString(R.string.bariol))
                            .setFontAttrId(R.attr.fontPath)
                            .build()))
            .build());

I used font bariol you can change it to yours.

& newbase to

super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));

Please foloow this below steps.
1> First of all check build.gradle(:app) file
2> If you are using  this below library:
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
3> Update this " implementation 'uk.co.chrisjenx:calligraphy:2.3.0' " library with this below library.
implementation 'io.github.inflationx:viewpump:2.0.3'
implementation 'io.github.inflationx:calligraphy3:3.1.1'
4> In project where You use this below code :
@Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }

5> Update it with this below code:

   @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
    }

Definitively your problem is the Calligraphy library, I've got the same problem and there are 2 ways to solve it:

  1. Go back to target version 28, and wait a possible update of the Calligraphy library. 2
  2. Remove the library

About the exception:

The exception error in Calligraphy comes from the use of the reflection in the library. See the last line of this exception:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example, PID: 8220
android.view.InflateException: Binary XML file line #17 in com.example:layout/abc_screen_simple: Binary XML file line #17 in com.example/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
Caused by: android.view.InflateException: Binary XML file line #17 in com.example/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference

Android in your documentation explain that some reflection methods (non-SDK interfaces) are restricted in the API 29 platform.

Reflection via Class.getDeclaredField() or Class.getField() --------> NoSuchFieldException thrown

Reflection via Class.getDeclaredMethod(), Class.getMethod() ----> NoSuchMethodException thrown.

Reflection via Class.getDeclaredFields(), Class.getFields() --------> Non-SDK members not in results.

Reflection via Class.getDeclaredMethods(), Class.getMethods() -> Non-SDK members not in results

Source: Restrictions on non-SDK interfaces


if you are using calligraphy so you should migrate to calligraphy3 : https://github.com/InflationX/Calligraphy

implementation 'io.github.inflationx:calligraphy3:3.1.1'
implementation 'io.github.inflationx:viewpump:2.0.3'

Migrate from chrisjenx/Calligraphy to InflationX/Calligraphy and update Calligraphy to newest version