Search Unity

Unity on Linux and Android

Discussion in 'Linux Editor' started by lovemoebius, Dec 26, 2018.

  1. lovemoebius

    lovemoebius

    Joined:
    Dec 12, 2016
    Posts:
    83
    I'm loving the Linux editor so far it's worked great and performance is sometimes better than Windows.

    My only gripe so far is when I need to develop for Android. Apart from the Problems with Unity Remote, every time I connect my phone and open Unity, I find myself having to restart the adb server to have Unity actually recognize my Android phone.

    The most annoying part is that Unity itself knows the problem is with adb, even giving me the error:
    Code (CSharp):
    1. CommandInvokationFailure: Unable to retrieve device properties. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details.
    2. /home/leonardo/Android/platform-tools/adb -s "emulator-5554" shell getprop
    3.  
    The usual fix for this is to just run:
    Code (CSharp):
    1. /home/leonardo/Android/platform-tools/adb kill-server
    2. /home/leonardo/Android/platform-tools/adb start-server
    I'm just wondering if anyone else is having this problem and, if so, if an official fix could be implemented. Even just having Unity restart the server when the Device isn't found would cut a lot of time out of doing it myself.
     
  2. senkal_

    senkal_

    Joined:
    May 22, 2018
    Posts:
    36
    Oh I used to have this all the time.
    I just don't do it this way now.
    I found on some Stack Overflow topic some alternative way to do it.

    In general when I need to work with Android device what I do:
    1. Be sure that Unity is NOT started.
    2. Start adb server, for me I do: {path to android sdk}/AndroidSDK/platform-tools/adb devices
    This gives me also device id, but I also can get it from Unity console log.
    Of course it also starts server.
    3. I execute Unity command with sudo, for example:
    sudo {path to adnroid sdk}/AndroidSDK/platform-tools/adb -s "{device id}" forward "tcp:34999" "localabstract:Unity-{android app key}"
    This command should also be visible in Unity console when you deploy to your device without this hack.

    After this I start Unity.
    Get usual "port is already taken" error, what is expected since that is the truth.
    After that I can run games on Android no problem and I don't have to restart adb from time to time.
    Even profiling works and Unity starts my game automatically after deploy(what is not the case with automatic way).

    I have no idea if this is the right way, probably NOT.
    But it works for me.
    I have no time to check now what is preferred way which will work for me.
    Probably will check in a while if "automatic" Unity way works for me now.

    Important - there are issue with this method, obviously :)
    adb started from sudo, after few hours, can freeze some stuff on my pc, like usb ports...
    I am not sure if this is the problem with calling adb with sudo or it's adb issue.
     
    Last edited: Dec 29, 2018
  3. lovemoebius

    lovemoebius

    Joined:
    Dec 12, 2016
    Posts:
    83
    I've actually never tried it that way, thank you for the great tips!
     
  4. senkal_

    senkal_

    Joined:
    May 22, 2018
    Posts:
    36
    @lovemoebius
    I think sudo is not needed in that long command.
    Btw this bug is reported and it is marked as fixed in Unity 2019, earlier versions still wait for the backported fix, there is a separate ticket fot that.

    Good luck.