Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Java 9 (JDK 9) support by Unity Android

Discussion in 'Android' started by Yury-Habets, Oct 9, 2017.

  1. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    It's explicitly mentioned here https://docs.unity3d.com/Manual/android-sdksetup.html

    Do you have in mind other docs where it is not mentioned?
     
  2. Gen_Scorpius

    Gen_Scorpius

    Joined:
    Nov 2, 2016
    Posts:
    65
    I think that it could be made clearer by adjusting the wording and perhaps add a "common mistake" paragraph regarding android sdk's current Java constraint.

    Unity itself is more than happy to accept the Java 9 and 10 path and when building the only error I got was "Unable to list target platforms", which wasn't particularly helpful for troubleshooting. Also, the android sdk seems to use by default the highest installed Java version. So setting the Java path in Unity didn't seem to do anything.
     
  3. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Could you elaborate on where it could be made clearer?

    Unfortunately this is correct. This is why uninstalling latest JDK and installing JDK8 only is the way we recommend it now.
     
    justgky likes this.
  4. Gen_Scorpius

    Gen_Scorpius

    Joined:
    Nov 2, 2016
    Posts:
    65
    Depending on how long it will take to get that JDK constraint removed, I would add that recommendation right next to the JDK install instruction e.g. like that for immediate visibility when following the install guide (https://docs.unity3d.com/2018.2/Documentation/Manual/android-sdksetup.html):

    1. Install the Java Development Kit
    Download and install the Java Development Kit (JDK). Unity requires the 64-bit version JDK 8 (1.8).
    Note: Currently due to software incompatibility, we recommend to uninstall latest JDK and to install JDK8 only.
     
  5. AustynPember

    AustynPember

    Joined:
    Mar 14, 2018
    Posts:
    17
    Hello - I have followed the main instructions as well as what has been suggested here.

    I'm using 172 instead of 152 for JDK.

    This is what I'm getting for an Error:
    CommandInvokationFailure: Unable to list target platforms. Please make sure the android sdk path is correct. C:/Users/*******/AppData/Local/Android/Sdk\tools\bin\avdmanager.bat list target -c

    I have tried to follow all of the instructions I can find with fixing my PATH variable - but perhaps I'm missing something?
     
    Last edited: Jun 7, 2018
  6. coward

    coward

    Joined:
    Jan 9, 2013
    Posts:
    21
    At the moment, that seems to be fixed if you download the older version of the Android tools. Not sure why the docs aren't updated to show this...

    Replace your tools folder with the folder in this package:

    http://dl-ssl.google.com/android/repository/tools_r25.2.5-windows.zip

    I still can't get Unity to find a 'compatible device' even with all of the other bits and pieces set up (A whole mess of different SDK versions (including the one that my device has!), build-tools 27.0.3 and the google USB driver - adb detects it, and it's in the Unity build settings). It's really frustrating how light the docs are. Perhaps the device specific drivers are too new...

    So many other locations for answers, and no-one is updating the docs to show that there clearly is a need for a 'troubleshooting' section.

    **Edit: Oh, hey! there is a troubleshooting section. Alas, it's already telling me things that I have done, and they don't work..

    **Edit 2: As an aside, I am able to export the project instead and open it in Android Studio and deploy it from there. It told me what the error was - in Player Settings, I had not ticked the ARMv7 box. Which is obvious when you see it! It would be really good to have the Unity Process updated to give a more detailed error.
     
    Last edited: Jun 10, 2018
  7. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Please don't downgrade the tools. Don't do anything with the drivers. What you need is:
    - latest Unity
    - JDK8 64 bit (every other JDK should be UNINSTALLED)
    - latest Android SDK tools, platform-tools, build-tools.
     
    TheKingOfTheRoad likes this.
  8. Mansitos

    Mansitos

    Joined:
    Jun 24, 2015
    Posts:
    6
    I've tried everything... I have the last unity version, I've tried jdk10,jdk9 and jdk8, I've downloaded android studio.. so I think to have the last android-sdk version(?!?!?)

    Now has you say I uninstalled all the jdk versions exept for jdk8... but nothing... I can't build the app because of this: unity unable to list target platforms ... etc. etc.

    Please help me... I lost all the day trying to fix it.
    I'm going to format the **** pc.....
     
  9. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Android Studio alone is not enough, please open the SDK manager (Tools menu IIRC) and install latest tools, platform-tools, build-tools.
     
  10. Situacao

    Situacao

    Joined:
    Dec 4, 2013
    Posts:
    21
    I'm having the same "Unable to list target platforms" problem when trying to build for Android.

    I'm using:
    Unity 2018.1.2f1
    The latest tools for the Android SDK
    jdk 1.8.0_121 (the only JDK installed on my computer)

    And I'm still getting this error. Is there any solution available?
     
  11. ZZix

    ZZix

    Joined:
    Jan 13, 2017
    Posts:
    5
    Everything is installed/updated (except JDK 8) and I'm still getting the errors. This is driving me absolutely insane.
     
  12. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Please provide the editor log with the error. It's hard to help without this info.
     
  13. ZZix

    ZZix

    Joined:
    Jan 13, 2017
    Posts:
    5
    I managed to get it to work. I had to replace the tools files with an older version. The first time i tried it didn't work because i was using the newer jdk, but once implemented the fixes in this thread and than tried to tool method it worked.
     
  14. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    PLEASE DON'T REPLACE YOUR TOOLS WITH AN OLDER VERSION.

    It's a very bad solution.
    If you use JDK8 64bit, latest Unity patch release and latest tools - it all works.
     
  15. ZZix

    ZZix

    Joined:
    Jan 13, 2017
    Posts:
    5
    You keep saying that and yet here we are.
     
  16. Thiago-Paiola

    Thiago-Paiola

    Joined:
    Sep 14, 2015
    Posts:
    1
    My solution was uninstalling Java 10 and reinstalling Java 8 on Windows10.
     
    Yury-Habets likes this.
  17. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Unfortunately, if someone finds it more appropriate to use older SDK tools instead of reporting a bug - we are unable to fix the issues, if they exist. At the moment we have zero open bug reports with Android SDK and JDK issues.
     
  18. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    217
    It would be really great if Unity could update the Android Environment Setup document in the manual to reflect that the latest jdk doesn't work with the latest versions. Wasted many hours on this relatively simple fix.
     
  19. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    AlexSD3 likes this.
  20. screensmith

    screensmith

    Joined:
    Apr 8, 2018
    Posts:
    1
    If you're using Android Studio, doesn't it default to using the internal Android Studio JDK anyway? I went into the studio and changed the JDK from the internal JDK to the Java 8 JDK (https://www.jetbrains.com/help/idea/configuring-mobile-java-sdk.html) and there's no other JDK's on my system, but I'm still getting the "Unable to list target platforms" error.

    upload_2018-8-21_13-33-29.png

    I'm not sure what I'm doing wrong, I've read through this whole forum thread and I can't find anything that's worked.

    This is 2018.2 with the most recent android studio and the Java SDK 8
     
    Last edited: Aug 22, 2018
  21. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    But the error you posted is from Unity Editor, does it have anything to do with Android Studio? Unity has its own JDK path setting in Preferences.
     
  22. AshleyBates

    AshleyBates

    Joined:
    Feb 24, 2017
    Posts:
    34
    Hi,

    I just upgraded to 2017.4.10f1 and before this version I could build and sign my android app without any problems.

    Now I can sign it to release mode, but I can't build in debug (unsigned).
    I get the error 'CommandInvokationFailure: Failed to sign APK package.'

    Any idea what is causing this? It has to be Unity, as I changed nothing else other than upgrading Unity from 9f1.

    Thanks.

    Edit: I just downgraded to 9f1 as I don't have time to mess around with this - everything is building / working as it should again.
     
    Last edited: Aug 30, 2018
  23. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    More details are in your console and Editor log.
     
  24. renyuzhuo

    renyuzhuo

    Joined:
    Feb 24, 2018
    Posts:
    1
  25. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    UPDATE: in Unity 2018.3, we are shipping OpenJDK together with Unity. By default, it will be used by the build pipeline, which means - no external JDK installations are needed, no version hassle etc. You can also specify your own external JDK installation at your own risk (in Preferences window).
     
    ferretnt likes this.
  26. Ohyouknow

    Ohyouknow

    Joined:
    Oct 23, 2013
    Posts:
    109
    @Yury-Habets - when can we expect 2018.3?

    I cant seem to get any working Android builds with 2017.X and in 2018.1-2, for some strange reason, if I try to change from Gradle to Internal, it completely crashes the editor. Reopening unity does nothing. It just automatically crashes my editor until I open a different copy of my game. Same thing happened when I selected export project. Tried submitting a report and even that wouldnt go through. Tried everything I've found on google and the forum to no avail.

    Tried downgrading to 2017.4.12 and it picks and chooses which errors it wants to give me to ruin my day. If I select internal, it'll say my manifests cant merge (despite everything being correct), if I select Gradle, it'll give me the JDK issues, and it'll throw in Google.JarResolver.ResolutionException: Cannot find candidate artifact for, and UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors.
     
  27. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Soon. I don't have an exact date but it's in beta stage now.

    As for your issues - never heard of something like that before. If you create a new thread with your issues, someone may help you.
     
  28. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    Does this mean I can remove Android Studio now? I have no other need for it outside of Unity.
     
    Qbit86 likes this.
  29. OB

    OB

    Joined:
    Jan 20, 2013
    Posts:
    1
    After installing 2018.3 I have run into a problem that seems to be related to this. All my Java scripts worked before, now they're not recognised. I'm installing Java separately to see if it gets it working...
     
  30. iDeveloper2

    iDeveloper2

    Joined:
    May 8, 2013
    Posts:
    10
    Hi, I facing this issue
    "Your app bundle contains the following configurations where the initial install would exceed the maximum size of 100 MB: ARMEABI_V7A"
    If I upload app bundle under 100mb size then work fine. How I upload app bundle with more then 100mb size.
     
  31. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    @iDeveloper2 that's a bit unrelated to this thread.
    Google promised the limit for app bundle deliverables is going to be bumped to 500Mb soon:

    https://medium.com/googleplaydev/wh...t-means-for-the-future-of-android-2e34981793a

    Maybe try contacting Google Play support about that.
     
  32. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    620
    @Yury-Habets
    Any chance you could bundle the latest SDK tools, platform-tools, build-tools with the Android Support Installer?
    These are way trickier than simple OpenJDK configuration.
     
  33. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
  34. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    620
    @Yury-Habets That's awesome, but the SDK Tools are bundled together with the NDK Tools.
    Would be far better if the SDK tools are part of the Android Support and the NDK remains optional.
     
  35. sinjimonkey

    sinjimonkey

    Joined:
    Jul 31, 2013
    Posts:
    72
    This is also an issue with JDK 11 as well (I had to remove it to get my project to build)

    I realise this may have been fixed with a newer version of Unity - I'm still on an old version for my project but plan to update soon.
     
  36. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Thank you for the feedback!
    @JC-Cimetiere FYI
     
  37. JC-Cimetiere

    JC-Cimetiere

    Unity Technologies

    Joined:
    May 8, 2014
    Posts:
    123
    Hello,
    Thank you for the feedback!
    I understand your point, but ... ;-)

    The main idea of having Unity install the JDK (OpenJDK distribution), Android SDK and NDK with Android support is to avoid all the issues many users are having with wrong/conflicting versions of these external dependencies.
    Bundling Android SDK and NDK together is to make it simple for most users.
    NDK is pretty much mandatory because of 64bit (mandatory to publish on Google Play very soon) and required by IL2CPP.

    And for advanced users who want to control everything, there is the option to specify JDK/SDK/NDK separately in the Preference window, see the doc for details:
    https://docs.unity3d.com/2019.1/Documentation/Manual/android-sdksetup.html

    Cheers!
    JC
     
  38. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    620
    @JC-Cimetiere I understand, but may I argue that if the motive behind this move is avoiding conflict and simplifying the process then I think it's even more suitable to include the SDK, because with the same rationale, you can't build an app with the JDK alone, it's pretty useless on its own, but it's way easier to set up then setting up the SDK.

    The OpenJDK version that ships with Unity happens to be the same I've been using in my PC for the last 1.5 years (1.8.0_152), same with the NDK (16b), ...on the other hand Unity is already complaining about a deprecated SDK tools and platform tools and I'm still trying to update them.

    So for me at least, It seems obvious to me that setting up JDK and NDK is least troublesome, the more stable part, so I don't understand why I have to keep reinstalling them with each Unity minor version.
    Whereas the SDK is the more volatile and troublesome setup. especially if you're using it without Android Studio, and unfortunately there's no longer a GUI installer or GUI SDK manager provided by Google.

    It's my opinion but I would prefer a bundled SDK instead of Java, and in any case I would like to propose that the Andoid Installer per se gives the option to untick all the extra dependencies so as to not reinstall them if the same version is already installed.
    I'm not sure if the Nullsoft installer used by Unity supports it or not but it's worth a try.
     
  39. xCyborg

    xCyborg

    Joined:
    Oct 4, 2010
    Posts:
    620
    @JC-Cimetiere To maybe illustrate the point, after leaving Unity update the SDK toolchain overnight, yes overnight, I wake up to see it failed .

    There is this weird conflict and I have to update it manually after all.
    Here is a screenshot if you're interested.

    From the looks of it, Unity spent the night downloading the emulator which I don't need, and I'm not even sure which packages need updating and to what version.

    My sdk directory became a hot mess and I'm neck deep trying to figure it out in the command line and stackoverflow, I would take a simple Java mismatch over this any day.
     

    Attached Files:

    • f1.jpg
      f1.jpg
      File size:
      162 KB
      Views:
      1,684
    • f2.jpg
      f2.jpg
      File size:
      412 KB
      Views:
      1,015
  40. kickstep

    kickstep

    Joined:
    Jan 29, 2013
    Posts:
    13
    Hi Yury-Habets, this is a great feature. I'm having issues using a headless build (Jenkins) where I can no longer set JAVA_HOME to use JDK 8 set up externally. Using Unity 2018.3.10f1.

    I am able to get an Android build to complete successfully using BuildPipeline static method call from batch script when signed in as a user who has configured the Android Editor Prefs (SDK, NDK, JDK 8). However, calling this same method from a headless build system fails since these variables are not set. %ANDROID_HOME% and %ANDROID_NDK_HOME% are successfully used when configured however %JAVA_HOME% seems to be ignored. It keeps defaulting to the embedded OpenJDK which is causing build failure (JDK 8 dependency).

    I have tried
    Code (CSharp):
    1.                     EditorPrefs.SetString("JdkPath", @path);
    2.                     EditorPrefs.SetInt("JdkUseEmbbeded", 0);
    3.                     Debug.Log("JAVA_HOME is" + Environment.GetEnvironmentVariable("JAVA_HOME") + ". About to set to " + path);
    4.                     Environment.SetEnvironmentVariable("JAVA_HOME", path);
    However, setting these prefs via code seems to do nothing. The environment variable JAVA_HOME is set correctly to an external JDK so overwriting it before calling the build script does not seem to help.

    I have inspected UnityEditor.dll with ILspy and can't seem to find anything useful to manually set the JDK path.
     
  41. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
  42. kickstep

    kickstep

    Joined:
    Jan 29, 2013
    Posts:
    13
    Thanks for your response.

    Currently the Facebook SDK for mobile login/analytics needs JDK 8. I will try your change when I get a chance, but I'm not sure if that will make a difference. Firstly AFAICT the pref was saved as an int in registry and more importantly none of those prefs seem to work if you are signed in as System. I confirmed the same SetPrefs DO work when executing the same command line from a user.

    When are these prefs loaded? Can they be dynamically changed right before a build, or does it require restarting Unity? I think this might be related to why it doesn't work -> Jenkins may not keep register/editor prefs between executions.

    For now I'm just running Jenkins as a user instead of System (though I think this may cause other issues and unfortunately requires one time setup per build machine).
     
  43. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    Right that makes sense.
    On Windows, the EditorPrefs are stored in the registry, in HKEY_CURRENT_USER (HKEY_USERS) section.
    On Mac/Linux... I can get an expert to answer same question.
    If you are building under a particular user, you may want to do the setup under the same user.
     
  44. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    133
    Hi guys. So can use newer JDK now or still stick with JDK8?
     
  45. Yury-Habets

    Yury-Habets

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    1,162
    We officially support JDK8, and OpenJDK is included into Unity installation. There is no support for newer versions, and no plans to.
     
  46. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,015
    Hi @Yury-Habets,

    I have a problem that is forcing me to use download Android Studio and preventing use of these new embedded features.

    I've transferred my project to another PC to do PC housekeeping on the main machine. The backup PC doesn't have Android studio or any Android tools on other than those that installed with unity (that is the embedded ones). I don't want to add Android studio etc to the backup PC as I'm trying to do things the new unity way. Plus hopefully keeping the PC tidier.

    I've installed a fresh unity 2018.4.1f1 with all the android components and selected use embedded JDK and NDK in the preferences.

    The build always fails and says 'Unable to locate Android SDK'

    I've checked the Android components have installed via Unity hub and it shows they are installed. Does the Android component actually include the SDK? I would assume if unity is making use of an embedded component that it would download/include all the SDK's etc needed? It does say so in the tick box when downloading unity and the android component.

    Is this a bug?

    Either way is it possible to just explicitly set the Paths to the embedded components? If so where are they?

    Thanks :)
     
  47. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    824
    Hi, unfortunately Unity 2018.4 is a little bit weird in this case. As you've seen we've added functionality to use embedded SDK, however we couldn't figure out the proper way to provide the actual SDK to users (mostly due to legal issues). So for 2018.4 you would still have to download android SDK yourself. You can follow the guide here https://docs.unity3d.com/2018.4/Documentation/Manual/android-sdksetup.html
    For Unity 2019.1 and future versions you will be able to download SDK and NDK directly from the hub. See this page for more information https://docs.unity3d.com/Manual/android-sdksetup.html
     
  48. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,015
    Hi @JuliusM,

    Thanks for the reply and clearing this up.that explains why I couldn't get it working until installed Android Studio.
    Not sure if you've made a notice of this but would be good to let people know especially with 2018 being an LTS now.

    I was going to use 2019.1 but there's a weird bug with UI sprites changing size for no apparent reason.

    Thanks anyway.
     
  49. WibbuTechnology

    WibbuTechnology

    Joined:
    Apr 20, 2015
    Posts:
    2
    Hello,

    I have an issue with this setup using Unity 2018.4.2f1 where I have the external tools set to use the embedded JDK. I specify the SDK and NDK locations to match the current Android Studio setup. However, when I try to run the Play Services Android Resolver, I get the following error:

    Code (CSharp):
    1. Gradle failed to fetch dependencies.
    2.  
    3. Failed to run 'C:\BitBucket\RubyRei_Android\Temp\PlayServicesResolverGradle\gradlew.bat -b "C:\BitBucket\RubyRei_Android\Temp\PlayServicesResolverGradle\PlayServicesResolver.scripts.download_artifacts.gradle" --no-daemon "-PANDROID_HOME=C:/Android/SDK" "-PTARGET_DIR=C:\BitBucket\RubyRei_Android\Assets\Plugins\Android" "-PMAVEN_REPOS=" "-PPACKAGES_TO_COPY="'
    4. stdout:
    5.  
    6. ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
    7.  
    8. Please set the JAVA_HOME variable in your environment to match the
    9. location of your Java installation.
    10.  
    In the documentation found here, it says that Unity is supposed to set the JAVA_HOME environment variable itself, which it did not. I know how to set it, but I don't know what to set it to because I don't know the location of the embedded JDK.

    Additionally, Unity is deleting all of the plugins for Firebase and others found in "Assets/Plugins/Android" every time I launch the editor. I have not figured out how to get these to stop deleting, which is why I've been trying to use the Play Services Resolver because I've read that this tool is supposed to be what handles those things.

    Any assistance you could provide would be of great help.

    Thanks
     
  50. modandroidapk

    modandroidapk

    Joined:
    Jul 15, 2019
    Posts:
    1
    I think still should use JDK8