3

Problem

Sometimes a crash caused by a ResourceNotFoundException is reported to me. This exception is caused at the launch of my app : the app seems to doesn't get a drawable resource in my first screen.

Environment

My drawable is a png and exists in mdpi, hdpi, xhdpi, xxhdpi and xxxhdpi. I'm using View Binding and Fragment to get my layout and the id of the drawable is specified in my xml

Side notes

I don't know if it's because of the first needed drawable or if all my drawables are absent, because it crashes at launch.

This exception happens rarely but enough to be observed, recently it happened on a Pixel 4 and a Galaxy A20s. I have personally never been able to reproduce this error.

Question

Is it possible that Play Store doesn't give drawables when a user downloads my app ? How can I be sure that drawables are presents in my app ?

Log

Here are log that I receive :

Caused by android.view.InflateException: Binary XML file line #25 in xx.xxx.xxx:layout/fragment_home: Error inflating class ImageView

and

Caused by android.content.res.Resources$NotFoundException: Resource ID #0x7f0800c7
       at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
       at android.content.res.Resources.getValue(Resources.java:1428)
       at androidx.appcompat.widget.ResourceManagerInternal.createDrawableIfNeeded(ResourceManagerInternal.java:176)
       at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:141)
       at androidx.appcompat.widget.ResourceManagerInternal.getDrawable(ResourceManagerInternal.java:132)
       at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:104)
       at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:63)
       at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:82)
       at androidx.appcompat.widget.AppCompatImageView.<init>(AppCompatImageView.java:69)
       at androidx.appcompat.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:199)
       at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:119)
       at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1551)
       at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1602)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:240)
       at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1059)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:995)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
       at xx.xxx.xxx.databinding.FragmentHomeBinding.inflate(FragmentHomeBinding.java:125)
       at xx.xxx.xxx.databinding.FragmentHomeBinding.inflate(FragmentHomeBinding.java:119)
       at xx.xxx.xxx.fragments.home.HomeFragment.onCreateView(HomeFragment.kt:52)
       at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2699)
       at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
       at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199)
       at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368)
       at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446)
       at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:442)
       at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2181)
       at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2004)
       at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1959)
       at androidx.fragment.app.FragmentManager.execSingleAction(FragmentManager.java:1830)
       at androidx.fragment.app.BackStackRecord.commitNow(BackStackRecord.java:297)
       at androidx.viewpager2.adapter.FragmentStateAdapter.placeFragmentInViewHolder(FragmentStateAdapter.java:341)
       at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:276)
       at androidx.viewpager2.adapter.FragmentStateAdapter.onViewAttachedToWindow(FragmentStateAdapter.java:67)
       at androidx.recyclerview.widget.RecyclerView.dispatchChildAttached(RecyclerView.java:7556)
       at androidx.recyclerview.widget.RecyclerView$5.addView(RecyclerView.java:860)
       at androidx.recyclerview.widget.ChildHelper.addView(ChildHelper.java:107)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:8601)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8559)
       at androidx.recyclerview.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:8547)
       at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1641)
       at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
       at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4134)
       at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3540)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChild(ViewGroup.java:6928)
       at androidx.viewpager2.widget.ViewPager2.onMeasure(ViewPager2.java:498)
       at android.view.View.measure(View.java:25466)
       at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:763)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.measure(BasicMeasure.java:426)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.measureChildren(BasicMeasure.java:105)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:247)
       at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:117)
       at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:1532)
       at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1607)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25466)
       at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(ConstraintLayout.java:763)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.measure(BasicMeasure.java:426)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.measureChildren(BasicMeasure.java:105)
       at androidx.constraintlayout.solver.widgets.analyzer.BasicMeasure.solverMeasure(BasicMeasure.java:247)
       at androidx.constraintlayout.solver.widgets.ConstraintWidgetContainer.measure(ConstraintWidgetContainer.java:117)
       at androidx.constraintlayout.widget.ConstraintLayout.resolveSystem(ConstraintLayout.java:1532)
       at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1607)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:833)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6957)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at com.android.internal.policy.DecorView.onMeasure(DecorView.java:747)
       at android.view.View.measure(View.java:25466)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3397)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2228)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2486)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1952)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8171)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:972)
       at android.view.Choreographer.doCallbacks(Choreographer.java:796)
       at android.view.Choreographer.doFrame(Choreographer.java:731)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7656)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

XML

This ImageViewconcerned :

<ImageView
  android:id="@+id/first_image"
  android:layout_width="0dp"
  android:layout_height="0dp"
  android:adjustViewBounds="true"
  android:baselineAlignBottom="true"
  android:contentDescription="@null"
  android:cropToPadding="true"
  android:scaleType="centerCrop"
  app:srcCompat="@drawable/home_1"
  app:layout_constraintDimensionRatio="1:1"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintEnd_toEndOf="parent"
  app:layout_constraintBottom_toBottomOf="parent"/>

The id is correct, but like I said I don't know if the issue is caused by this drawable especially or if all my drawables are concerned and the app crashes at first ImageView

Ady
  • 230
  • 3
  • 16
  • Can you share some logs or code? – Parth Bhatti Dec 31 '20 at 09:34
  • To check resources: you can open any APK as compressed archive and check "res" folder as you do when developing an App. However without any log or error we cannot help you very much..... – emandt Dec 31 '20 at 09:35
  • I've added some logs ! I haven't been able to reproduce that issue, so maybe the issue come from the ```Play Store``` ? – Ady Dec 31 '20 at 10:35
  • please share your fragment_home.xml. There is something wrong with your imageview in line 25. I thing your using wrong imageview id. – Rajendra Mahato Dec 31 '20 at 10:42
  • put the drawable in default `drawable` also. – rahat Jan 26 '21 at 04:17
  • Did you ever find out what happened or a way to fix it? I'm facing the same rare crash report on startup, coincidentally also with a Galaxy A device. – moertel Mar 24 '22 at 09:42
  • @moertel Unfortunately no, it always happens, very rarely but always – Ady Mar 24 '22 at 16:11
  • 1
    @Ady I continued the search yesterday and found this response by a (former?) Google employee. The reason seems to be users trying to load the app outside of the Play Store. As AABs consist of multiple ABKs, users can get incomplete resources this way. https://stackoverflow.com/questions/52469914/app-sometimes-crashes-with-resourcesnotfoundexception-after-switching-to-androi/52474885#52474885 – moertel Mar 25 '22 at 11:59
  • 1
    @moertel Oh, so if someone has this problem, it's their fault! Thank you for your help! – Ady Apr 03 '22 at 15:03
  • 1
    @Ady you're welcome! I wasn't able to confirm this hypothesis with a user yet but it would explain why it happens across so many different device types, versions and regions, and why it's such a relatively rare phenomenon. If you ever find proof for it, let me know! – moertel Apr 04 '22 at 17:32

0 Answers0