react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

✨ Support the v8 version of react-native-reanimated

Open jzxchiang1 opened this issue 2 years ago • 14 comments

What feature or enhancement are you suggesting?

Very soon, reanimated will support v8. (I've gotten it working on RN 64 with the help of Kudo, who is the maintainer of react-native-v8.)

I tried the v8 version of react-native-reanimated with vision-camera 2.9.0 on iOS and it worked fine.

However, on Android it threw an error on npm run android because vision-camera only expects Hermes or JSC:

https://github.com/mrousavy/react-native-vision-camera/blob/2cf8087ad663fafeb645280978ed55240f290284/android/build.gradle#L227

Also, these files won't exist for those running react-native-v8:

https://github.com/mrousavy/react-native-vision-camera/blob/2cf8087ad663fafeb645280978ed55240f290284/android/build.gradle#L220


One question I have is how you know whether to package the Hermes or JSC AAR at build time? Doesn't that depend on what the library user is using, which you don't know until runtime? That's why I'm confused how you can only choose to package one AAR in this PR instead of all of them.

Thanks!

What Platforms whould this feature/enhancement affect?

Android

Alternatives/Workarounds

Not sure how to get it working right now. All the ingredients for v8 support are there however.

Additional information

jzxchiang1 avatar Oct 10 '21 18:10 jzxchiang1

Related comment: https://github.com/mrousavy/react-native-vision-camera/pull/412#issuecomment-939523230

jzxchiang1 avatar Oct 10 '21 18:10 jzxchiang1

Hi! Thanks for the feature request, v8 is surely cool to support.

One question I have is how you know whether to package the Hermes or JSC AAR at build time?

Because that's how it works. RN has the enableHermes property in build.gradle to determine the engine at build time. Not sure how V8 solves this..

mrousavy avatar Oct 11 '21 08:10 mrousavy

reanimated didn't officially support v8 now. in the meantime i just forked and build v8 aar by myself.

and here is how i check which aar to use: https://github.com/Kudo/react-native-reanimated/commit/4b069950c4b75b836350b1803485819939ce632b#diff-d260c332176b5c72008900aef1116a89a873451c7388a808c8d2d58be0865d38R64-R65

Kudo avatar Oct 11 '21 12:10 Kudo

Hi! Thanks for the feature request, v8 is surely cool to support.

One question I have is how you know whether to package the Hermes or JSC AAR at build time?

Because that's how it works. RN has the enableHermes property in build.gradle to determine the engine at build time. Not sure how V8 solves this..

One question: is the vision-camera build.gradle run when the user runs npx react-native run-android or when the library maintainer (i.e. you) builds the NPM package to distribute?

In the meantime, is there a quick fix (possibly patched locally) for me to get @Kudo's v8 reanimated working with vision-camera 2.5.0+ on Android? It's so close but I don't quite understand everything yet :(

jzxchiang1 avatar Oct 14 '21 02:10 jzxchiang1

One question: is the vision-camera build.gradle run when the user runs npx react-native run-android or when the library maintainer (i.e. you) builds the NPM package to distribute?

build.gradle is evaluated when you run npx react-native run-android. I am not pre-building VisionCamera for distribution.

is there a quick fix (possibly patched locally) for me to get @Kudo's v8 reanimated working with vision-camera 2.5.0+ on Android?

No, Reanimated needs to add V8 support first.

mrousavy avatar Oct 14 '21 10:10 mrousavy

Thanks for the response. Interesting, so npx react-native run-android not only looks at android/app/build.gradle it also looks at all of the build.gradle files in node_modules/? That's really interesting, had no idea.

jzxchiang1 avatar Oct 16 '21 18:10 jzxchiang1

I'm looking at this again, and I'm curious why the prepareJSC gradle task writes to this directory, but CMakeLists.txt never actually uses that to compile or link?

jzxchiang1 avatar Nov 26 '21 07:11 jzxchiang1

OK I got it working with a local patch: https://gist.github.com/jzxchiang1/012af920bca8b335faab2d913fd6293d

So now I'm running:

  • react-native 0.64.2
  • react-native-reanimated 2.2.2 (patched version published by @Kudo at npm:react-native-reanimated-v8)
  • react-native-v8 0.64.2-patch.1
  • react-native-vision-camera 2.9.4

Note that iOS works without any changes (besides pod install).

This is a workaround until reanimated officially supports v8, which I hope they do since all the pieces are already there.

jzxchiang1 avatar Nov 26 '21 19:11 jzxchiang1

Nice job on the workaround @jzxchiang1 !

mrousavy avatar Nov 29 '21 13:11 mrousavy

https://github.com/software-mansion/react-native-reanimated/releases/tag/3.0.0-rc.1 reanimated now has a v8 compatiable version

sunnylqm avatar Aug 17 '22 02:08 sunnylqm

Bump!

jzxchiang1 avatar Aug 25 '22 06:08 jzxchiang1

V8 Support has been added to react-native-reanimated with 2.10.0 release v2.10.0 react-native-reanimated now officially supports v8 engine

Is that possible to add the v8 support to react-native-vision-camera too?

dipcore avatar Sep 14 '22 12:09 dipcore

Shouldn't be too difficult, I just don't have a need for it and don't have the free time to work on this atm

mrousavy avatar Sep 14 '22 13:09 mrousavy

@mrousavy Thanks for answering!

In the description it says Added support for react-native-v8 (building from source only) means there is no .aar files provided with react-native-reanimated package.

In the line 282 (https://github.com/mrousavy/react-native-vision-camera/blob/main/android/build.gradle#L282) we use .aar to extractJNI So it seems for me its a bit more complicated...

What do you think?

dipcore avatar Sep 14 '22 13:09 dipcore