Search Unity

[RESOLVED]Unknown Error (WWW, Android, PHP)

Discussion in 'Android' started by BlueSin, Aug 22, 2018.

  1. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    So I am getting issues with my login/registration system when deploying to Android. If I run it in Unity it works just fine. But when I run it in Android I keep getting Unknown Error when submitting POST requests to my PHP back-end. This is coming from parsing www.error. www.text comes back empty. So I simplified the code to test, and I STILL get Unknown Error even with this super simple code. Any ideas?

    Clickme.cs

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. public class Clickme : MonoBehaviour
    5. {
    6.      public Text Result;
    7.      public void OnClick()
    8.      {
    9.          StartCoroutine(RunScript());
    10.      }
    11.      IEnumerator RunScript()
    12.      {
    13.          WWW www = new WWW("http://www.familypolaris.com/helloWorld.php");
    14.          yield return www;
    15.          if (www.text == "")
    16.              Result.text = "Result was empty, error: " + www.error;
    17.          else
    18.              Result.text = www.text;
    19.      }
    20. }

    helloWorld.php

    Code (Boo):
    1. <?php
    2.     echo "Hello World!";
    3. ?>
     
    Last edited: Aug 22, 2018
    piggie_pie likes this.
  2. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    In Player Settings is "Internet Access" set to "Require"? I think by default it's "Auto" which presumably should work but you could try forcing it to "Require" just in case.

    Sam
     
  3. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Yes, internet access is set to require.
     
  4. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Weird, I did a little test on my Android device with your code and it worked! It seems like it's something specific to your setup or your device. It's probably more likely your device since it works in the editor. I don't know what else to suggest sorry!

    Sam
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,442
    samizzo likes this.
  6. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    I figured it out, so I will post the answer here. After samizzo commented that they tried my code and it worked just fine, I decided to try another device here. That device also failed to register and login. This told me something was wrong with my build settings. My first idea was to switch build type from Gradle to Internal, and that solved the problem for both my devices immediately.
     
    piggie_pie likes this.
  7. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    That's strange! Maybe the Gradle build wasn't including the permissions in the manifest for some reason. If it happens again you could also check the manifest in your apk (there's a tool available which can extract it).

    Sam
     
  8. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Is it super important to use Gradle vs. Internal? This is my first mobile app and I plan to be releasing it eventually for Android and iOS.
     
  9. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Nah you'll probably be fine with internal but it's probably worth getting your Gradle build working eventually. I imagine at some point Unity will remove the old build system since it's using an older Android project format which is no longer supported by Google.

    Sam
     
  10. BlueSin

    BlueSin

    Joined:
    Apr 26, 2013
    Posts:
    137
    Alright, well thank you so much for the help. I'll add Gradle to my TODO list for later.
     
  11. Apollo-Meijer

    Apollo-Meijer

    Joined:
    Mar 30, 2015
    Posts:
    31
    Did you find a solution for Gradle builds? I have this issue with my captive portal detection now. It works if I build with internal, but I cant do that because of some plugins we use.
     
  12. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
    I am having similar error on some devices when trying to download ~2mb assetbundle from server(Pixel 3xl) however most devices are fine. Please help. My internet connection in player settings is set to require.
    Unknown Error

    also
    www.isNetworkError is true
    www.isHttpError is false

    while
    www.error is "Unknown Error"


    I also tried to download the file using browser on device it downloaded normally
     
    Last edited: Jan 9, 2019
  13. warmanw

    warmanw

    Joined:
    Feb 2, 2015
    Posts:
    32
  14. piggie_pie

    piggie_pie

    Joined:
    May 18, 2015
    Posts:
    4
    THANK YOU!!!

    I have done a thorough search on this and every answer was basically the same... "turn on Internet Access in build settings". Well I had that turned on from the beginning. I even started digging around in the manifest.

    I finally found this post and did what you suggested and it solved my issue so THANK YOU!
     
  15. ABI16

    ABI16

    Joined:
    Mar 19, 2019
    Posts:
    16
    Hello. I'm having the same issue with some of our users' devices with having "Unknown Error" logs and mostly android devices.
    In our network_security_config.xml we have this
    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
    <base-config cleartextTrafficPermitted="true">
    <!-- add the list of domains and subdomains you want to address -->
    <base includeSubdomains="true">https://xxx.xxxxx.xxx/</base>
    </base-config>
    </network-security-config>

    I'm wondering if I should add cleartextTrafficPermitted="true" in the main Manifest.xml..
     
  16. ozlgktg

    ozlgktg

    Joined:
    Jan 15, 2020
    Posts:
    21