3

我将我的targetSdkVersion26增加到29并面对这个崩溃:

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

在此处输入图像描述

关于我的应用程序:

-Java语言的应用程序

- 不使用安卓 X

-targetSdkVersion 29 _

Gradle中的当前依赖项:

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

我还查看了以下所有链接,但它们都没有帮助:

GitHub问题35

Android 10 崩溃(layout/abc_screen_simple 第 17 行中的 InflateException)

GitHub问题37

chris Jenx for Android Q 的书法库崩溃

我还升级了我的依赖项,如下所示

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

但后来我收到以下错误:

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) 

我没有找到任何关于限制使用此版本的书法仅在Android X上的文档

有没有更好的方法来解决这个崩溃,而不是将targetSdkVersion降低到28

4

4 回答 4

1

我遇到过同样的问题。我通过以下代码解决了它:

@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);
        }
    }

在函数上面添加上面的代码onCreate

于 2020-09-02T01:19:37.093 回答
1

嘿,您可以直接使用android:fontFamily="@font/aktiv_bold"属性Button, TextView, EditText ...设置自定义字体,而不需要使用书法或 ViewPump。

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

你所有的字体都应该放在 res 目录下的字体文件夹中。

在此处输入图像描述

于 2019-12-04T08:12:48.567 回答
0

我终于将minSdkVersion增加到16并使用font-family :)) 它非常干净灵活https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml

于 2020-07-07T15:01:53.573 回答
0

这可能不是适合您的解决方案,但我放弃了书法要求:

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

我意识到无论如何我都需要将我的应用程序更新为 androidx。因此,一旦我迁移到 androidx,这个问题就得到了解决:

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

于 2019-12-04T07:34:21.143 回答