LoginSignup
2
0

More than 1 year has passed since last update.

Android10以上でError inflating class androidx.appcompat.widget.FitWindowsLinearLayoutと出てクラッシュする対策

Posted at

こんにちは。もぐめっとです。

本日は表題のようなエラーが出てActivityが立ち上がらずcrashしていたのでその対策について記載します。

どんなエラー?

こんなエラーが発生していました。

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
uk.co.chrisjenx.calligraphy.ReflectionUtils.getValue (ReflectionUtils.java:29)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.createCustomViewInternal (CalligraphyLayoutInflater.java:203)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.access$000 (CalligraphyLayoutInflater.java:20)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$PrivateWrapperFactory2.onCreateView (CalligraphyLayoutInflater.java:302)
android.view.LayoutInflater$FactoryMerger.onCreateView (LayoutInflater.java:239)
android.view.LayoutInflater.inflate (LayoutInflater.java:659)
uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate (CalligraphyLayoutInflater.java:60)
android.view.LayoutInflater.inflate (LayoutInflater.java:534)
androidx.appcompat.app.AppCompatActivity.setContentView (AppCompatActivity.java:195)
...

具体的な原因はこのエラーの模様

Caused by android.view.InflateException
Binary XML file line #23 in com.hoge:layout/abc_screen_simple: Error inflating class androidx.appcompat.widget.FitWindowsLinearLayout

最近アプリをアップデートする際に一気にライブラリなどもアップグレードしたのですが、それをえいやとリリースしたらAndroid10以上で発生していました(自分の端末はAndroid8だったため気づかなかった)

対策

ぐぐったら下記に答えがありました。

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'

calligraphyをアップデートしろってことですね

これにアップデートすると書き方も新しく書き直さないと行けないです。

Install

Activity.kt
@Override
public void onCreate() {
    super.onCreate();
    ViewPump.init(ViewPump.builder()
        .addInterceptor(new CalligraphyInterceptor(
                new CalligraphyConfig.Builder()
                    .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
                    .setFontAttrId(R.attr.fontPath)
                    .build()))
        .build());
    //....
}

Inject

Activity.kt
@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
}

これで無事に治ります。

再発防止策

ではどうすれば起きてなかったというところを考えると、FirebaseのTest Labを使ったり、Play Consoleのリリース前レポートをちゃんと確認していれば早期に発見できていたかもしれません。
あとは、10%リリースなどちょっとずつリリースすることによってユーザへの被害も最小限に抑えられたかもしれませんね。

まとめ

ライブラリをアップデートした時は慎重にリリースしよう!

最後に、ワンナイト人狼オンラインというゲームを作ってます!よかったら遊んでね!

他にもCameconOffchaといったサービスも作ってるのでよかったら使ってね!

また、チームビルディングや技術顧問、Firebaseの設計やアドバイスといったお話も受け付けてますので御用の方は弊社までお問い合わせください。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0