dotnet/maui · error · Exception

All key generation methods failed. Unable to create ADB keys

Error message

All key generation methods failed. Unable to create ADB keys.

What it means

Thrown after three sequential ADB key-generation strategies all return false: (1) automatic generation, (2) CreateAdbKeysUsingAutomaticGeneration, and (3) CreateAdbKeysUsingOpenSSL fallback. ADB key pairs (adbkey/adbkey.pub) are needed to authorize the host with the emulator/device, and none of the available methods could produce them.

Source

Thrown at eng/devices/android.cake:917

        keysGenerated = CreateAdbKeysUsingKeygen(adbKeyPath, adbKeyFile);

		// Option 2: Use automatic key generation by connecting to a device
        if (!keysGenerated)
        {
            Information("Option 1 failed. Trying automatic key generation...");
            keysGenerated = CreateAdbKeysUsingAutomaticGeneration(settings, adbKeyFile, adbKeyPubFile);
        }
		
		// Option 3: Use OpenSSL as fallback (if available)
        if (!keysGenerated)
        {
            Information("Option 2 failed. Trying OpenSSL key generation...");
            keysGenerated = CreateAdbKeysUsingOpenSSL(adbKeyFile, adbKeyPubFile);
        }
        
        if (!keysGenerated)
        {
            throw new Exception("All key generation methods failed. Unable to create ADB keys.");
        }
        
      	// Verify keys were created
        if (!System.IO.File.Exists(adbKeyFile) || !System.IO.File.Exists(adbKeyPubFile))
        {
            throw new Exception("ADB keys were not created successfully.");
        }

        Information("ADB keys generated successfully!");

        // Set correct file permissions for ADB keys (Unix systems only)
        if (IsRunningOnLinux())
        {
            Information("Setting correct permissions for ADB keys...");
            StartProcess("chmod", $"600 {adbKeyFile}");
            StartProcess("chmod", $"600 {adbKeyPubFile}");
        }

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Ensure openssl is installed and on PATH (`openssl version`), since it is the last-resort generator.
  2. Check write permissions and free space in the ~/.android directory where adbkey files are written.
  3. In minimal containers, install openssl and any required crypto libraries.
  4. Pre-create the ~/.android directory and verify the adbKeyFile path is writable by the cake process.
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight capability checks
if (StartProcess("which", new ProcessSettings { Arguments = "openssl", Silent = true, RedirectStandardOutput = true }) != 0)
    Warning("openssl not found; ADB key generation may fail.");
if (!DirectoryExists(System.IO.Path.GetDirectoryName(adbKeyFile)))
    CreateDirectory(System.IO.Path.GetDirectoryName(adbKeyFile));

Prevention

When it happens

Trigger: All three key-generation methods return keysGenerated=false in sequence — neither the built-in automatic generator nor the OpenSSL fallback could write a valid RSA key pair to adbKeyFile/adbKeyPubFile.

Common situations: OpenSSL not installed or not on PATH (so the fallback fails); no write permission to the ~/.android directory; a locked-down container lacking keytool/openssl/ssh-keygen; disk full.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/94522aa83ef3e39d. Report an issue: GitHub.