我将我的 targetSdkVersion 从 26 增加到 29 并面对这次崩溃:
ReflectionUtils.java io.github.inflationx.viewpump.ReflectionUtils.getValue
关于我的应用程序:
-使用 java 语言的应用
-不使用 android X
- targetSdkVersion 29
等级中的当前依赖项:
implementation 'io.github.inflationx:calligraphy3:3.0.0'
implementation 'io.github.inflationx:viewpump:1.0.0'
我还检查了以下所有链接,但这些链接都无济于事:
Crash on Android 10 (InflateException in layout/abc_screen_simple line #17)
Crash on calligraphy library by 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 ?
答案 0 :(得分: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
函数上方添加以上代码。
答案 1 :(得分:0)
这可能不是适合您的解决方案,但我放弃了书法要求:
https://github.com/InflationX/Calligraphy/commit/35954922d735b38b76a6d2a0b460be8f7c8cc4a4
我意识到无论如何我都需要将应用程序更新为androidx。因此,当我迁移到androidx后,此问题已修复:
答案 2 :(得分:0)
嘿,您可以直接使用android:fontFamily="@font/aktiv_bold"
的{{1}}属性来设置自定义字体,而不必使用书法或ViewPump。
Button, TextView, EditText ...
所有字体都应放在res目录的字体文件夹中。
答案 3 :(得分:0)
我最终将 minSdkVersion 增加到 16 ,并使用 font-family :))更干净和 flexible 。 https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml