Sepehr
Sepehr

Reputation: 1249

InflationX/Calligraphy Crash on Android 10

I increase my targetSdkVersion from 26 to 29 and face this Crash:

ReflectionUtils.java io.github.inflationx.viewpump.ReflectionUtils.getValue

enter image description here

About My App:

-App in java language

-not using android X

-targetSdkVersion 29

Current dependency in Gradle:

implementation 'io.github.inflationx:calligraphy3:3.0.0'
implementation 'io.github.inflationx:viewpump:1.0.0'

I also check out all of this below links but none of them help:

GitHubIssue35

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

GitHubIssue37

Crash on calligraphy library by chris Jenx for Android Q

I also upgrade my dependencies as below :

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

but then I get the following error:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/os/BuildCompat;
    at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.<init>(-ViewPumpLayoutInflater.kt:25)
    at io.github.inflationx.viewpump.ViewPumpContextWrapper$inflater$2.invoke(ViewPumpContextWrapper.kt:25)
    at io.github.inflationx.viewpump.ViewPumpContextWrapper$inflater$2.invoke(ViewPumpContextWrapper.kt:22)
    at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
    at io.github.inflationx.viewpump.ViewPumpContextWrapper.getInflater(Unknown Source:7)
    at io.github.inflationx.viewpump.ViewPumpContextWrapper.getSystemService(ViewPumpContextWrapper.kt:31)
    at android.view.LayoutInflater.from(LayoutInflater.java:229)
    at android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:167)
    at android.app.Activity.getSystemService(Activity.java:6146)
    at android.view.LayoutInflater.from(LayoutInflater.java:229)
    at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:346)
    at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:362)
    at android.app.Activity.attach(Activity.java:7246)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3055)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.os.BuildCompat" on path: DexPathList[[zip file "/data/app/ir.daal.app.debug-h0TdlfmBM6nnB6Tuy6emlg==/base.apk"],nativeLibraryDirectories=[/data/app/ir.daal.app.debug-h0TdlfmBM6nnB6Tuy6emlg==/lib/arm64, /data/app/ir.daal.app.debug-h0TdlfmBM6nnB6Tuy6emlg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at io.github.inflationx.viewpump.internal.-ViewPumpLayoutInflater.<init>(-ViewPumpLayoutInflater.kt:25) 
    at io.github.inflationx.viewpump.ViewPumpContextWrapper$inflater$2.invoke(ViewPumpContextWrapper.kt:25) 
    at io.github.inflationx.viewpump.ViewPumpContextWrapper$inflater$2.invoke(ViewPumpContextWrapper.kt:22) 
    at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81) 
    at io.github.inflationx.viewpump.ViewPumpContextWrapper.getInflater(Unknown Source:7) 
    at io.github.inflationx.viewpump.ViewPumpContextWrapper.getSystemService(ViewPumpContextWrapper.kt:31) 
    at android.view.LayoutInflater.from(LayoutInflater.java:229) 
    at android.view.ContextThemeWrapper.getSystemService(ContextThemeWrapper.java:167) 
    at android.app.Activity.getSystemService(Activity.java:6146) 
    at android.view.LayoutInflater.from(LayoutInflater.java:229) 
    at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:346) 
    at com.android.internal.policy.PhoneWindow.<init>(PhoneWindow.java:362) 
    at android.app.Activity.attach(Activity.java:7246) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3055) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:214) 
    at android.app.ActivityThread.main(ActivityThread.java:7050) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) 

I didn't found any docs about the restriction of usage of this versions of Calligraphy only on Android X

Is there any better way to solve this crash rather than decrease the targetSdkVersion to 28?

Upvotes: 3

Views: 4339

Answers (4)

Abraham
Abraham

Reputation: 29

I had the same issue. I solved it by the following code:

@Override
    protected void attachBaseContext(Context newBase) {

        //Implement this for api 28 and below
        if(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
            super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
        }
        //Or implement this for api 29 and above
        else {
            super.attachBaseContext(newBase);
        }
    }

Add the above code above onCreate function.

Upvotes: 2

Sepehr
Sepehr

Reputation: 1249

I finally increase minSdkVersion to 16 and use font-family :)) it was so much cleaner and flexible. https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml

Upvotes: 0

surga
surga

Reputation: 1671

This is might not the right solution for you but I gave up to Calligraphy requirement:

https://github.com/InflationX/Calligraphy/commit/35954922d735b38b76a6d2a0b460be8f7c8cc4a4

I realize that I need to update my application anyway to androidx. So this issue is fixed once I migrated to androidx:

https://developer.android.com/jetpack/androidx/migrate

Upvotes: 0

Spiker
Spiker

Reputation: 575

Hey you can directly use android:fontFamily="@font/aktiv_bold" attribute for Button, TextView, EditText ... to set a custom font, not required to use calligraphy or ViewPump.

            <Button
                ...
                android:fontFamily="@font/aktiv_bold"
                ...
                >
            </Button>

all your fonts should be placed in the font folder in res directory.

enter image description here

Upvotes: 2

Related Questions