mobile-sdk-android: Inflating Views using Contexts wrapped by CrowdIn result in Resources$NotFoundExceptions

Describe the bug When using CrowdIn in our app, we’ve found hundreds of mysterious android.content.res.Resources$NotFoundException coming from our WebView and ExoPlayer views we’re inflating in our app (our only non-composable views in our app). We tried several approaches to figure out the root cause of these crashes, and were able to determine that CrowdIn’s wrapping of our base context that we were then using to inflate these views was the root cause of these crashes.

To Reproduce Steps to reproduce the behavior:

  1. Set up a project using CrowdIn that wraps the base context when an activity starts up in attachBaseContext
  2. Inflate a WebView instance programmatically, ie WebView(context)
  3. Select text on a web page or text input field in order to trigger the system inflating a contextual window pop up (ie, Copy, Paste, etc) via long clicking, or double-tapping text.
  4. Observe the web view crash, with a Resources$NotFoundException. Exception thrown will be some permutation of this message:

android.content.res.Resources$NotFoundException - Unable to find resource ID #<address>

  1. Comment out lines that wrap the base context attachBaseContext
  2. Select text in a webview, you should see no crash.

Expected behavior A view’s non-string resources should not be impacted or obstructed by crowd in in any way

Screenshots N/A

Smartphone (please complete the following information):

  • All Android versions we support (Android 8-14), dozens of different models

Additional context We were able to add a work around for this issue by preserving our activity’s base context before it gets wrapped by CrowdIn, keep a reference to it, and use that context to inflate our views. Since doing that, our crash rates have reduced dramatically.

See additional context/thread in this WebView Issue Tracker issue.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 16 (3 by maintainers)

Most upvoted comments

@anderlipkin @MykhailoNester looks like someone from google recommended a fix. Can someone take a look and start work on this? It seems as though Crowdin’s existing approach has some significant flaws, and there are, especially on modern Android versions, official ways to accomplish the task of adding/loading resources dynamically. Please see this comment: https://issuetracker.google.com/issues/237587153#comment27

Looks like a new permutation of this crash surfaced while using 1.9.1:

Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x0
       at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:233)
       at android.content.res.Resources.loadXmlResourceParser(Resources.java:2446)
       at android.content.res.Resources.getLayout(Resources.java:1252)
       at com.crowdin.platform.CrowdinResources.getLayout(CrowdinResources.kt:176)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:536)
       at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:425)
       at android.widget.ArrayAdapter.getView(ArrayAdapter.java:416)
       at WV.MM.getView(chromium-TrichromeWebViewGoogle6432.aab-stable-636705433:11)
       at android.widget.AbsListView.obtainView(AbsListView.java:2405)
       at android.widget.ListView.measureHeightOfChildren(ListView.java:1417)
       at android.widget.ListView.onMeasure(ListView.java:1323)
       at android.view.View.measure(View.java:25905)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6980)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25905)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6980)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25905)
       at com.android.internal.widget.AlertDialogLayout.tryOnMeasure(AlertDialogLayout.java:146)
       at com.android.internal.widget.AlertDialogLayout.onMeasure(AlertDialogLayout.java:71)
       at android.view.View.measure(View.java:25905)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6980)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25905)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6980)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:25905)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6980)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at com.android.internal.policy.DecorView.onMeasure(DecorView.java:793)
       at android.view.View.measure(View.java:25905)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3808)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2563)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2874)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2294)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8998)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1037)
       at android.view.Choreographer.doCallbacks(Choreographer.java:845)
       at android.view.Choreographer.doFrame(Choreographer.java:780)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1022)
       at android.os.Handler.handleCallback(Handler.java:978)
       at android.os.Handler.dispatchMessage(Handler.java:104)
       at android.os.Looper.loopOnce(Looper.java:238)
       at android.os.Looper.loop(Looper.java:357)
       at android.app.ActivityThread.main(ActivityThread.java:8090)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)

Can confirm, updating to 1.9.1 finally fixed the issue! Thanks so much for all the work here!

Hi @isles1217, could you please check if the recent release fixes this for you? https://github.com/crowdin/mobile-sdk-android/releases/tag/1.9.0