Android tools in Unity 2022.2

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.

4 Likes

Can Unity 2022.2 use r23c instead of 23b? There are improvements especially on Apple M1. Changelog r23 · android/ndk Wiki · GitHub

3 Likes

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.

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

3 Likes

I wish unity 2023 would end the unity paired android package and just use centralized android studio package manager instead

7 Likes

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.

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

2 Likes

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: \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 \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.

2 Likes

Had to v11 JDK from here because v8 was installed by Hub 3.2

https://jdk.java.net/archive/

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)

Yarp

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.

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?

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.

2 Likes

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:

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

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.
1 Like

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.

1 Like

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)
3 Likes