3

It's been a while now that every single layout file in my multiple projects isn't rendered correctly when it's first opened. The Exception AndroidStudio 3.0 displays is (full stack trace):

    java.util.concurrent.TimeoutException: Preview timed out while rendering the layout.
This typically happens when there is an infinite loop or unbounded recursion in one of the custom views.
    at org.kxml2.io.KXmlParser.next(Unknown Source)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl$NamedParser.next(LayoutlibCallbackImpl.java:855)
    at com.android.layoutlib.bridge.android.BridgeXmlBlockParser.next(BridgeXmlBlockParser.java:302)
    at android.content.res.FontResourcesParser.skip(FontResourcesParser.java:220)
    at android.content.res.FontResourcesParser.readFamily(FontResourcesParser.java:154)
    at android.content.res.FontResourcesParser.readFamilies(FontResourcesParser.java:135)
    at android.content.res.FontResourcesParser.parse(FontResourcesParser.java:126)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getFont(ResourceHelper.java:424)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getFont(ResourceHelper.java:454)
    at android.content.res.BridgeTypedArray.getFont(BridgeTypedArray.java:735)
    at android.widget.TextView.readTextAppearance(TextView.java:3369)
    at android.widget.TextView.<init>(TextView.java:919)
    at android.widget.TextView.<init>(TextView.java:832)
    at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:75)
    at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:481)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:252)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:215)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadClass(LayoutlibCallbackImpl.java:218)
    at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:336)
    at android.view.BridgeInflater.onCreateView(BridgeInflater.java:155)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:225)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:866)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:384)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:547)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$3(RenderTask.java:681)
    at com.android.tools.idea.rendering.RenderTask$$Lambda$2201/612657191.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Since I couldn't find a proper solution, I decided to post this question. Does anyone know what's happening?

From the stacktrace I gather that the issue is related to the new font management in xml files... My projects were written before the new api 26 and like many other fellow developers I used custom fonts diligently stored in the assets folder. And my layouts are still filled with the "old way". On the contrary I'm using the easier "new way" for my new layouts, declaring the fontFamily attribute with downloadable fonts. And everything works perfectly fine.

Can this coexistence be my problem?

The only solution a found is invalidating AND restarting EVERY TIME AndroidStudio. But there must be another way, and a reason why this happens...

EDIT 11-29-2017

The problem showed up again two days ago and now, not even the only thing that did the trick (AS option Invalidate cache and Restart), works anymore.

Maybe the same issue popped up for someone else during these days? Trying to create layouts completely in the dark isn't funny...

Massimo Baldrighi
  • 365
  • 2
  • 6
  • 17
  • Is this occurring for both types of layout ("old way" and "new way")? When you say "invalidating and restarting", what do you mean by "invalidating"? If you create a new project with the "Empty Activity" template in Android Studio -- which won't have any custom fonts -- can you view the generated layout file? – CommonsWare Nov 17 '17 at 22:29
  • So sorry for my late reply... Yes, it's happening for both "ways", and with "invalidating" I meant the Android Studio built-in option of `Invalidate cache and restart`. As far as a new simple project is concerned, actually everything works as expected since the project build... And, surprisingly, if I start an incriminated project right after the empty one, everything works fine immediately for that one too! – Massimo Baldrighi Nov 19 '17 at 13:41
  • OK, that's pretty strange. Are you able to reproduce the problem at all anymore? – CommonsWare Nov 19 '17 at 13:50
  • I will report here the results as soon as I am able to test it. – Massimo Baldrighi Nov 19 '17 at 14:23
  • It's been 2 days now, and the problem no longer showed up. I still don't know what caused the issue. There are times in which the layout preview doesn't work immediately, reporting completely different and random errors, but a simple selection of "Force layout refresh" is enoug to make it work once again. – Massimo Baldrighi Nov 22 '17 at 11:12

0 Answers0