# Await xr.baseExperience.enterXRAsync doesn't return on Android device

**URL:** <https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801>\
**Category:** Questions\
**Tags:** native, webxr, react-native\
**Created:** [November 20, 2023, 2:39am UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801 "2023-11-20T02:39:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivas\_kumar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srinivas_kumar/32/35901_2.png) [@srinivas\_kumar](https://forum.babylonjs.com/u/srinivas_kumar)\
**Post date:** [November 20, 2023, 2:39am UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801/1 "2023-11-20T02:39:24Z")

</div>

Hello!  
I’m very new to React Native (and JS in general), so I apologize in advance

I’m trying to launch a simple XR(AR) session on my Samsung Galaxy S21 phone.  
I have react native and the babylon dependencies installed/

EDIT: A few notes about how I differed from the instruction to install babylon react native.  
The [Instructions for a fresh project](https://github.com/BabylonJS/BabylonReactNativeSample/blob/main/CREATE.md) recommend using React native 0.69, but that won’t work properly on my m1 mac, so I used react 71.

But this required me to use [@babylonjs/react-native-iosandroid-0-71 - npm](https://www.npmjs.com/package/@babylonjs/react-native-iosandroid-0-71) (not 64) and my installation command became  
`pm i @babylonjs/react-native@1.6.4-preview @babylonjs/react-native-iosandroid-0-71 @babylonjs/core @babylonjs/loaders react-native-permissions --legacy-peer-deps`. This was needed because 1.6.4 oreview was updated to work with loaders package according to this [answer](https://forum.babylonjs.com/t/error-babylonjs-react-native-1-6-3-requires-babylonjs-core-5-42-2-but-version-6-14-0-is-currently-installed-run-npm-install-babylonjs-core-5-42-2-in-your-apps-root-directory-to-upgrade/42923)

The scene the code I took from the sample renders fine even with a few small changes

but when I press the Start XR button, nothing happens. I added some debugging logs inside  
and only the first one `test message 1` is printed.

I think `await xr.baseExperience.enterXRAsync` is not returning, am I invoking it correctly?

This is my code

```auto

import React, {
  FunctionComponent,
  useEffect,
  useCallback,
  useState,
} from 'react';

import {SafeAreaView, View, Button, ViewProps, StatusBar} from 'react-native';

import {EngineView, useEngine} from '@babylonjs/react-native';
import {SceneLoader} from '@babylonjs/core/Loading/sceneLoader';
import {Camera} from '@babylonjs/core/Cameras/camera';
import {ArcRotateCamera} from '@babylonjs/core/Cameras/arcRotateCamera';
import '@babylonjs/loaders/glTF';
import {Scene} from '@babylonjs/core/scene';
import {WebXRSessionManager, WebXRTrackingState} from '@babylonjs/core/XR';
import {LogBox} from 'react-native';

const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
  const engine = useEngine();
  const [camera, setCamera] = useState<Camera>();
  const [xrSession, setXrSession] = useState<WebXRSessionManager>();
  const [trackingState, setTrackingState] = useState<WebXRTrackingState>();
  const [scene, setScene] = useState<Scene>();

  const onToggleXr = useCallback(() => {
    (async () => {
      try {
        if (xrSession) {
          await xrSession.exitXRAsync();
        } else if (scene) {
          const xr = await scene.createDefaultXRExperienceAsync({
            disableDefaultUI: true,
            disableTeleportation: true,
          });
          console.log("test message 1");
          const session = await xr.baseExperience.enterXRAsync(
            'immersive-ar',
            'unbounded',
            xr.renderTarget,
          );
          console.log("test message 2");
          setXrSession(session);
          console.log("test message 3");
        }
      } catch (error) {
        console.error("Failed to toggle XR", error);
      }
    })();
  }, [scene, xrSession]);

  useEffect(() => {
    if (engine) {
      const url =
        'https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf';
      SceneLoader.LoadAsync(url, undefined, engine).then(loadScene => {
        setScene(loadScene);
        loadScene.createDefaultCameraOrLight(true, undefined, true);
        (loadScene.activeCamera as ArcRotateCamera).alpha += Math.PI;
        (loadScene.activeCamera as ArcRotateCamera).radius = 10;
        setCamera(loadScene.activeCamera!);
      });
    }
  }, [engine]);

  return (
    <>
      <View style={props.style}>
        <Button
          title={xrSession ? 'Stop XR' : 'Start XR'}
          onPress={onToggleXr}
        />
        <View style={{flex: 1}}>
          <EngineView camera={camera} displayFrameRate={true} />
        </View>
      </View>
    </>
  );
};

const App = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={{flex: 1, backgroundColor: 'white'}}>
        <EngineScreen style={{flex: 1}} />
      </SafeAreaView>
    </>
  );
};

export default App;

```

If launching for the first time, if i minimize the app and go back in I get

> LOG test message 1  
> LOG [Error: ARCore not installed.]  
> LOG ARCore not installed.  
> ERROR Failed to toggle XR [Error: ARCore not installed.]

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [November 20, 2023, 11:35pm UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801/2 "2023-11-20T23:35:37Z")

</div>

cc [@BabylonNative](https://forum.babylonjs.com/groups/babylonnative) to help on this one 🙂 @ryantrem might also have an idea.

---

<div class="post-metadata">

**Author:** ![dalidaliW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/dalidaliw/32/28108_2.png) [@dalidaliW](https://forum.babylonjs.com/u/dalidaliW)\
**Post date:** [November 21, 2023, 2:11am UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801/3 "2023-11-21T02:11:00Z")

</div>

> [@srinivas\_kumar](#):
>
> ARCore

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/b/7b16050f621413bc39ee819093461da1d175a79a.png)

[SDK Downloads | ARCore | Google for Developers](https://developers.google.cn/ar/develop/downloads)  
I’m not sure if this can solve your problem

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [November 21, 2023, 3:30am UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801/5 "2023-11-21T03:30:48Z")

</div>

To try to narrow things down, have you tried running the Playground app in the BabylonReactNative repo? Do you get the same error?

---

<div class="post-metadata">

**Author:** ![ryantrem](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/ryantrem/32/34010_2.png) [@ryantrem](https://forum.babylonjs.com/u/ryantrem)\
**Post date:** [November 21, 2023, 3:36am UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801/6 "2023-11-21T03:36:49Z")

</div>

Also did you include ARCore in your AndroidManifest.xml (something like )?

---

<div class="post-metadata">

**Author:** ![srinivas\_kumar](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/srinivas_kumar/32/35901_2.png) [@srinivas\_kumar](https://forum.babylonjs.com/u/srinivas_kumar)\
**Post date:** [November 27, 2023, 12:31am UTC](https://forum.babylonjs.com/t/await-xr-baseexperience-enterxrasync-doesnt-return-on-android-device/45801/7 "2023-11-27T00:31:45Z")

</div>

hi, thanks for all the help.

The error about ARCore not being installed it appears was a little misleading, the problem was that I had downloaded a different version of react-native-permissions and that did not work right.

Using the versions from the sample app worked fine and I am able to launch it, Thanks everyone
