Azure / azure-spatial-anchors-samples

Azure Spatial Anchors sample code
Other
293 stars 139 forks source link

CreateSessionAsync hangs indefinitely on Android with Unity 2019.4.14f1 #230

Closed oyvind-soroy closed 2 years ago

oyvind-soroy commented 3 years ago

I have debug-logged every step of the way and can't seem to get past the CloudManager.CreateSessionAsync()-step. Everything is set up in Azure according to the documentation here: https://docs.microsoft.com/en-us/azure/spatial-anchors/tutorials/tutorial-share-anchors-across-devices?tabs=azure-portal%2CVS%2CUnity#create-a-spatial-anchors-resource

I have tried it for UWP, iOS, and 'Roid.

I also made a custom implementation to see if I could understand what is going on, but a lot of the code is seemingly pattern-locked boilerplate which could be best hidden behind in the API, like an async Task-method you can call that returns a bool if it succeeded or not.

Steps to reproduce the issue

  1. Open the Unity-project in Unity 2019.4.14f1.
  2. Build for any platform you have a device for.
  3. Click the "Next Step"-button.

Expected behavior

Everything just works as explained in the documentation.

Screenshots

If applicable, add screenshots to help explain your problem.

Development information (please complete the following information)

AR Device information (please complete the following information):

Additional context

I wish this was better documented on what to expect from the behaviour and how to work around.

msftradford commented 3 years ago

Hi @oyvind-soroy, thanks for reaching out! I'll be happy to help track this down with you. What version of the ASA SDK are you using? Please keep in mind that starting in February, ASA SDK 2.7.0 will become the minimum supported version. Are you able to run the ASA Unity sample scenes without any issues? Does this issue occur when Script Debugging and Development Build are disabled in Unity? Have you placed breakpoints inside of CreateSessionAsync() to see where it starts to hang?

oyvind-soroy commented 3 years ago

I wrote that I am using the latest, which is the version that is of the most recent date. I didn't look at the version number but I presume it is 2.7.0 according to what I can see. Here is where I got it from (the green button in the repository view with the readme.md displayed below, last downloaded on the 16th of December 2020): https://github.com/Azure/azure-spatial-anchors-samples/archive/master.zip

By run do you mean click Play in the editor without any errors preventing it from playing? If so, yes, I can.

I assumed the build settings were as intended and have not changed any build settings beyond what I have tested of variations after I tried the default project settings that did not work.

CreateSessionAsync() goes to [from metadata] in VS2019 so I can't place breakpoints because there is nothing there for me to place breakpoints in.

msftradford commented 3 years ago

Thanks for the info @oyvind-soroy. In order to step through the code, you'll have to create your own copy of SpatialAnchorManager, but we'll keep that in our back pocket for now. Can you send me one of your log files for a session that hangs on either your iOS or Android device?

oyvind-soroy commented 3 years ago

I am still testing across devices/Azure resource groups in the case that something on our end is wrong. I can oversend the logs after the testing sessions today.

oyvind-soroy commented 3 years ago

As stated I debug-logged every step of the way and here is where it failed on Android (sorry about the formatting but this place is horrible for that for some reason):

` if (!javaInitialized) { FeedBaccText.text = "Initialising Java."; // THIS IS WHERE IT STOPS PROCEEDING. // Create a TaskCompletionSource that we can use to know when // the Java plugin has completed initialization on the Android // thread. TaskCompletionSource pluginInit = new TaskCompletionSource();

            // Make sure ARCore is running. This code must be executed
            // on a Java thread provided by Android.
            AndroidHelper.Instance.DispatchUiThread(unityActivity =>
            {
                // Create the plugin
                using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
                {
                    // Initialize the plugin
                    cloudServices.CallStatic("initialize", unityActivity);

                    // Update static variable to say that the plugin has been initialized
                    javaInitialized = true;

                    // Set the task completion source so the CreateSession method can
                    // continue back on the Unity thread.
                    pluginInit.SetResult(true);
                }
            });

            // Wait for the plugin to complete initialization on the
            // Java thread.
            await pluginInit.Task;
        }

` Still testing iOS but due to an unprecedented amount of updates etc. needed it's not gone as fast as I had hoped. I hope to get some answers from testing soon, though.

msftradford commented 3 years ago

@oyvind-soroy, does it get stuck on the line with the DispatchUiThread() call? Can you let me know if you have "Initialize XR on Startup" checked in Project Settings->XR Plug-in Management? If so, can you try stepping past the DispatchUiThread() call with "Initialize XR on Startup" unchecked?

oyvind-soroy commented 3 years ago

Unchecked still goes inside this block: `if (!javaInitialized) { FeedBaccText.text = "Initialising Java."; // Create a TaskCompletionSource that we can use to know when // the Java plugin has completed initialization on the Android // thread. TaskCompletionSource pluginInit = new TaskCompletionSource();

            // Make sure ARCore is running. This code must be executed
            // on a Java thread provided by Android.
            AndroidHelper.Instance.DispatchUiThread(unityActivity =>
            {
                // Create the plugin
                using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
                {
                    // Initialize the plugin
                    cloudServices.CallStatic("initialize", unityActivity);

                    // Update static variable to say that the plugin has been initialized
                    javaInitialized = true;

                    // Set the task completion source so the CreateSession method can
                    // continue back on the Unity thread.
                    pluginInit.SetResult(true);
                }
            });

            // Wait for the plugin to complete initialization on the
            // Java thread.
            await pluginInit.Task;
        }`
msftradford commented 3 years ago

Thanks @oyvind-soroy. If I understand correctly, you have "Initialize XR on Startup" unchecked and you are stepping into the javaInitialized if statement, but at some point it hangs indefinitely. Are you able to step past the FeedBaccText.text update call as well as the plugInit call? Can you step into the DispatchUiThread() call? If you can, how far can you step before it hangs? Have you looked at the logcat around the time of hang to see if anything interesting is getting logged?

oyvind-soroy commented 3 years ago

After FeedBaccText.text = "Initialising Java."; is where it stops progressing.

[edit] Where it hangs is:

await pluginInit.Task;

Also, I tried to just fake it by automatically accepting, but now I get:

"Unable to load DLL 'azurespatialanchorsndk': The specified module could not be found."

msftradford commented 3 years ago

Thanks @oyvind-soroy. We haven't been able to reproduce this issue yet. Would you mind sending me your logs for one of these sessions?

oyvind-soroy commented 3 years ago

Yes, I am going to provide a log later today hopefully. I need to be able to test on the same device again for consistency, but it is currently unavailable.

Varnauld commented 2 years ago

This issue has been closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

hagenfilip commented 2 years ago

Hey, sorry for commenting on this old issue. I have been trying to port one of our apps from iOS to Android devices. It works perfectly for iOS, but not for Android.

When doing this I have stumbled upon the same issue as here. I have the same code as shown above. Was there any solution uncovered for this problem?

Varnauld commented 2 years ago

Hello, thank you for reaching out. Assigned to @pamistel (tracking #38407464)

johannesvollmer commented 2 years ago

We had a similar Problem. We use the exported Unity Project as a compiled dependency inside another separate app, let's call it the Host App.

We found that the Java code could not load a certain AppCenter class, and it hangs instead of throwing an error (in the TelemetryHelper class). The AppCenter class was missing, even though we specified the gradle dependencies using implementation('com.microsoft.appcenter:...'), as suggested in the documentation:

  1. Open your mainTemplate.gradle file in a text editor.
  2. In the dependencies section, paste the following dependencies:
    implementation('com.squareup.okhttp3:okhttp:[3.11.0]')
    implementation('com.microsoft.appcenter:appcenter-analytics:[1.10.0]')

However, as it turns out, the way gradle works makes the dependency disappear in the context of our Host App. Now, by also also including these two gradle dependencies in our Host App, it works. There are probably other ways of making it work though, maybe by changing the implementation('com....') to api('com....') in the Unity gradle template (which unfortunately did not work for our custom dependency system).

darax commented 2 years ago

@johannesvollmer would you mind filing a new issue for this? Unity's feature which allows you to access unity like a lib isn't something we've spent time investigating. It does sound like you have a workaround, please let me know if I'm wrong.

johannesvollmer commented 2 years ago

There is no particular unexpected behavior regarding the azure anchors. What was unexpected was the fact that Java did not throw an exception when a class was missing, instead it just hung indefinitely. This was probably some weird Java issue.

The class was missing, because we forgot to copy the implementation(...) statement to another Gradle file. Maybe this also helps other people stumbling across this issue.

Maybe this isn't event the original error, as our error did not have anything to do with DLLs. Maybe it will help someone nevertheless

LexDeKogel commented 1 year ago

I'm still having this same issue, we are just working on a single Unity project so I don't know if gradle could somehow be overwritten. It always hangs on CreateSessionAsync without giving errors and I don't understand why. My dependencies in the main graddle look like this

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation('com.squareup.okhttp3:okhttp:[3.11.0]') implementation('com.microsoft.appcenter:appcenter-analytics:[1.10.0]') DEPS}

Varnauld commented 1 year ago

Hello @LexDeKogel could you open a new issue for this please? thank you!

LexDeKogel commented 1 year ago

@Varnauld Yes thanks, I just created https://github.com/Azure/azure-spatial-anchors-samples/issues/383