Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What could cause a Resources$NotFoundException? #59

Open
io7m opened this issue Dec 5, 2023 · 9 comments
Open

What could cause a Resources$NotFoundException? #59

io7m opened this issue Dec 5, 2023 · 9 comments

Comments

@io7m
Copy link

io7m commented Dec 5, 2023

Hello!

We've been using Transifex for a few months in our open-source Android app:

https://github.com/ThePalaceProject/android-core

We're seeing a few crashes in Crashlytics along these lines:

Fatal Exception: android.content.res.Resources$NotFoundException
Unable to find resource ID #0x2140054

android.content.res.ResourcesImpl.getResourcePackageName (ResourcesImpl.java:263)
android.content.res.Resources.getResourcePackageName (Resources.java:1970)
com.transifex.txnative.TxResources.isAndroidStringResource (TxResources.java:103)
com.transifex.txnative.NativeCore.internalTranslate (NativeCore.java:198)
com.transifex.txnative.NativeCore.translate (NativeCore.java:152)
com.transifex.txnative.TxResources.getText (TxResources.java:63)
android.content.res.Resources.getString (Resources.java:441)
android.content.Context.getString (Context.java:578)
org.chromium.android_webview.AwActionModeCallback.onCreateActionMode (AMAZON_VERSION.json:code):41)
com.android.internal.policy.DecorView$ActionModeCallback2Wrapper.onCreateActionMode (DecorView.java:2397)
com.android.internal.policy.DecorView.startActionMode (DecorView.java:897)
com.android.internal.policy.DecorView.startActionModeForChild (DecorView.java:853)
android.view.ViewGroup.startActionModeForChild (ViewGroup.java:985)
android.view.ViewGroup.startActionModeForChild (ViewGroup.java:985)
android.view.ViewGroup.startActionModeForChild (ViewGroup.java:985)
android.view.ViewGroup.startActionModeForChild (ViewGroup.java:985)
android.view.ViewGroup.startActionModeForChild (ViewGroup.java:985)
android.view.ViewGroup.startActionModeForChild (ViewGroup.java:985)
android.view.View.startActionMode (View.java:6796)
org.chromium.content.browser.selection.SelectionPopupControllerImpl.showActionModeOrClearOnFailure (AMAZON_VERSION.json:code):66)
org.chromium.content.browser.selection.SelectionPopupControllerImpl$2.onClassified (AMAZON_VERSION.json:code):38)
org.chromium.content.browser.selection.SmartSelectionProvider$ClassificationTask.onPostExecute (AMAZON_VERSION.json:code):7)
org.chromium.base.task.AsyncTask$$ExternalSyntheticLambda1.run (AMAZON_VERSION.json:code):15)
android.os.MessageQueue.nativePollOnce (MessageQueue.java)
android.os.MessageQueue.next (MessageQueue.java:326)
android.os.Looper.loop (Looper.java:178)
android.app.ActivityThread.main (ActivityThread.java:6775)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)

The obvious answer is that we're somehow missing a translated string somewhere, but even then... That shouldn't cause a crash, right? I'm at a bit of a loss as to how to track down exactly what's going wrong.

Is this a common occurrence with Transifex? Is there a bug here?

@Petrakeas
Copy link
Contributor

Petrakeas commented Dec 5, 2023

This is probably related to a bug we had with Webiew. A String resource id, required by WebView, should be made available to Android's Resources when WebView loads for the first time. However, it's not available because TxNative uses a wrapped Resources object which points to an older AssetManager which does not have the required resource id . We released a fix for this.

Do these crashes occur with TxNative 1.2.3 ?

Can you reproduce it consistently? If yes, can you provide with an STR for your app or send me a minimal reproducible example?

@io7m
Copy link
Author

io7m commented Dec 5, 2023

Ah, it looks like we're on 1.2.1. I'll try upgrading and we'll see if it goes away in the next release. 👍

Unfortunately, I don't have a consistent way to reproduce it; I've actually never even seen it happen. The only reason I know about it is because crashes are showing up in Crashlytics. If it's worth anything, the crashes we do see appear to be consistently happening only on Android 9. We don't exactly have a huge sample size, though.

@Petrakeas
Copy link
Contributor

The STR we found (and is included in the sample app) is showing an Activity with webview that has a selector:
https://github.com/transifex/transifex-java/blob/devel/TransifexNativeSDK/app/src/main/assets/example.html

Do you have something similar in your app? Using a Txnative before 1.2.2 should crash in this scenario.

@io7m
Copy link
Author

io7m commented Dec 5, 2023

It's entirely possible that we do. Our app presents an interface to various public and academic libraries, and sometimes those libraries require logging in using SAML. This basically entails opening arbitrary web pages inside the app... Anything could be in there, really!

@Petrakeas
Copy link
Contributor

Another workaround, if possible for your app, is to avoid extending TxBaseAppCompatActivity in the activities that use WebView.

This will disable TxNative functionality in these activities, but if all they do is show a WebView, you can do this.

@io7m
Copy link
Author

io7m commented Dec 5, 2023

Thanks! I'll be trying each of these suggestions. We won't be doing another app release until January as it's the holiday season, but we should find out pretty quickly if the problem has gone away.

I'll leave this ticket open for now, and I'll try to report back.

io7m added a commit to ThePalaceProject/android-core that referenced this issue Dec 5, 2023
@io7m
Copy link
Author

io7m commented Jan 10, 2024

We just released a new version of the application yesterday, so hopefully we'll see if this has resolved things.

@Petrakeas
Copy link
Contributor

Note that TxNative 1.3.0 was released that improves the WebView related issue even further.

@io7m
Copy link
Author

io7m commented Jan 17, 2024

Looks like there was still one instance of the crash in our new release. I'm going to upgrade to 1.3.0 today. 👍

io7m added a commit to ThePalaceProject/android-core that referenced this issue Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants