Closed thejoshuafazel closed 1 year ago
Assigning to @darax (tracking n#42358353)
check if this is related https://github.com/Azure/azure-spatial-anchors-samples/issues/363 I don't now about unity but in android ndk you have to be careful with how you configure location provider sensors.
@sergeiromanov Went through that issue before logging this one. My wifi, bluetooth and gps are ON before running the application.
@thejoshuafazel Looking through https://forum.unity.com/threads/gps-not-work-well-on-android-12.1212534/ this sounds like a known issue that was fixed in a later unity build.
Can you try Unity >= 2020.3.31f1?
@darax Tried the same project with unity 2020.3.42f1 and the crash still occurs.
Additional Information: While messing around in code, I tried asking for the location access before starting the ASA session and it works fine but as soon as the ASA session starts the app crashes.
In logcat I see this: 2022-11-29 11:42:30.275 7061-7088/com.microsoft.azure.spatialanchors.examples.unity.helloar A/s.unity.helloa: java_vm_ext.cc:579] JNI DETECTED ERROR IN APPLICATION: JNI AllocObject called with pending exception java.lang.SecurityException: Need android.permission.BLUETOOTH_SCAN permission for AttributionSource { uid = 10412, packageName = com.microsoft.azure.spatialanchors.examples.unity.helloar, attributionTag = null, token = android.os.BinderProxy@db9381, next = null }: GattService registerScanner
I'm getting my lastest unity install setup with android so I can try myself, but I wonder if it works if you either don't ask for bluetooth location or the bluetooth_scan is added to the android manifest.
Do you mean that either we dont ask for bluetooth location permission or the bluetooth_scan should be added to the android manifest?
Yes. I'm halfway through building without a change now to make sure I'm still reproducing this. After I confirm I'll try the workarounds. Hopefully adding the bluetooth_scan permission to the manifest works.
@thejoshuafazel
I didn't see a crash when I rebuilt, but I was using the unity 2022.2 beta when I did this ( most of my time was spent futzing with input. :)). It was failing to complete the demo.
to Assets/Plugins/Android/AndroidManifest.xml I added
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
to Assets/AzureSpatialAnchors.Examples/Scripts/SensorPermissionsHelper I added:
const string androidBluetoothScanPermission = "android.permission.BLUETOOTH_SCAN";
and in RequestSensorPermissions() is added a call:
RequestPermissionIfNotGiven(androidBluetoothScanPermission);
after that the coarse reloc demo worked again. LMK if this works for you. If it doesn't, maybe there is a hint in logcat.
@darax
Can you tell me the package versions you used for unity 2022.2 beta?
Using the following: XR Core v2.1.0 AR Foundation v5.0.3 Azure Spatial Anchors SDK v2.13.3
Getting the following errors when opening the project with unity 2022.2 beta:
Library\PackageCache\com.microsoft.azure.spatial-anchors-sdk.core@fc109db5a78b\Runtime\Scripts\SpatialAnchorManager.cs(404,17): error CS0012: The type 'XROrigin' is defined in an assembly that is not referenced. You must add a reference to assembly 'Unity.XR.CoreUtils, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Library\PackageCache\com.microsoft.azure.spatial-anchors-sdk.core@fc109db5a78b\Runtime\Scripts\SpatialAnchorManager.cs(404,61): error CS0012: The type 'XROrigin' is defined in an assembly that is not referenced. You must add a reference to assembly 'Unity.XR.CoreUtils, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Library\PackageCache\com.microsoft.azure.spatial-anchors-sdk.core@fc109db5a78b\Runtime\Scripts\SpatialAnchorManager.cs(404,61): error CS1061: 'ARSessionOrigin' does not contain a definition for 'enabled' and no accessible extension method 'enabled' accepting a first argument of type 'ARSessionOrigin' could be found (are you missing a using directive or an assembly reference?)
Library\PackageCache\com.microsoft.azure.spatial-anchors-sdk.core@fc109db5a78b\Runtime\Scripts\SpatialAnchorManager.cs(797,31): error CS0311: The type 'UnityEngine.XR.ARFoundation.ARSessionOrigin' cannot be used as type parameter 'T' in the generic type or method 'Object.FindObjectOfType<T>()'. There is no implicit reference conversion from 'UnityEngine.XR.ARFoundation.ARSessionOrigin' to 'UnityEngine.Object'.
Library\PackageCache\com.microsoft.azure.spatial-anchors-sdk.core@fc109db5a78b\Runtime\Scripts\SpatialAnchorManager.cs(797,31): error CS0012: The type 'XROrigin' is defined in an assembly that is not referenced. You must add a reference to assembly 'Unity.XR.CoreUtils, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
In the meantime, I looked through the logcat errors
The fatal error is
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] JNI DETECTED ERROR IN APPLICATION: JNI NewString called with pending exception java.lang.IllegalArgumentException: provider "gps" does not exist
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at java.lang.Exception android.os.Parcel.createExceptionOrNull(int, java.lang.String) (Parcel.java:2460)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at java.lang.Exception android.os.Parcel.createException(int, java.lang.String) (Parcel.java:2440)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Parcel.readException(int, java.lang.String) (Parcel.java:2423)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Parcel.readException() (Parcel.java:2365)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.ILocationManager$Stub$Proxy.registerLocationListener(java.lang.String, android.location.LocationRequest, android.location.ILocationListener, java.lang.String, java.lang.String, java.lang.String) (ILocationManager.java:1445)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.LocationManager.requestLocationUpdates(java.lang.String, android.location.LocationRequest, java.util.concurrent.Executor, android.location.LocationListener) (LocationManager.java:1498)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, java.util.concurrent.Executor, android.location.LocationListener) (LocationManager.java:1186)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper) (LocationManager.java:1151)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean com.microsoft.mixedreality.spatialservices.coarserelocalization.AndroidGeoLocationWatcher.resume() (AndroidGeoLocationWatcher.java:61)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean com.unity3d.player.UnityPlayer.access$300(com.unity3d.player.UnityPlayer) ((null):-1)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean com.unity3d.player.UnityPlayer$e$1.handleMessage(android.os.Message) ((null):-1)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:201)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Looper.loop() (Looper.java:288)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at void com.unity3d.player.UnityPlayer$e.run() ((null):-1)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] Caused by: android.os.RemoteException: Remote stack trace:
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at com.android.internal.util.Preconditions.checkArgument(Preconditions.java:59)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at com.android.server.location.LocationManagerService.registerLocationListener(LocationManagerService.java:746)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:585)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at android.os.Binder.execTransactInternal(Binder.java:1184)
2022-11-30 19:49:51.488 15378 15398 Fatal s.unity.helloa java_vm_ext.cc:594] at android.os.Binder.execTransact(Binder.java:1143)
@thejoshuafazel
For 2022.2 I'm using
"com.unity.xr.arcore": "5.0.0-pre.13",
"com.unity.xr.arfoundation": "5.0.0-pre.13",
"com.unity.xr.arkit": "5.0.0-pre.13",
"com.unity.xr.arsubsystems": "5.0.0-pre.13",
"com.unity.xr.management": "4.2.0",
"com.unity.xr.openxr": "1.5.1",
I would recommend first trying the unity version you were using (before 2022.2) while making the following modifications to the android files.
to Assets/Plugins/Android/AndroidManifest.xml I added
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
to Assets/AzureSpatialAnchors.Examples/Scripts/SensorPermissionsHelper I added:
const string androidBluetoothScanPermission = "android.permission.BLUETOOTH_SCAN";
and in RequestSensorPermissions() is added a call:
RequestPermissionIfNotGiven(androidBluetoothScanPermission);
if you really want to use 2022.2, I posted instructions here: https://github.com/Azure/azure-spatial-anchors-samples/issues/389. The above modifications will still be necessary.
@darax
I would rather stick to the version I was using before. Made the changes you suggested and still getting the same error as before. Pasting it below as well. You can find the full logs here : com.microsoft.azure.spatialanchors.examples.unity.helloar-logcat.txt
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] JNI DETECTED ERROR IN APPLICATION: JNI NewString called with pending exception java.lang.IllegalArgumentException: provider "gps" does not exist
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at java.lang.Exception android.os.Parcel.createExceptionOrNull(int, java.lang.String) (Parcel.java:2460)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at java.lang.Exception android.os.Parcel.createException(int, java.lang.String) (Parcel.java:2440)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Parcel.readException(int, java.lang.String) (Parcel.java:2423)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Parcel.readException() (Parcel.java:2365)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.ILocationManager$Stub$Proxy.registerLocationListener(java.lang.String, android.location.LocationRequest, android.location.ILocationListener, java.lang.String, java.lang.String, java.lang.String) (ILocationManager.java:1445)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.LocationManager.requestLocationUpdates(java.lang.String, android.location.LocationRequest, java.util.concurrent.Executor, android.location.LocationListener) (LocationManager.java:1498)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, java.util.concurrent.Executor, android.location.LocationListener) (LocationManager.java:1186)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.location.LocationManager.requestLocationUpdates(java.lang.String, long, float, android.location.LocationListener, android.os.Looper) (LocationManager.java:1151)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean com.microsoft.mixedreality.spatialservices.coarserelocalization.AndroidGeoLocationWatcher.resume() (AndroidGeoLocationWatcher.java:61)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void com.unity3d.player.UnityPlayer.nativeFocusChanged(boolean) ((null):-2)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void com.unity3d.player.UnityPlayer.access$000(com.unity3d.player.UnityPlayer, boolean) ((null):-1)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void com.unity3d.player.UnityPlayer$e$1.a() ((null):-1)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean com.unity3d.player.UnityPlayer$e$1.handleMessage(android.os.Message) ((null):-1)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:201)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void android.os.Looper.loop() (Looper.java:288)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at void com.unity3d.player.UnityPlayer$e.run() ((null):-1)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] Caused by: android.os.RemoteException: Remote stack trace:
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at com.android.internal.util.Preconditions.checkArgument(Preconditions.java:59)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at com.android.server.location.LocationManagerService.registerLocationListener(LocationManagerService.java:746)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:585)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at android.os.Binder.execTransactInternal(Binder.java:1179)
2022-12-06 19:34:26.378 13754 13775 Fatal s.unity.helloa java_vm_ext.cc:594] at android.os.Binder.execTransact(Binder.java:1143)
Hey @darax,
I think I may have found the problem.
Before going to the problem here is what I did to debug the issue:
Wrote the following code to see the output:
fun getAllProviders() {
val context: Context = this.baseContext
// Get a reference to the location manager
val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
// Get a list of all providers
val providers = locationManager.getAllProviders()
Log.e(null,locationManager.isLocationEnabled.toString())
// Print the list of providers
for (provider in providers) {
Log.e(null,provider)
}
}
After this went digging through the ASA sdk code.
Let me know if there is a work around for this, or when this will be supported in ASA. We really want to use ASA for our project, hope this is fixed soon.
Nice find! Out of curiosity can you modify the java to request the FUSED_PROVIDER instead of the GPS_PROVIDER?
@darax
I'm not able to recompile the coarserelocalization-3.0.0-release0104 after de-compiling it. Can you try it and let me know?
@darax
Could you perhaps try the change you suggested and recompile the com.microsoft.azure.spatial-anchors-sdk.android-2.13.0.tgz and send it to me? I can test it out
@thejoshuafazel I don't have a way to share an internal build (policy, not technology). I spoke with the team, and the fused location provider was used previously and the results from the network provider was providing better results than the fused location provider. Clearly asking for the "gps" provider when it is not on the system is a bug, and I'm going to work on a fix. Hard to anticipate when the next release will be, but I'd expect January or February. Once I have the fix in an internal build I'll also try to get this out as a 'hotfix'. This might take me some time logistically. The fix is straightforward. The coarse reloc packages are owned by a sister team, and this will be my first time contributing code to their repository.
@darax
I understand that sharing the build might not be possible at this moment but I do have a few questions based on your response.
fixed in 2.14.1
Description
Trying out Geolocation for Coarse Relocation and encountering a crash when enabling the sensors. Tried it out on two different projects, the first one being the Coarse Relocation Demo Example from this repository and the second one being a similar code to the example but with only Geolocation enabled. Building only for android.
Steps to reproduce the issue
Sample Application: First Run:
Second Run: *Note: The location permission is granted for the application when checking the application settings
My Application: The code Setup is very similar but only Geolocation is enabled in code, everything else is commented out from the sample code. Only one scene in the application i.e. the Coarse Relocation Scene along with the main menu.
First Run:
*Note: The location permission is granted for the application when checking the application settings First Run:
Expected behavior
GPS Sensor should be enabled and can be used for setting up and viewing the anchor.
Screenshots
My Appplication:
The message 'True' is a log from the SensorPermissionHelper.HasGeoLocationPermission() function call.
The application throws the following error:
Autoconnected Player InvalidOperationException: CoarseReloc: Location access has been declined. at Microsoft.Azure.SpatialAnchors.NativeLibraryHelpers.CheckStatus (System.IntPtr handle, Microsoft.Azure.SpatialAnchors.status value) [0x00000] in <00000000000000000000000000000000>:0 at Microsoft.Azure.SpatialAnchors.PlatformLocationProvider.get_GeoLocationStatus () [0x00000] in <00000000000000000000000000000000>:0 at SetupAnchorScript.Update () [0x00000] in <00000000000000000000000000000000>:0
Development information
AR Device information (please complete the following information):**
Additional context
All logs have been enabled in the 'Logging Level' option. Bluetooth, GPS and WIFI are enabled at all times. All the other example scenes seem to be working fine so it does not look like a config issue.
Additionally, have tried my application with Android Version 12 (One UI-Version is 4.1) on a Galaxy A3 5G. It seems to be working fine on it, this seems to me like a device specific problem. Is there anything I can do to narrow down the issue?