Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  3. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Official Android tools in Unity 2022.2

Discussion in '2022.2 Beta' started by JuliusM, Jun 13, 2022.

  1. JuliusM

    JuliusM

    Unity Technologies

    Joined:
    Apr 17, 2013
    Posts:
    836
    We are upgrading Android NDK, SDK and JDK used in Unity 2022.2. NDK will be upgraded to r23b. SDK will be upgraded to depend on cmdline-tools version 6.0 (instead of deprecated “tools” component) and Unity will require to have build-tools and platform-tools versions 32.0 or newer installed. JDK will be upgraded to version 11.

    During the latest alpha and a couple of upcoming beta releases, Hub can install incorrect tools versions when installing Android support. Currently available Hub versions install the same dependencies as for Unity 2022.1. This is fine for SDK and JDK since current Unity 2022.2 versions still expect old SDK and JDK, but latest 2022.2 alpha versions already require NDK r23b.
    In upcoming days, Hub version 3.2 should be released which will install NDK r23b, JDK 11 and updated SDK, however Unity will start accepting new SDK and JDK only during later beta releases.

    We will update this post once dependencies provided by the Hub will match tools versions expected by the latest Unity 2022.2 beta release. Meanwhile please don’t depend on Hub to install SDK, NDK and JDK. Sorry for the inconvenience.
     
  2. XEDORA

    XEDORA

    Joined:
    Jul 8, 2015
    Posts:
    12
    tealm, koiq and FernandoMK like this.
  3. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Doesn't seem like this is really limited to Hub only. I think recent Hub 3.2 beta installs the SDKs mentioned here but 2022.2.0a17 just straight up refuses to accept them.. And if you install a17 with android sdks on Hub 3.1 it just fails to build as well.
     
  4. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I figured this out. Basically for 2022.2.0 a16 and a17 you only ever need to update NDK and not update Android SDK or OpenJDK but if you use Hub 3.2 beta, it actually updates these all and that makes these incompatible with current 2022.2 alphas. Basically right now there's no Hub version that works out of the box with latest 2022.2 alphas but if you need to build for Android, you should use Hub 3.1 or older and just swap NDK to newer version.

    For NDK I just used the newer version provided by that Hub 3.2 (manually copied the folder from <2022.2.0a17 install dir>\Editor\Data\PlaybackEngines\AndroidPlayer) but I suppose you could just manually download it and use that one instead as well so you don't have to deal with that Hub beta (which you shouldn't since it breaks rest of the android packages now). Direct NDK r23b download links here (it's not listed on their site anymore but DL works):
    Win: https://dl.google.com/android/repository/android-ndk-r23b-windows.zip
    Mac: https://dl.google.com/android/repository/android-ndk-r23b-darwin.dmg
     
    kallais and jalilseguel7 like this.
  5. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    I wish unity 2023 would end the unity paired android package and just use centralized android studio package manager instead
     
  6. milox777

    milox777

    Joined:
    Sep 23, 2012
    Posts:
    195
    That's asking for trouble in the Android world, it's already as bad as it is (although it used to be even worse). Built in Unity Hub SDKs may be a little dated but at least they are certified to work with Unity projects.
     
  7. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,168
    What I mean is, unityhub can have their own android studio, but it should be centralized in the hub and load android sdk/ndk into the same places. Then each unity can share the same android sdk/ndk repo (which could be many version)

    And even using locally provided android manager, it could also be manipulated to download and store android sdk/ndk for specific version unity wanted to use.

    Let's think about this. If we have unity 2021.2 and want to update to 2021.3 or even 2022.1, it would more likely to use the same android sdk/ndk version. And so we might not need to download whole sdk again repeatedly and keep the duplicate sdk in difference folder on our disk

    Unity project settings for android should also have version selector, and download button for any version, and reset button to revert back to factory setting sdk version. Also unity hub should have some ui for controlling android studio, such as remove all unused version from the disk or function to clean and download all sdk and ndk version that installed unity would wanted

    This behaviour should be default behaviour of every module. But android studio might be good choice for implemented first as a test system
     
    Last edited: Jul 1, 2022
    jalilseguel7 and cmdexecutor like this.
  8. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Seems like Unity Hub 3.2 is still missing the commandline tools from the SDK:


    I fixed this in bit hacky way:
    - install 2022.2.0a18 with android tools via Unity Hub 3.2
    - download cmdline tools from https://developer.android.com/studio#command-tools
    - unzip and put the contents inside cmdline-tools folder into: <wherever your unity installations go>\2022.2.0a18\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tools\latest\
    - build apk using Unity
    - once the dialog pops up, select "Update Android SDK"
    - once it's updated go to <wherever your unity installations go>\2022.2.0a18\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\cmdline-tool folder and delete latest and rename 6.0 to latest

    If someone has direct download links to 6.0 commandline tools Unity uses, then you can omit latter half of these steps.
     
    JamesArndt likes this.
  9. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    140
  10. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    You sure you are were on 3.2? I got OpenJDK 11.0.14.1+1 automatically with it (just checked the version)

    Or maybe it's Win/Mac difference? (using Windows myself)
     
  11. Cloudwalker_

    Cloudwalker_

    Joined:
    Jan 3, 2014
    Posts:
    140
    Yarp
     
  12. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    It seems like Unity really struggles to get this right atm. I tried to install 2022.2.0b1:


    It just kept failing if I retried it. And when I looked into installation folder I saw this:


    Meaning the Hub tried to put the cmdline tools to the editors root folder, instead of playerengines android folder.
     
  13. kolobokspb

    kolobokspb

    Joined:
    Nov 21, 2016
    Posts:
    16
    Hello.
    Unity Hub 3.2
    Unity 2022.2.0b8
    installation from the hub does not work.
    There are fixes in this version that should reduce the number of crashes.
    I was able to install the NDK and JDK manually, but the SDK contains too many packages.
    When is it planned to fix this?


    upload_2022-9-12_23-5-10.png
     
  14. JessHolle

    JessHolle

    Joined:
    Jul 9, 2019
    Posts:
    14
    In my opinion, there should be an option for Unity to just use `ANDROID_HOME` as well as an option allowing you to provide an explicit directory instead. (`ANDROID_HOME` is more flexible when dealing with CI builds on multiple platforms!)

    The assumption should then be that the contents of this directory are as would be created by the Android SDK manager (command-line or via Android Studio -- same thing), providing SDKs, build-tools, platform-tools, etc, under this directory.

    Oh, and one should be able to explicitly spell out the build-tools version to use for a project -- rather than Unity simply using the latest available as it currently does. This applies wherever/however the Android SDK tools directory is specified/located, internal or external.

    Similarly for the NDK, if one chooses not to install and use a Unity bundled NDK, there should be an option to use the expected location under the external SDK directory if one has been specified (via ANDROID_HOME or explicitly as per above). There should be options to use ANDROID_NDK_HOME or an explicit directory instead as well.

    And newer maintenance releases of the required NDK version should be explicitly supported.
     
    robertsmith01 and Thaina like this.
  15. Andrew010110

    Andrew010110

    Joined:
    Oct 8, 2022
    Posts:
    18
    I've noticed that with Unity Hub 3.3 and Unity Editor 2022.2.0b10, if you install the Android tools via the Unity Hub GUI, it installs perfectly fine and Unity picks it up correctly. However, when installing the Android tools via Unity Hub CLI, it still installs the old versions of the NDK and JDK which causes build errors. This was tested on Ubuntu 20.04. Is this a known issue or does it need to be bug reported somewhere to get it fixed? Thanks!

    Installing via Unity Hub:
    UnityHubGUIAndroid.png

    Installing via CLI with the command
    /opt/unityhub/unityhub-bin --no-sandbox --headless install-modules --version "2022.2.0b10" --module "android" --childModules

    UnityHubCLIAndroid.png
     
    Last edited: Oct 11, 2022
  16. tealm

    tealm

    Joined:
    Feb 4, 2014
    Posts:
    108
    Great to hear you upgraded the SDK, NDK & JDK in 2022.2. I also wanted to give a heads up for anyone else looking for a updated Gradle version that 2022.2 is in fact using Gradle v7 which is great (I needed this for supporting a android .aar library plugin I wrote).

    From release notes:
    • Android: Unity uses Android Gradle Plugin 7.1.2 by default.
    • Android: Unity uses Gradle 7.2 by default.
     
    JamesArndt likes this.
  17. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,922
    P.S we also specify gradle versions + android gradle plugin versions here - https://docs.unity3d.com/2023.1/Documentation/Manual/android-gradle-overview.html if someone needs this information.
     
    pixelsprite_unity likes this.
  18. machi-ryo

    machi-ryo

    Joined:
    Jun 19, 2015
    Posts:
    1
    I'm having the same issue.
    I would like to know how to use AndroidSDK and NDK normally even in an environment where UnityHub is installed using CLI.

    UnityHub version: 3.4.1
    Unity Editor version: 2022.2.4f1 (8216e0211249)

    UnityHub is installed with CLI Homebrew.
    https://formulae.brew.sh/cask/unity-hub


    DisplayProgressbar: Detect Android NDK
    Uploading Crash Report
    UnityException: Android NDK not found
    Android NDK not found or invalid. Please, fix it in Edit / Unity -> Preferences -> External Tools
    UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, String, BuildTargetGroup, BuildTarget, Int32, BuildOptions, String[], Boolean)