2019-05-24T04:07:42.000+09:00

`NoClassDefFoundError: Failed resolution of: Landroid/arch/lifecycle/Observer`というエラーが出たら

Androidアプリ起動時に、以下のようなエラーが出てる場合がある:

I/***: Rejecting re-init on previously-failed class java.lang.Class<android.databinding.ViewDataBinding$LiveDataListener>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/lifecycle/Observer;
        at void android.databinding.ViewDataBinding.<clinit>() (ViewDataBinding.java:120)
        at android.databinding.ViewDataBinding jp.voicy.app.player.DataBinderMapperImpl.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (DataBinderMapperImpl.java:246)
        at android.databinding.ViewDataBinding android.databinding.MergedDataBinderMapper.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (MergedDataBinderMapper.java:74)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.bind(android.databinding.DataBindingComponent, android.view.View, int) (DataBindingUtil.java:199)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean, android.databinding.DataBindingComponent) (DataBindingUtil.java:130)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean) (DataBindingUtil.java:95)
        at android.view.View com.arrvis.library.app.BaseFragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (BaseFragment.kt:67)
        at android.view.View android.support.v4.app.Fragment.performCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (Fragment.java:2261)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(android.support.v4.app.Fragment, int, int, int, boolean) (FragmentManager.java:1419)
        at void android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(android.support.v4.app.Fragment) (FragmentManager.java:1750)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(int, boolean) (FragmentManager.java:1819)
        at void android.support.v4.app.BackStackRecord.executeOps() (BackStackRecord.java:797)
        at void android.support.v4.app.FragmentManagerImpl.executeOps(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2590)
        at void android.support.v4.app.FragmentManagerImpl.executeOpsTogether(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2377)
        at void android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(java.util.ArrayList, java.util.ArrayList) (FragmentManager.java:2332)
        at boolean android.support.v4.app.FragmentManagerImpl.execPendingActions() (FragmentManager.java:2239)
        at void android.support.v4.app.FragmentManagerImpl.dispatchStateChange(int) (FragmentManager.java:3231)
        at void android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated() (FragmentManager.java:3181)
        at void android.support.v4.app.FragmentController.dispatchActivityCreated() (FragmentController.java:192)
        at void android.support.v4.app.FragmentActivity.onStart() (FragmentActivity.java:572)
        at void android.support.v7.app.AppCompatActivity.onStart() (AppCompatActivity.java:177)
        at void android.app.Instrumentation.callActivityOnStart(android.app.Activity) (Instrumentation.java:1391)
        at void android.app.Activity.performStart(java.lang.String) (Activity.java:7165)
        at void android.app.ActivityThread.handleStartActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions) (ActivityThread.java:2975)
        at void android.app.servertransaction.TransactionExecutor.performLifecycleSequence(android.app.ActivityThread$ActivityClientRecord, android.util.IntArray) (TransactionExecutor.java:180)
        at void android.app.servertransaction.TransactionExecutor.cycleToPath(android.app.ActivityThread$ActivityClientRecord, int, boolean) (TransactionExecutor.java:165)
        at void android.app.servertransaction.TransactionExecutor.executeLifecycleState(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:142)
        at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:70)
        at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1816)
        at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
        at void android.os.Looper.loop() (Looper.java:193)
        at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6718)
        at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
        at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
        at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:858)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.lifecycle.Observer" on path: DexPathList[[zip file "/data/app/***/base.apk"],nativeLibraryDirectories=[/data/app/***/lib/arm64, /system/lib64]]
        at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:134)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
        at void android.databinding.ViewDataBinding.<clinit>() (ViewDataBinding.java:120)
        at android.databinding.ViewDataBinding jp.voicy.app.player.DataBinderMapperImpl.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (DataBinderMapperImpl.java:246)
        at android.databinding.ViewDataBinding android.databinding.MergedDataBinderMapper.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (MergedDataBinderMapper.java:74)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.bind(android.databinding.DataBindingComponent, android.view.View, int) (DataBindingUtil.java:199)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean, android.databinding.DataBindingComponent) (DataBindingUtil.java:130)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean) (DataBindingUtil.java:95)
        at android.view.View com.arrvis.library.app.BaseFragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (BaseFragment.kt:67)
        at android.view.View android.support.v4.app.Fragment.performCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (Fragment.java:2261)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(android.support.v4.app.Fragment, int, int, int, boolean) (FragmentManager.java:1419)
        at void android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(android.support.v4.app.Fragment) (FragmentManager.java:1750)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(int, boolean) (FragmentManager.java:1819)
        at void android.support.v4.app.BackStackRecord.executeOps() (BackStackRecord.java:797)
        at void android.support.v4.app.FragmentManagerImpl.executeOps(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2590)
        at void android.support.v4.app.FragmentManagerImpl.executeOpsTogether(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2377)
        at void android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(java.util.ArrayList, java.util.ArrayList) (FragmentManager.java:2332)
        at boolean android.support.v4.app.FragmentManagerImpl.execPendingActions() (FragmentManager.java:2239)
        at void android.support.v4.app.FragmentManagerImpl.dispatchStateChange(int) (FragmentManager.java:3231)
        at void android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated() (FragmentManager.java:3181)
        at void android.support.v4.app.FragmentController.dispatchActivityCreated() (FragmentController.java:192)
        at void android.support.v4.app.FragmentActivity.onStart() (FragmentActivity.java:572)
        at void android.support.v7.app.AppCompatActivity.onStart() (AppCompatActivity.java:177)
        at void android.app.Instrumentation.callActivityOnStart(android.app.Activity) (Instrumentation.java:1391)
        at void android.app.Activity.performStart(java.lang.String) (Activity.java:7165)
        at void android.app.ActivityThread.handleStartActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions) (ActivityThread.java:2975)
        at void android.app.servertransaction.TransactionExecutor.performLifecycleSequence(android.app.ActivityThread$ActivityClientRecord, android.util.IntArray) (TransactionExecutor.java:180)
        at void android.app.servertransaction.TransactionExecutor.cycleToPath(android.app.ActivityThread$ActivityClientRecord, int, boolean) (TransactionExecutor.java:165)
        at void android.app.servertransaction.TransactionExecutor.executeLifecycleState(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:142)
        at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:70)
        at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1816)
        at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
        at void android.os.Looper.loop() (Looper.java:193)
        at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6718)
        at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
        at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
        at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:858)
I/***: Rejecting re-init on previously-failed class java.lang.Class<android.databinding.ViewDataBinding$LiveDataListener>: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/lifecycle/Observer;
        at void android.databinding.ViewDataBinding.<clinit>() (ViewDataBinding.java:120)
        at android.databinding.ViewDataBinding jp.voicy.app.player.DataBinderMapperImpl.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (DataBinderMapperImpl.java:246)
        at android.databinding.ViewDataBinding android.databinding.MergedDataBinderMapper.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (MergedDataBinderMapper.java:74)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.bind(android.databinding.DataBindingComponent, android.view.View, int) (DataBindingUtil.java:199)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean, android.databinding.DataBindingComponent) (DataBindingUtil.java:130)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean) (DataBindingUtil.java:95)
        at android.view.View com.arrvis.library.app.BaseFragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (BaseFragment.kt:67)
        at android.view.View android.support.v4.app.Fragment.performCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (Fragment.java:2261)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(android.support.v4.app.Fragment, int, int, int, boolean) (FragmentManager.java:1419)
        at void android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(android.support.v4.app.Fragment) (FragmentManager.java:1750)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(int, boolean) (FragmentManager.java:1819)
        at void android.support.v4.app.BackStackRecord.executeOps() (BackStackRecord.java:797)
        at void android.support.v4.app.FragmentManagerImpl.executeOps(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2590)
        at void android.support.v4.app.FragmentManagerImpl.executeOpsTogether(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2377)
        at void android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(java.util.ArrayList, java.util.ArrayList) (FragmentManager.java:2332)
        at boolean android.support.v4.app.FragmentManagerImpl.execPendingActions() (FragmentManager.java:2239)
        at void android.support.v4.app.FragmentManagerImpl.dispatchStateChange(int) (FragmentManager.java:3231)
        at void android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated() (FragmentManager.java:3181)
        at void android.support.v4.app.FragmentController.dispatchActivityCreated() (FragmentController.java:192)
        at void android.support.v4.app.FragmentActivity.onStart() (FragmentActivity.java:572)
        at void android.support.v7.app.AppCompatActivity.onStart() (AppCompatActivity.java:177)
        at void android.app.Instrumentation.callActivityOnStart(android.app.Activity) (Instrumentation.java:1391)
        at void android.app.Activity.performStart(java.lang.String) (Activity.java:7165)
        at void android.app.ActivityThread.handleStartActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions) (ActivityThread.java:2975)
        at void android.app.servertransaction.TransactionExecutor.performLifecycleSequence(android.app.ActivityThread$ActivityClientRecord, android.util.IntArray) (TransactionExecutor.java:180)
        at void android.app.servertransaction.TransactionExecutor.cycleToPath(android.app.ActivityThread$ActivityClientRecord, int, boolean) (TransactionExecutor.java:165)
        at void android.app.servertransaction.TransactionExecutor.executeLifecycleState(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:142)
        at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:70)
        at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1816)
        at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
        at void android.os.Looper.loop() (Looper.java:193)
        at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6718)
        at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
        at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
        at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:858)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.lifecycle.Observer" on path: DexPathList[[zip file "/data/app/***/base.apk"],nativeLibraryDirectories=[/data/app/***/lib/arm64, /system/lib64]]
        at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:134)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
        at void android.databinding.ViewDataBinding.<clinit>() (ViewDataBinding.java:120)
        at android.databinding.ViewDataBinding jp.voicy.app.player.DataBinderMapperImpl.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (DataBinderMapperImpl.java:246)
        at android.databinding.ViewDataBinding android.databinding.MergedDataBinderMapper.getDataBinder(android.databinding.DataBindingComponent, android.view.View, int) (MergedDataBinderMapper.java:74)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.bind(android.databinding.DataBindingComponent, android.view.View, int) (DataBindingUtil.java:199)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean, android.databinding.DataBindingComponent) (DataBindingUtil.java:130)
        at android.databinding.ViewDataBinding android.databinding.DataBindingUtil.inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean) (DataBindingUtil.java:95)
        at android.view.View com.arrvis.library.app.BaseFragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (BaseFragment.kt:67)
        at android.view.View android.support.v4.app.Fragment.performCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) (Fragment.java:2261)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(android.support.v4.app.Fragment, int, int, int, boolean) (FragmentManager.java:1419)
        at void android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(android.support.v4.app.Fragment) (FragmentManager.java:1750)
        at void android.support.v4.app.FragmentManagerImpl.moveToState(int, boolean) (FragmentManager.java:1819)
        at void android.support.v4.app.BackStackRecord.executeOps() (BackStackRecord.java:797)
        at void android.support.v4.app.FragmentManagerImpl.executeOps(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2590)
        at void android.support.v4.app.FragmentManagerImpl.executeOpsTogether(java.util.ArrayList, java.util.ArrayList, int, int) (FragmentManager.java:2377)
        at void android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(java.util.ArrayList, java.util.ArrayList) (FragmentManager.java:2332)
        at boolean android.support.v4.app.FragmentManagerImpl.execPendingActions() (FragmentManager.java:2239)
        at void android.support.v4.app.FragmentManagerImpl.dispatchStateChange(int) (FragmentManager.java:3231)
        at void android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated() (FragmentManager.java:3181)
        at void android.support.v4.app.FragmentController.dispatchActivityCreated() (FragmentController.java:192)
        at void android.support.v4.app.FragmentActivity.onStart() (FragmentActivity.java:572)
        at void android.support.v7.app.AppCompatActivity.onStart() (AppCompatActivity.java:177)
        at void android.app.Instrumentation.callActivityOnStart(android.app.Activity) (Instrumentation.java:1391)
        at void android.app.Activity.performStart(java.lang.String) (Activity.java:7165)
        at void android.app.ActivityThread.handleStartActivity(android.app.ActivityThread$ActivityClientRecord, android.app.servertransaction.PendingTransactionActions) (ActivityThread.java:2975)
        at void android.app.servertransaction.TransactionExecutor.performLifecycleSequence(android.app.ActivityThread$ActivityClientRecord, android.util.IntArray) (TransactionExecutor.java:180)
        at void android.app.servertransaction.TransactionExecutor.cycleToPath(android.app.ActivityThread$ActivityClientRecord, int, boolean) (TransactionExecutor.java:165)
        at void android.app.servertransaction.TransactionExecutor.executeLifecycleState(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:142)
        at void android.app.servertransaction.TransactionExecutor.execute(android.app.servertransaction.ClientTransaction) (TransactionExecutor.java:70)
        at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1816)
        at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:106)
        at void android.os.Looper.loop() (Looper.java:193)
        at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:6718)
        at java.lang.Object java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[]) (Method.java:-2)
        at void com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run() (RuntimeInit.java:493)
        at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:858)

なぜ起きるのか

これは単にLiveDataの関連クラスが含まれていないということ。つまり、当該のクラスを追加すればよい:

dependenceis {
    ...
    implementation "android.arch.lifecycle:livedata:1.1.1"
    ...
}