在 Android 10 上崩溃(布局/abc_screen_simple 行 #17 中的 InflateException)

新手上路,请多包涵

我的应用程序从 Android 4.3 到 Android 9 Pie 都运行良好,但我的应用程序在 Android 10 (Q API 29) 上无法运行并崩溃。这是我的 logcat - 为什么会这样?

 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

这是我的 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>

更新

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' }

原文由 user11453013 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 953
2 个回答

更新 Calligraphy 到最新版本解决这个问题:链接: https ://github.com/InflationX/Calligraphy/issues/35

更具体地说,Calligraphy ViewPump 都需要更新:

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

从 Calligraphy 2 迁移到 3 需要一些代码更改;请参阅 Calligraphy 3 README 中的示例。

原文由 Truong Hieu 发布,翻译遵循 CC BY-SA 4.0 许可协议

您需要根据新版本更新书法版本并更改代码

您需要更改依赖项中的存储库

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

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

您需要更改 import from 的用法

import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

import io.github.inflationx.calligraphy3.CalligraphyConfig;

书法配置来自

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

ViewPump.init(ViewPump.builder()
            .addInterceptor(new CalligraphyInterceptor(
                    new CalligraphyConfig.Builder()

            .setDefaultFontPath(getResources().getString(R.string.bariol))
                            .setFontAttrId(R.attr.fontPath)
                            .build()))
            .build());

我使用的是 bariol 字体,您可以将其更改为您的字体。

& 新基地到

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

原文由 Nafees Khabir 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题