facebookresearch / playtorch

PlayTorch is a framework for rapidly creating mobile AI experiences.
https://playtorch.dev/
MIT License
830 stars 101 forks source link

PlayTorchJSIModule not found - ios & android m2 macbook pro #201

Open rbmdotdev opened 1 year ago

rbmdotdev commented 1 year ago

Version

0.2.4

Problem Area

react-native-pytorch-core (core package)

Steps to Reproduce

follow these instructions on a 2023 m2 MacBook pro (not positive this is the cause) until you get to the section "Use PlayTorch SDK"

up until this point the expo app will work correctly for each of the following commands npx expo start npm run ios npm run android

once you add the import

import { torch } from 'react-native-pytorch-core';

The exception from line 27 of install-jsi.ts will be thrown when you run npx expo start

If you run npm run ios I get an extremely long xcodebuild error, I have posted what I think is the relevant portion below

› Compiling react-native Pods/libevent » signal.c
    Run script build phase '[CP-User] Generate app.config for prebuilt Constants.manifest' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'EXConstants' from project 'Pods')
    Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'testapp' from project 'testapp')
    Run script build phase 'Start Packager' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'testapp' from project 'testapp')

› 0 error(s), and 3 warning(s)

CommandError: Failed to build iOS project. "xcodebuild" exited with error code 65.
To view more error logs, try building the app with Xcode directly, by opening /Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/ios/testapp.xcworkspace.

Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -workspace /Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/ios/testapp.xcworkspace -configuration Debug -scheme testapp -destination id=CAC7A930-B0AD-4927-9DA6-DDCD8DA30303

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES

Prepare packages

Computing target dependency graph and provisioning inputs

if you run npm run android I get the following error

BUILD FAILED in 3s
5 actionable tasks: 4 executed, 1 from cache
Error: /Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/android/gradlew exited with non-zero code: 1
Error: /Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/android/gradlew exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)
    ...
    at Object.spawnAsync [as default] (/Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
    at spawnGradleAsync (/Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)
    at Object.assembleAsync (/Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)
    at runAndroidAsync (/Users/rbmdotdev/workspace/rbmdotdev/portfolio/test-app/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:31:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

removing the import allows npx expo start to work again however npm run ios and npm run android still throw the same error

Expected Results

I expext to be able to follow the instructions on this tutorial https://playtorch.dev/docs/tutorials/get-started-expo-app/ and get a working app

Code example, screenshot, or link to repository

No response

rraihansaputra commented 1 year ago

I have the same issue, just to help clarify:

  1. PlayTorchJSIModule is not found -> this happens when scanning the Expo QR on Expo Go, correct?
  2. I also have problems following the steps in the https://playtorch.dev/docs/tutorials/get-started-expo-app/ tutorial.

2a. torchlib-lite seems to not have.. something built for arm yet. I needed to disable arm64 as a build target for simulators 2b. After disabling arm64 build targets, I encounter this:

❌  (/Users/rs/Projects/uni/capstone/app/node_modules/expo-modules-core/ios/Swift/Functions/ConcurrentFunctionDefinition.swift:49:5)

  47 | 
  48 |     // Switch from the synchronous context to asynchronous
> 49 |     Task { [arguments] in
     |     ^ 'Task' is only available in iOS 13.0 or newer
  50 |       let result: Result<Any, Exception>
  51 | 
  52 |       do {

❌  (/Users/rs/Projects/uni/capstone/app/node_modules/expo-modules-core/ios/Swift/Functions/ConcurrentFunctionDefinition.swift:49:5)

  47 | 
  48 |     // Switch from the synchronous context to asynchronous
> 49 |     Task { [arguments] in
     |     ^ 'init' is only available in iOS 13.0 or newer
  50 |       let result: Result<Any, Exception>
  51 | 
  52 |       do {

I already tried reinstalling the expo-modules-core but still can't continue.

The biggest problem here is that the tutorial/docs is outdated and we can't even start a new project following the steps.

rraihansaputra commented 1 year ago

After more digging, seems like https://github.com/facebookresearch/playtorch/issues/195 is related.

I managed to run the tutorial steps, modified:

  1. change the first step (creating expo app) with SDK 47: I think this is related to the newer RN version incompatibility, as i didn't encounter issue 2b i described above.
    npx create-expo-app my_app --template blank@47
  2. once you have ran npx expo prebuild, run xed ios and disable arm64 bulid target. Follow these steps:

B. Pods -> PROJECT -> Pods -> Build Settings -> Excluded Architectures -> Add arm64

For building CocoaPods library.

from: https://developer.apple.com/forums/thread/672541?answerId=722978022#722978022

now you should be able to run npm run ios and continue the tutorial