-2

As I was reading few blogs on how react native works under the hood, I found out that ios devices have built in javascript engine called javascript core which is used in safari browser. But android phone doesn't have built in javascript engine so react native has to ship javascript engine as well to android phone along with the bundle.

But my question is android phones also have chrome browser built in. Doesn't it have V8 engine already? So, why to ship another javascript engine?

If anyone could help me understand this I would be really grateful.

  • "Why doesn't" questions are usually not very productive. The answer is simple: because Android is not iOS, and isn't built like iOS, and simply doesn't have that one feature that iOS has. – deceze Aug 09 '23 at 07:46
  • Okay. How can I ask the same question in productive manner? – Ranjit Budhathoki Aug 09 '23 at 07:48
  • Including a JS engine in one app is "easy" (for some definitions of "easy"). Including a JS engine in the OS and offering a system-wide way to hook into it and doing that in a secure way is much more work. Apple has done that work. Google apparently simply hasn't. That's what it comes down to. Not sure what more you want to hear. – deceze Aug 09 '23 at 07:52

2 Answers2

0

There technically is a built-in V8 engine, but it's only exposed via the WebView component. But anything that goes beyond what a WebView can do ships with its own JavaScript engine (Even Chrome, as mentioned in the link above), including React Native apps.

And if a native and more accessible V8 engine was added to the OS now, React Native would still need to ship with its own for a while for older devices.

LW001
  • 2,452
  • 6
  • 27
  • 36
  • Thank you for your response. But why javascript core engine used in safari works fine? Does it have to do with the implementation of the engine itself? – Ranjit Budhathoki Aug 09 '23 at 07:47
  • I don't really know a lot about the iOS engine but it just seems to be an API that's exposed for apps to just use, which just isn't the case in Android. So the real difference isn't what engine there is but how much of it is exposed and usable by apps outside of WebViews. – LW001 Aug 09 '23 at 07:51
  • The essence of this answer is still correct. The detail that "even Chrome ships its own V8" was true in 2014 (see the date at the bottom of the linked page) but is no longer true today. See e.g. https://chromium.googlesource.com/chromium/src/+/main/android_webview/docs/faq.md#what_s-the-relationship-between-webview-and-chrome and https://chromium.googlesource.com/chromium/src/+/main/android_webview/docs/aosp-system-integration.md#trichrome . – jmrk Aug 09 '23 at 19:11
-1

The integration and licensing aspects might be more straightforward on iOS. JavaScriptCore is licensed under LGPL, and its integration within iOS aligns with Apple's policies and development practices. Integrating V8 into Android as a system-wide library involves more complex legal and technical challenges.

LickingFilth
  • 223
  • 1
  • 8
  • I understand about about technical challenges but why legal challenges? Isn't V8 and android both owned by google? – Ranjit Budhathoki Aug 09 '23 at 08:33
  • Legal challenges in integrating V8 into Android, despite both being associated with Google, could arise from differences in licensing terms, intellectual property rights, regulatory compliance and third-party agreements. Google might have contracts, agreements, or partnerships with other entities related to V8 or Android. Integrating the two could necessitate renegotiating these agreements or might even be restricted under existing terms. Btw even within a company, different products and projects might have distinct IP rights and patent obligations. – LickingFilth Aug 09 '23 at 08:39
  • 1
    Sounds like this answer is pure speculation/guesswork. And considering that Android _does_ ship a copy of V8 (as part of WebView), it doesn't seem to be a particularly accurate guess :) – jmrk Aug 09 '23 at 18:59
  • Android does include a version of the V8 engine as part of WebView. However, the decision to ship a separate js engine with react on android is likely more related to technical considerations rather than legal ones. V8 in WebView is optimized for specific use cases related to web browsing and it is not suitable for the needs of react apps. Shipping a separate js engine ensures that the engine is tailored to the needs of react apps – LickingFilth Aug 10 '23 at 06:00