Android SDK causes NullReferenceException

I have newly installed the Unity version 2119.2.5f1 and started a new project. Almost instandly came this error in the console, even before I created any GameObjects.

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Android.SDKManager..ctor () (at <5557b445b4634c46b2ec8376c040bd34>:0)
UnityEditor.Android.SDKManager.GetInstance () (at <5557b445b4634c46b2ec8376c040bd34>:0)
UnityEditor.Android.AndroidPreferenceWindowExtension.WritePreferences () (at <5557b445b4634c46b2ec8376c040bd34>:0)
UnityEditor.PreferencesProvider.WritePreferences () (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:818)
UnityEditor.PreferencesProvider.AppsListClick (System.Object userData, System.String[] options, System.Int32 selected) (at C:/buildslave/unity/build/Editor/Mono/PreferencesWindow/PreferencesSettingsProviders.cs:974)

Does anyone know what caused this and how I can fix it?
I installed the Android SDK along with Unity via Hub.

I’m using Unity 2019.2.10.f1 on Ubuntu 18.04, and I installed it using Unity Hub 2.1.3 along with Android Build Support and the optional Android SDK & NDK Tools. I faced a similar problem when I created a new project and tried to build it to an apk. The build process stopped with a pop-up saying ‘Android SDK not found’ along with these errors in the console:

I tried to manually set the SDK and NDK directories in Unity under Preferences>External Tools, but toggling the ‘Android SDK Tools installed with Unity (recommended)’ checkbox threw the error you mentioned in the console.

Fixing the error

I read here that the error might be caused by a missing ‘tools’ folder in the Android SDK, so I downloaded the latest Android SDK for Linux (sdk-tools-linux_4333796 under ‘Command line tools only’), extracted the contents and copied the downloaded ‘tools’ folder into my SDK folder (/home/Unity/Hub/Editor/2019.2.10.f1/Editor/Data/PlaybackEngines/SDK). Toggling the SDK and NDK options was no longer throwing the error, so I opened up Build Settings to try building an apk now, but then this error started being spammed in the console:

So I opened up the folder with the adb file (/home/Unity/Hub/Editor/2019.2.10.f1/Editor/Data/PlaybackEngines/SDK/platform-tools/), opened a terminal in that directory, and ran this command:

chmod +x adb

Building the project now seems to work fine for me and there are no errors.

I imagine the process would be slightly different for Windows, if it even works, but I hope that helps.

These exact console error messages appeared to me on Unity 2019.2.17 whenever I would open Player section of Project Settings. After installing a few older SDK platforms via the Android Studio it disappeared