viro icon indicating copy to clipboard operation
viro copied to clipboard

Crash on simulator, any workaround?

Open tedcu opened this issue 1 year ago β€’ 4 comments

Requirements:

Environment

Mac, iOS 17.2, iPhone 15 Pro simulator

"@reactvision/react-viro": "^2.41.6",
"react-native": "0.73.5",

Bare react native project, non-expo.

Description

Simulator crashes immediately on startup, even without using any viro-react features. I was looking through some previous issues where this is mentioned, but I don't think any of them were actually solved, just closed.

I don't need AR features on a simulator, but it would be nice to run e2e and develop features that are not related to AR on a sim. So, any workarounds? Real device works, of course, but we need simulator to at least not crash.

Trace snippet:

Termination Reason: DYLD 1 Library missing
Library not loaded: @rpath/GTMSessionFetcher.framework/GTMSessionFetcher
Referenced from: <5D09F0A1-93BE-31F2-B28B-565B1A89B535> /Users/me/Library/Developer/CoreSimulator/Devices/91AD94B5-3753-4246-AD68-2962FF689C49/data/Containers/Bundle/Application/5CB74D3C-B33B-45EA-ACEE-E1BD134056F1/Marketplace.app/Frameworks/ViroKit.framework/ViroKit
Reason: tried: '/Users/me/Library/Developer/CoreSimulator/Devices/91AD94B5-3753-4246-AD68-2962FF689C49/data/Containers/Bundle/Application/5CB74D3C-B33B-45EA-ACEE-E1BD134056F1/Marketplace.app/Frameworks/GTMSessionFetcher.framework/GTMSessionFetcher' (no such file), '/Users/me/Library/Developer/CoreSimulator/Devices/91AD94B5-3753-4246-AD68-2962FF689C49/data/Containers/Bundle/Application/5CB74D3C-B33B-45EA-ACEE-E1BD134056F1/Marketplace.app/Frameworks/ViroKit.framework/Frameworks/GTMSessionFetcher.framework/GTMSessionFetcher' (no such file), '/Users/me/Library/Developer/CoreSimulator/Devices/91AD94B5-3753-4246-AD68-2962FF689C49/data/Container
(terminated at launch; ignore backtrace)

tedcu avatar Oct 23 '24 13:10 tedcu

you must run on a physical device, Apple Simulator and Android Emulator donΒ΄t acess ARCore (Android) and ARKit (iOS).

jefersonjuliani avatar Oct 28 '24 18:10 jefersonjuliani

It's not an ideal solution but we solved it by adding this condition to the Podfile

if !ENV["EXCLUDE_VIRO"]
 puts "adding VIRO.."
 pod 'ViroReact', :path => '../node_modules/@reactvision/react-viro/ios'
 pod 'ViroKit', :path => '../node_modules/@reactvision/react-viro/ios/dist/ViroRenderer/'
else
 puts "removing VIRO.."
end

in package.json then someting like this

"prepare:simulator": "EXCLUDE_VIRO=true; yarn install"

jirka-oone avatar Nov 23 '24 12:11 jirka-oone

I solved this a bit hacky by adding a config I called USE_VIRO as an environment variable, and then dynamically import Viro based on the config.

In My ARScreen:

let Viro3DObject: any,
  ViroAmbientLight: any,
  ViroARPlaneSelector: any,
  ViroARScene: any,
  ViroARSceneNavigator: any,
  ViroMaterials: any,
  ViroTrackingStateConstants: any;

if (config.USE_VIRO) {
  Viro3DObject = require('@reactvision/react-viro').Viro3DObject;
  ViroAmbientLight = require('@reactvision/react-viro').ViroAmbientLight;
  ViroARPlaneSelector = require('@reactvision/react-viro').ViroARPlaneSelector;
  ViroARScene = require('@reactvision/react-viro').ViroARScene;
  ViroARSceneNavigator = require('@reactvision/react-viro').ViroARSceneNavigator;
  ViroMaterials = require('@reactvision/react-viro').ViroMaterials;
  ViroTrackingStateConstants = require('@reactvision/react-viro').ViroTrackingStateConstants;
}

export default function ArScreen({ route, navigation }: ArScreenProps) {

  if (!config.USE_VIRO) {
    return (
      <View style={styles.placeholderView}>
        <Text style={textStyles.h4}>AR is disabled in this build</Text>
      </View>
    );
  }
  
  return (
      <ViroARScene
        onTrackingUpdated={handleTrackingUpdated}
        onAnchorUpdated={(_anchor: any) => setAnchorFound(true)}
      >
        <ViroAmbientLight color={'#ffffff'} />
        <ViroARPlaneSelector>
          // other viro stuff
        </ViroARPlaneSelector>
      </ViroARScene>
    );
  };
// 

Setup some way of getting the USE_VIRO config.

export const config = {
  USE_VIRO: !(process.env.USE_VIRO === 'false')
};

Adding the USE_VIRO env to the scripts:

{
  "scripts": {
    "start:dev": "USE_VIRO=true npx expo start --dev-client -c",
    "start:dev-simulator": "USE_VIRO=false npx expo start --dev-client -c",
    "build:ios-simulator": "USE_VIRO=false eas build --profile development-simulator --platform ios --local",
    "build:ios-dev": "USE_VIRO=true eas build --profile development --platform ios --local",
    "build:android-simulator": "USE_VIRO=false eas build --profile development --platform android --local",
    "build:android-dev": "USE_VIRO=true eas build --profile development --platform android --local",
  },
}

haakonjacobsen avatar Dec 21 '24 17:12 haakonjacobsen

@doranteseduardo I’m encountering the same issue. Since AR integration is just an additional feature in our app, it would be helpful if @reactvision/react-viro could provide a permanent and reliable solution. This would allow seamless integration of the dependency into projects that aren’t primarily focused on AR. Could we expect a proper resolution for this?

kaushalpanda22 avatar Jan 26 '25 17:01 kaushalpanda22