transifex / transifex-java

Transifex Native Toolkit for Java
Apache License 2.0
19 stars 3 forks source link

What could cause a Resources$NotFoundException? #59

Open io7m opened 11 months ago

io7m commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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. :+1:

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 10 months ago

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

Petrakeas commented 10 months ago

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

io7m commented 10 months ago

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