dotnet/maui · error · Exception

ADB keys were not created successfully.

Error message

ADB keys were not created successfully.

What it means

Thrown when a key-generation method reported success (keysGenerated=true) but the subsequent existence check finds that either adbKeyFile or adbKeyPubFile does not exist on disk. This catches the inconsistent case where the generator returned true without actually writing both files.

Source

Thrown at eng/devices/android.cake:923

            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}");
        }

        // Set environment variable properly (platform specific)
        Information("Setting ADB_VENDOR_KEYS environment variable...");

        // This actually sets it for the current process
        SetEnvironmentVariable("ADB_VENDOR_KEYS", adbKeyPubFile);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Inspect the actual adbKeyFile/adbKeyPubFile paths logged by the script and check what (if anything) was written.
  2. Ensure the target directory exists and is writable before key generation runs.
  3. Review the specific generator method that returned true to see why it didn't write both files.
  4. As a workaround, manually generate the pair with `openssl` and place both files at the expected paths.
Defensive patterns

Strategy: validation

Validate before calling

if (keysGenerated && (!System.IO.File.Exists(adbKeyFile) || !System.IO.File.Exists(adbKeyPubFile))) {
    throw new Exception($"Generator reported success but files missing: {adbKeyFile}, {adbKeyPubFile}");
}

Prevention

When it happens

Trigger: keysGenerated is true (so the previous 'all methods failed' check passed) but System.IO.File.Exists(adbKeyFile) || System.IO.File.Exists(adbKeyPubFile) is false — one or both key files are missing despite the success flag.

Common situations: A generator wrote only the private key, wrote to a different path than expected, was interrupted, or the file was deleted between generation and verification; a bug in a generator returning true prematurely.

Related errors


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