watson-developer-cloud / unity-sdk

:video_game: Unity SDK to use the IBM Watson services.
Apache License 2.0
569 stars 206 forks source link

Unable to Create Assistant Session when building to Android #613

Closed lncslncs closed 4 years ago

lncslncs commented 4 years ago

Hi there, I am experiencing this same issue as mentioned in a previous closed problem when building to Android. This is when trying to create an Assistant session, I get stuck in an infinite loop of "No Assistant Session created" (see below code, (while (!sessionCreated))). I am using Unity 2019.2.7f2 for Mac building to Android 8.0.0 on a Motorola G6. When I run in the editor on Mac it works perfectly but cannot get around this issue when building to Android.

if (string.IsNullOrEmpty(assistantIamApikey)) { throw new IBMException("Plesae provide IAM ApiKey for the Assistant service."); }

    IamAuthenticator assistantAuthenticator = new IamAuthenticator(apikey: assistantIamApikey);

    while (!assistantAuthenticator.CanAuthenticate()) {
        Debug.Log("Not yet authenticated Assitant");
            yield return null; }

    _assistant = new AssistantService("2019-02-08", assistantAuthenticator);
    if (!string.IsNullOrEmpty(AssistantURL))
        {
            _assistant.SetServiceUrl(AssistantURL);
        }

    _assistant.CreateSession(OnCreateSession, assistantId);
    Debug.Log("Created Assistant Instance");

    while (!sessionCreated) {
        yield return null;
        Debug.Log("No Assistant Instance Created"); // Here stuck in infinite loop

    }

Originally posted by @lncslncs in https://github.com/watson-developer-cloud/unity-sdk/issues/515#issuecomment-573631504

lncslncs commented 4 years ago

Realised that this might well not be an issue with the SDKs and instead an android issue, although it persists when tried on other android devices. On further investigation, the server is returning a 403 error and that's what's causing the loop.

[ERROR][RESTConnector.ProcessRequestQueue()]: URL: (url code here) , ErrorCode: 403, Error: HTTP/1.1 403 Forbidden, Response: {"code":403, "error": "Forbidden"}

mamoonraja commented 4 years ago

Hi @lncslncs, thanks for opening the issue and providing more info. Sorry for the late reply as I didn't have access to an android device. Did you play around with network permissions on your device? On a quick search, I found this post, maybe it can be helpful. Meanwhile, I will look more into the issue and see if I can find anything.

lncslncs commented 4 years ago

Thanks for the reply, I tried changing permissions as suggested in the post you linked to and it didn't solve the issue unfortunately.

lncslncs commented 4 years ago

Managed to fixed this by disabling SSL when building to Android using the disableSslVerification bool in assistantservice.cs. Then it worked fine on Android, so seems like it's an SSL issue. I guess we will have to find a way to use SSL on android seeing as ideally we don't want to use an insecure connection, but it works for now!

shyamraje1012 commented 4 years ago

I am developing 3d voice bot by using unity 2019.3.1f7, vuforia , watson 4.6 sdk from gethub. I created 1) speech to text 2) voice bot. It works fine in unity playmode and windows pc . but when i create android application. android app does not work. in condo i get error message with this line.
System.Windows.Forms.dll assembly is referenced by user code, but is not supported on Android platform. Various failures might follow. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)