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

10

96

My application works fine from Android 4.3 until Android 9 Pie, but my application doesn't work on Android 10 (Q API 29) and crashes. This is my logcat - why this is happening?

java.lang.RuntimeException: Unable to start activity 
     ComponentInfo{ir.mahdi.circulars/ir.mahdi.circulars.MainActivity}: 
     android.view.InflateException: Binary XML file line #17 
     in ir.mahdi.circulars:layout/abc_screen_simple: Binary XML file line #17 
     in ir.mahdi.circulars:layout/abc_screen_simple: 
         Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout

and this is my mainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:layoutDirection="ltr"
    tools:context=".MainActivity">


</androidx.coordinatorlayout.widget.CoordinatorLayout>

update

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    } }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }
Virtuosity answered 10/6, 2019 at 10:46 Comment(7)
use this lib com.google.android.material:material:1.0.0-rc01 insted of com.google.android.material:material:1.0.0Tumid
@MilanPansuriya not workVirtuosity
Please, share your whole error log... Usually, the real reason in these cases are mentioned at the end of the crash traceMarbut
@W0rmH0le i found problem, it came from calligraphy library so i fixed it by removing itVirtuosity
@git, any other way rather than removing Calligraphy? I couldn't find a solution for the issue but find this library handy for fonts, any idea?Sulphuryl
For me, this is happening with, more or less, the same gradle config but I can't understand why this runs in devices with android P but doesn't works in devices with android Q...Recife
My project does not use Calligraphy but I still face this exact issue on Android 10, anyone face the same issue with me? I tried to add calligraphy3:3.1.1 and viewpump:2.0.3 but it still happen.Consignor
D
138

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.

Diogenes answered 12/8, 2019 at 13:57 Comment(4)
Update: actually it is quite trivial to update to Calligraphy 3; the code snippets in the README make it straightforward. But thing is, at least in our case the Calligraphy update didn't help: still getting InflateException with layout/abc_screen_simple after that.Mid
@Mid hmm.. very strange. Maybe some standalone modules in your app still have old dependencies to Calligraphy? Did you try to check transitive dependencies in gradle, maybe you'll see something strange?Bulgaria
@KonstantinKuznetsov: Thanks a lot! I checked :app:dependencies and saw that calligraphy3:3.1.1 was depending on viewpump:1.0.0. That was because in our build files we only had explicit dependency on Calligraphy. Adding viewpump:2.0.3 explicitly fixes this!Mid
I took the liberty to edit the missing info into the answer.Mid
B
67

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));
Bluebottle answered 7/8, 2020 at 9:51 Comment(4)
Thanks @Nafees Khabir very clear solution.Convery
Thanks @Nafees Khabir very clear solution you really saved me more than you can thinkMcnary
@ SHahi SHiva , @Mcnary I faced this issue so shared the solution hereBluebottle
thank you again then , really helped, tried so much solutions but with no chances, hope your life be easier like what you made for my day :)Mcnary
J
20
 Please follow 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));
        }
Jacquez answered 7/4, 2020 at 9:12 Comment(1)
This solution was explained properly and it solved the issueLyonnesse
R
9

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

Recife answered 27/7, 2019 at 12:17 Comment(1)
In all likelihood, Calligraphy dependency has been added in a project for a reason. No need to remove it; updating to Calligraphy 3 also fixes the InflateException issue: https://mcmap.net/q/217762/-crash-on-android-10-inflateexception-in-layout-abc_screen_simple-line-17Mid
G
8

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'
Gabrielson answered 26/10, 2019 at 11:32 Comment(0)
A
4

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

Algonkian answered 26/11, 2019 at 3:14 Comment(0)
C
2

You can change buildTools version and sdk version from 29 to 28

    targetSdk = 28
    compileSdk = 28
    buildTools = '28.0.3'
Chipmunk answered 23/6, 2019 at 13:20 Comment(2)
This is a workaround, but at some point you'll want to update targetSdk to 29 in any case, and you'll need to properly deal with the issue.Mid
Only targetSdk must be 28, compileSdk and buildTools can be 29, but this is temporarily solutionJonquil
S
2

This dependency implementation 'com.ice.restring:restring:1.0.0' also causes this crash if targetSdkVersion equals to 29 or higher,

so if you have this dependency (implementation 'com.ice.restring:restring:1.0.0') in your gradle you can solve this problem by removing it or using another lib that work with targetSdkVersion 29

Swot answered 31/12, 2020 at 12:4 Comment(0)
O
1

When faced with this issue, just update the calligraphy and viewpump in your app gradle to the latest version. Presently, the current version is: implementation 'io.github.inflationx:calligraphy3:3.1.1' implementation 'io.github.inflationx:viewpump:2.0.3'

Outwork answered 17/10, 2019 at 13:51 Comment(0)
P
1

Update your calligraphy import in your build.gradle(:app) file with this below

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

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

and use ViewPumpContextWrapper instead of CalligraphyContextWrapper

Pestiferous answered 25/11, 2020 at 11:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.