10

The app I'm currently building for work is mainly focused around displaying articles. Some of them contain Twitter embeds (on the web version) and since the API is shared by both of our apps I also receive the embed as HTML. Whenever I try to display tweets inside a WebView with the source set to the HTML and the Twitter JS script for styling, the page either loads correctly but crashes when I press back (using react-navigation) or it simply crashes on load but ONLY ON ANDROID.

I have tried the following:

  • Use the community supported WebView package instead of the built-in one. I have opened an issue over there as well.

  • Remove the JS script from the WebView.

  • Use the injectedJavaScript prop instead.

  • Install TwitterKit to use the native embeds, unfortunately that's not supported by Twitter anymore :(

This is how I render the WebViews:

const JS = '<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>';
return (
    <View
        key={content.embed._id} 
        style={[{ overflow : "hidden", marginTop : 15, marginStart : 15 }]}>
        <WebView 
            scrollEnabled={false}
            style={{ height : 150, width : Dimensions.get('window').width - 30 }}
            source={{ html : content.embed.html + JS }} />
    </View>
);

This is the stack trace from Android Studio (I don't even get a RedBox, just a plain old hard crash).

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c in tid 13662 (RenderThread), pid 13634 (com.example)
Build fingerprint: 'google/sdk_gphone_x86/generic_x86:9/PSR1.180720.093/5456446:userdebug/dev-keys'
Revision: '0'
ABI: 'x86'
pid: 13634, tid: 13662, name: RenderThread  >>> com.example <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c
Cause: null pointer dereference
    eax e7a959c0  ebx f0a794a0  ecx f0a6994c  edx 00000002
    edi efcbbd9c  esi 00000000
    ebp d314a7e8  esp d314a7d0  eip f07edeea
backtrace:
    #00 pc 0060ceea  /system/lib/libhwui.so (SkSurface::getCanvas()+26)
    #01 pc 0009b53d  /system/lib/libhwui.so (android::uirenderer::skiapipeline::GLFunctorDrawable::onDraw(SkCanvas*)+3357)
    #02 pc 005200f7  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+279)
    #03 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #04 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #05 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #06 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #07 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #08 pc 0052006d  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+141)
    #09 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #10 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #11 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #12 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #13 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #14 pc 0052006d  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+141)
    #15 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #16 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #17 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #18 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #19 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #20 pc 0052006d  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+141)
    #21 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #22 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #23 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #24 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #25 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #26 pc 0052006d  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+141)
    #27 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #28 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #29 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #30 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #31 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #32 pc 0052006d  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+141)
    #33 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #34 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #35 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #36 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #37 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #38 pc 0052006d  /system/lib/libhwui.so (SkDrawable::draw(SkCanvas*, SkMatrix const*)+141)
    #39 pc 0051c9a6  /system/lib/libhwui.so (SkCanvas::onDrawDrawable(SkDrawable*, SkMatrix const*)+38)
    #40 pc 00178318  /system/lib/libhwui.so (SkCanvas::drawDrawable(SkDrawable*, SkMatrix const*)+344)
    #41 pc 005208f5  /system/lib/libhwui.so (SkLiteDL::draw(SkCanvas*) const+229)
    #42 pc 004fe090  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::drawContent(SkCanvas*) const+352)
    #43 pc 004fe51f  /system/lib/libhwui.so (android::uirenderer::skiapipeline::RenderNodeDrawable::forceDraw(SkCanvas*)+287)
    #44 pc 000a655e  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderLayersImpl(android::uirenderer::LayerUpdateQueue const&, bool, bool)+862)
    #45 pc 00546e44  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderFrame(android::uirenderer::LayerUpdateQueue const&, SkRect const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, bool, bool, android::uirenderer::Rect const&, sk_sp<SkSurface>)+84)
    #46 pc 00545e39  /system/lib/libhwui.so (android::uirenderer::skiapipeline::SkiaOpenGLPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::FrameBuilder::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, bool, android::uirenderer::BakedOpRenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>
    #47 pc 000b2e76  /system/lib/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw()+262)
    #48 pc 0054bd02  /system/lib/libhwui.so (_ZNSt3__110__function6__funcIZN7android10uirenderer12renderthread13DrawFrameTask11postAndWaitEvE3$_0NS_9allocatorIS6_EEFvvEEclEv$c303f2d2360db58ed70a2d0ac7ed911b+898)
    #49 pc 004fd4c2  /system/lib/libhwui.so (android::uirenderer::WorkQueue::process()+242)
    #50 pc 000c454a  /system/lib/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+314)
    #51 pc 0000e616  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+326)
    #52 pc 0000df76  /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+246)
    #53 pc 0008f065  /system/lib/libc.so (__pthread_start(void*)+53)
emeraldsanto
  • 4,330
  • 1
  • 12
  • 25
  • In my experience `WebView` is still fairly unstable , it might be worth rendering the tweets in react/jsx if that is an option. I don't think there's an easy fix from the JS side – Trevor Atlas Jun 12 '19 at 03:28
  • Hey Trevor, that's an option I've considered but the tweet layout is fairly complex (sometimes the parent tweet is included for context, contains images, link previews, etc.). That's why I was looking at TwitterKit but I couldn't even get it to compile. – emeraldsanto Jun 12 '19 at 03:39

3 Answers3

24

So I've done a little more digging on the community supported WebView github page and turns out there is this androidHardwareAccelerationDisabled which is a boolean. I tried setting it to true and it seems to have fixed the problem!

<Webview
    androidHardwareAccelerationDisabled
    ... 
/>
emeraldsanto
  • 4,330
  • 1
  • 12
  • 25
  • Seems related to this [issue](https://github.com/react-native-community/react-native-webview/issues/811). I am still experiencing it in react-native-webview v10.4.1. An alternate solution listed at this [link](https://www.gitmemory.com/issue/react-native-community/react-native-webview/430/493976111) also works if you wish to keep hardware acceleration enabled. – sushrut619 Aug 14 '20 at 17:46
2

androidHardwareAccelerationDisabled did not work for me, but the following solution did:

https://github.com/react-native-webview/react-native-webview/issues/811#issuecomment-570813204

Example code:

    <WebView
      style={{ opacity: 0.99 }}
    />

Also, using androidHardwareAccelerationDisabled can cause performance issues.

Ovidiu Cristescu
  • 821
  • 7
  • 19
0

I added

android:hardwareAccelerated="false"

in android manifest file, and it solved the problem.

박제영
  • 101
  • 1
  • 4
  • Be careful, this disables hardware acceleration for your whole application instead of only in certain Webviews. This can drastically affect performance on some devices and applications. – emeraldsanto Mar 24 '21 at 11:30
  • Thanks @emeraldsanto! I recently found out that it can cause some problems. for example, android elevation is disabled when hardwareAccelerated is false. So I think the solution above can be the best one. – 박제영 Mar 29 '21 at 00:31
  • Only this one worked for me. Added for activity. – Alexander Danilov Jun 21 '22 at 16:59