Starting from a fresh Unity install on Linux Mint, many start having issues when they try and “Build and Run” their projects. This can be traced back to inadequate dependency installation by the Unity Hub installer which is otherwise fantastic.

In this post I will go over the problems encountered and the solutions found.

First, I would like to post the main error messages encountered in a large garish font so that people can find their way to the solutions here using search engines.

linux-x86_64/bin/clang++: 1: clang: not found

clang: error: no input files

Fix linux-x86_64/bin/clang++: 1: clang: not found

This one is quick and easy to solve. Open up a terminal and do the following.

ubuntu@goodboy:~$ sudo apt-get install clang
[sudo] password for ubuntu:       
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  docker-scan-plugin linux-headers-5.15.0-57 linux-headers-5.15.0-57-generic
  linux-image-5.15.0-57-generic linux-modules-5.15.0-57-generic
  linux-modules-extra-5.15.0-57-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  clang
0 upgraded, 1 newly installed, 0 to remove and 91 not upgraded.
Need to get 0 B/3.558 B of archives.
After this operation, 25,6 kB of additional disk space will be used.
Selecting previously unselected package clang.
(Reading database ... 803608 files and directories currently installed.)
Preparing to unpack .../clang_1%3a14.0-55~exp2_amd64.deb ...
Unpacking clang (1:14.0-55~exp2) ...
Setting up clang (1:14.0-55~exp2) ...
Processing triggers for man-db (2.10.2-1) ...
ubuntu@goodboy:~$ 

Fix clang: error: no input files

As soon as you fix one issue, you are slammed with this ‘clang: error: no input files‘ problem.

This apparently is a bug related to how the Unity Hub installer delivers the android NDK.

Let’s cover some Unity Hub behaviours.

Multiple Editor Installs ~/Unity/Hub/Editors

Under linux mint, Unity Hub installs different versions of the Unity editor in location ~/Unity/Hub/Editor/

ubuntu@goodboy:~/Unity/Hub/Editor$ pwd
/home/ubuntu/Unity/Hub/Editor
ubuntu@goodboy:~/Unity/Hub/Editor$ ls -l
total 12
drwxr-xr-x 3 ubuntu ubuntu 4096 Jul 19 12:02 2021.3.8f1
drwxr-xr-x 3 ubuntu ubuntu 4096 Jul  4 17:57 2022.3.4f1
drwxr-xr-x 3 ubuntu ubuntu 4096 Jul 19 13:53 2022.3.5f1

NDK Install Location

From within any Unity editor you can check where the NDK is located by selecting Edit > Preferences > External Tools . You will find that each individual Unity editor install has its own NDK installed in a subdirectory, for example,

ubuntu@goodboy:~/Unity/Hub/Editor/2022.3.5f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK$ pwd
/home/ubuntu/Unity/Hub/Editor/2022.3.5f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK

Unity Editor NDK Version Dependency

You can verify these at the source, https://docs.unity3d.com/Manual/android-sdksetup.html

Unity versionNDK version
2019.4 LTSr19
2020.3 LTSr19
2021.3 LTSr21d
2022.3 LTSr23b
2023.2 BETAr23b
Table showing the NDK version that each Unity version supports:

The Fix

Common Recommended Step

A common recommended step is to simply re-download the NDK version for your Unity editor, then either change the NDK location setting in Unity to your new download, or to replace the files in the NDK directory for your editor.


Sounds straightforward but either way you choose you will unfortunately be met by the following error from Unity when you attempt this fix.

NDK 23.2.8568313 detected. Unity requires NDK r23b (64-bit) (23.1.7779620)

Yup. NDK version r23b has subversions, and you will find that you can’t download every version at https://github.com/android/ndk/wiki/Unsupported-Downloads

Install Android Studio

You are not going to believe this. You need to install another IDE to fix the IDE.

Head over to https://developer.android.com/studio and download android studio for linux.
You will have downloaded a zip file. Extract its contents and click the file pointed out by the red arrow in the image below. Go through the setup wizard.

Use SDK Manager

Once completed, from the main menu under ‘More Actions’ select SDK Manager.

Select the ‘SDK Tools’ tab, then make sure ‘Show Package Details’ is selected on the bottom right as shown, then you will be immediately shown a list of NDK versions.

Select the NDK version you need then click apply.

Click OK to confirm the change.

Wait for the installer to finish.
Note that in the window you are told that the SDK Path is /home/ubuntu/Android/Sdk (This will be different for you). You will find the directory with the correct version ready to be pointed to or copied to the previous Unity editor directory.

Unity still complains even though we have given it the version it wanted.

Luckily we just get a warning and no error.

Unity will now compile your project.

android.keystore file issues

Fix Cannot Recover Key

Now, incase you are having the above issues because you are dusting off an old project there is another error you might see when building your project.

KeytoolException: Failed to read key your.key from store “your.keystore”: Cannot recover key

I’ve tried many suggestions found out there on the internet, but nothing worked. I had the correct keystore password, alias password, and I was able to verify this using the keytool. Unity still complains that it can’t access it. It’s a keystore I’ve used for years – why it has suddenly stopped working I do not know.

The good news is, you can create a new keystore and alias as you did before and request to update it in the Google Play store.

*** It will take a few days for Google Play to process your request ***

*** However, you can start coding in Unity with your new keystore immediately ***

  1. Generate a new keystore, instructions can be found here
  2. Go to your Google Play Console
  3. Select your app
  4. Select App signing
  5. Select Request Upload Key Reset
  6. Follow the instruction to generate an upload file
  7. Upload the file and wait for your request to go through

You will find that your application now compiles without any issues.
Compiling and running on your device is another problem…

Autofill Keystore & Keyalias Password In Unity Editor

When you restart Unity and reload your project Unity has this really annoying habit of forgetting your Keystore passwords. This can be a massive pain. Here are some steps you can take.

Create a credentials text file in your user home directory

ubuntu@goodboy:~$ cat keystorecreds.txt 
keystorePass=myPwd
keyaliasPass=myAliasPwd

Create a directory called ‘Editor’ under your assets directory

The “Editor” folder is a special folder in Unity, and its name is considered a “reserved word” that serves a specific purpose. Placing scripts inside the “Editor” folder tells Unity that these scripts are meant to be used for editor-related functionality and will not be included in the final build of your game or application.

Create a new script called EditorSettingsLoader.cs in the Editor directory

#if UNITY_EDITOR

using System.IO;
using UnityEditor;
using UnityEngine;

public class EditorSettingsLoader : MonoBehaviour
{
    private static string credsFilePath;

    [UnityEditor.MenuItem("Custom/Load Editor Settings")]
    public static void LoadEditorSettings()
    {
        credsFilePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.UserProfile) + "/keystorecreds.txt";
        if (File.Exists(credsFilePath))
        {
            string[] lines = File.ReadAllLines(credsFilePath);
            foreach (string line in lines)
            {
                string[] keyValue = line.Split('=');
                if (keyValue.Length == 2)
                {
                    string key = keyValue[0].Trim();
                    string value = keyValue[1].Trim();
                    ApplySetting(key, value);
                }
            }
        }
        else
        {
            Debug.LogWarning("Creds file not found at path: " + credsFilePath);
        }

    }

    private static void ApplySetting(string key, string value)
    {
        switch (key)
        {
            case "keystorePass":
                PlayerSettings.keystorePass = value;
                break;
            case "keyaliasPass":
                PlayerSettings.keyaliasPass = value;
                break;
            // Add more cases for other settings if needed
            default:
                Debug.LogWarning("Unknown setting key: " + key);
                break;
        }
    }
}

#endif

EditorSettingsLoader‘ is not a reserved word script name. Unity will load and run any script of any name in the Editor directory.

Usage

When you next restart your Unity editor and project select the following menu option.

When you check your project settings you will find that your passwords have now been loaded.

Notice that in the script there is a tag that exists,

[UnityEditor.MenuItem("Custom/Load Editor Settings")]

this tag defines the custom menu item that runs your method. You can use this knowledge to build further custom Unity scripts and menu items to adjust your editor settings.

Fix INSTALL_FAILED_UPDATE_INCOMPATIBLE

If you try to build and run your app with a new keystore on a device you’ve already been using to test, develop, compile and run with the old keystore – it will fail. You will see the following error in Unity.

Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package your.app.package.name signatures do not match previously installed version; ignoring!]

Even if you uninstall your app on your device, even if you select uninstall for all users, you still may get this error message. We need the help of adb (Android Debug Bridge) to actually completely uninstall your application from your test device.

We need to open up Android Studio again to solve issues in Unity.

We need to use android adb, which is part of Android SDK platform-Tools. Make sure these are installed,
also select Android SDK Command-line Tools and click apply.

You will find the adb command at the following location.

ubuntu@goodboy:~/Android/Sdk/platform-tools$ ./adb --version
Android Debug Bridge version 1.0.41
Version 34.0.4-10411341
Installed as /home/ubuntu/Android/Sdk/platform-tools/adb
Running on Linux 5.15.0-75-generic (x86_64)

adb will operate on your connected android device/virtual device and remove all trace of your application that used your previous keys.

Run the following code with your package name.

ubuntu@goodboy:~/Android/Sdk/platform-tools$ ./adb uninstall "your.app.package.name"
Success

Building and running to device will give you the following item in your log.

I think that is the end of a chain reaction of problems that started with wanting to dust off an revisit an old project.

Install Button Missing From Google Play Store Listing

You will notice that when you publish to the Google Play Store the [Install] button for your application will be missing. I think it is related to the change in your keystore key, and I hope over a day or so it refreshes. If you are impatient, like me, and want to see the Install/Buy button next to your app immediately you need to clear the Cache, and Memory of your Google Play Store app.

You may also get a complaint that you have a previous incompatible version installed which can be solved with the following.

ubuntu@goodboy:~/Android/Sdk/platform-tools$ ./adb uninstall "your.app.package.name"
Success

Thoughts

Considering this was a fresh install, with no errors or warning generated on install… very disappointed.

Why! Why is this so complicated? No real development has taken place and there are massive problems to be solved.

The problems are massive barriers to developers, especially younger developers with little experience wanting to stick to the Linux OS and just get started coding.

I’m disappointed that I have had to crawl through the weeds of the internet to figure these problems out.

Please do better Unity.

  • If I can use Android Studio to fix the NDK issue, you can fix Unity Hub to do the same.
  • For critical issues like keystores, why not create a pop up pointing directly to a solution or give the developers an interactive window to fix and create a new keystore for example?

Leave a Reply

%d bloggers like this: