B3nedikt / ViewPump

View Inflation you can intercept.
Apache License 2.0
165 stars 15 forks source link

BottomNavigationView fails to inflate when using Restring #8

Closed edgar-zigis closed 1 year ago

edgar-zigis commented 4 years ago

Hey Benedikt,

I am getting back again with issues :)) So we are cleaning up a backlog and I have noticed the following crash:

Fatal Exception: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView

Further related crash in the tree:

Caused by java.lang.reflect.InvocationTargetException
       at java.lang.reflect.Constructor.newInstance0(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
       at android.view.LayoutInflater.createView(LayoutInflater.java:652)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.createCustomViewInternal(-ViewPumpLayoutInflater.java:224)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.access$createCustomViewInternal(-ViewPumpLayoutInflater.java:18)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater$PrivateWrapperFactory2ViewCreator.onCreateView(-ViewPumpLayoutInflater.java:441)
       at dev.b3nedikt.viewpump.internal.-FallbackViewCreationInterceptor.intercept(-FallbackViewCreationInterceptor.java:14)
       at dev.b3nedikt.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
       at dev.b3nedikt.reword.RewordInterceptor.intercept(RewordInterceptor.java:13)
       at dev.b3nedikt.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
       at dev.b3nedikt.viewpump.ViewPump.inflate(ViewPump.java:38)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater$PrivateWrapperFactory2.onCreateView(-ViewPumpLayoutInflater.java:415)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:890)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:851)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:893)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:51)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
       at android.view.View.inflate(View.java:24834)

continuation:

Caused by java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0403b3 a=-1}
       at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
       at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
       at android.view.View.<init>(View.java:5090)
       at android.view.ViewGroup.<init>(ViewGroup.java:670)
       at android.widget.FrameLayout.<init>(FrameLayout.java:92)
       at android.widget.FrameLayout.<init>(FrameLayout.java:87)
       at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:138)
       at com.google.android.material.bottomnavigation.BottomNavigationView.<init>(BottomNavigationView.java:133)
       at java.lang.reflect.Constructor.newInstance0(Constructor.java)
       at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
       at android.view.LayoutInflater.createView(LayoutInflater.java:652)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.createCustomViewInternal(-ViewPumpLayoutInflater.java:224)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.access$createCustomViewInternal(-ViewPumpLayoutInflater.java:18)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater$PrivateWrapperFactory2ViewCreator.onCreateView(-ViewPumpLayoutInflater.java:441)
       at dev.b3nedikt.viewpump.internal.-FallbackViewCreationInterceptor.intercept(-FallbackViewCreationInterceptor.java:14)
       at dev.b3nedikt.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
       at dev.b3nedikt.reword.RewordInterceptor.intercept(RewordInterceptor.java:13)
       at dev.b3nedikt.viewpump.internal.-InterceptorChain.proceed(-InterceptorChain.java:30)
       at dev.b3nedikt.viewpump.ViewPump.inflate(ViewPump.java:38)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater$PrivateWrapperFactory2.onCreateView(-ViewPumpLayoutInflater.java:415)
       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:186)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:740)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:890)
       at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:851)
       at android.view.LayoutInflater.rInflate(LayoutInflater.java:893)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:60)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
       at dev.b3nedikt.viewpump.internal.-ViewPumpLayoutInflater.inflate(-ViewPumpLayoutInflater.java:51)
       at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
       at android.view.View.inflate(View.java:24834)

Libs which we use and maybe might cause this:

androidx.appcompat - 1.1.0
constraintLayout - 2.0.2
google.material - 1.1.0-rc01
b3nedikt.restring - 5.1.0
b3nedikt.viewPump - 3.0.1 - (maybe this can be an issue as I see now are newer versions) ?
B3nedikt commented 4 years ago

Hi again :) Yeah, this has been fixed with viewPump 4.0.3, all earlier versions have known issues. Btw. you can update appcompat to 1.2.0 as well, the new version of ViewPump has been tested with it. Also I would recommend to update google.material to 1.2.1, the version you use has some critical known issues. Hope this helps, feel free to reopen this issue if you encounter more issues :)

edgar-zigis commented 3 years ago

Hey there, after updating version to the latest ViewPump, webviews start crash again 😄

E/UncaughtException: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2293)
at android.content.res.Resources.getLayout(Resources.java:1187)
at dev.b3nedikt.restring.internal.RestringResources.getLayout(RestringResources.kt:162)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:428)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:419)
at z80.getView(chromium-TrichromeWebViewGoogle.aab-stable-428010133:2)
at android.widget.AbsListView.obtainView(AbsListView.java:2472)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1421)
at android.widget.ListView.onMeasure(ListView.java:1327)
at android.view.View.measure(View.java:24730)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6858)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24730)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6858)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24730)
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:24730)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6858)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:24730)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6858)
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:24730)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6858)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:749)
at android.view.View.measure(View.java:24730)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3282)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2025)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2354)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1940)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8041)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1163)
at android.view.Choreographer.doCallbacks(Choreographer.java:986)
at android.view.Choreographer.doFrame(Choreographer.java:902)
at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1091)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7710)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
B3nedikt commented 3 years ago

@edgar-zigis Hi again, these web views are an endless story xD I think I know by now though how these come up, my next (3 line) solution I will create tonight should fix these for ever.

Btw. with these webviews, how do you make sure they are in the correct language? I mean you cant really change any strings in a website.

edgar-zigis commented 3 years ago

@B3nedikt we don't really need ViewPump working for WebViews, but it's annoying that in order to launch WebView you basically have to have a separate activity which would not use Restring. So until your previous fix we basically opened all fragments containing webviews on the separate Activity (which was inconvenient and breaks modular architecture principles, unless each module has separate activity just for launching web views). So we have moved from that separate webview activity after your fix, but now after upgrading ViewPump this issue reocurred again :))))

B3nedikt commented 3 years ago

I see, that explains a lot xD Yeah, having restring work inside WebViews is as far as I know impossible, I mean at the end WebViews are a separate app displayed in your app, and they can do whatever they want. So I just excluded them in ViewPump now ;)

I just released this as ViewPump 4.0.4, please try it out :)

edgar-zigis commented 3 years ago

Awesome, thank you!! 👍 just I wonder whether it will work on WebView child views, because the issue usually occurs when clicking on some dropdown inside of the webview which triggers opening Android Spinner view.

edgar-zigis commented 3 years ago

I will try it out this anyway.

B3nedikt commented 3 years ago

You're welcome :) Yeah, these child views are Android Views, but the assets which generate them come from the WebView app and not your app or the android system, including the layout file for the Spinner. For android assets to work they always need to stay in sync with the resources, which kind of got messed up in the WebView apps code. So to fix this google provided a fix in appcompat 1.2.0.

This commit explains the fix, some other commits in this version fix issues from this commit.

However this reworked attachedBaseContext2 method stripps away the custom resources from Restring. So my fix just is: Use custom resources for all views except web views. Whenever a web view is requested, just create a WebView with the context fixed using the new attachedBaseContext2 method. See my commit.

Let's see if the theory plays out for your complex app as well, appcompat is such a messy library xD

B3nedikt commented 1 year ago

@youngmeng You need to provide me more info on what exactly the same problem is, and how that relates to "chromium-TrichromeWebViewGoogle". In short just fork this repository, and change the sample app so that it reproduces your issue. Then just link the fork to this ticket.

B3nedikt commented 1 year ago

That should normally not be needed. Without code which reproduces your issue I don't think there is a chance I can help here ;)

B3nedikt commented 1 year ago

Closed due to inactivity, if you find out more on how to reproduce it, feel free to open it again :)