dotnet/maui · error · Exception
Failed to push ADB keys after multiple attempts.
Error message
Failed to push ADB keys after multiple attempts.
What it means
Thrown when the ADB key-push retry loop exhausts all attempts without pushSuccess becoming true. Each attempt tries to adb push the generated adbkey.pub to the device's /data/misc/adb/adb_keys, retrying with a 1-second sleep between attempts.
Source
Thrown at eng/devices/android.cake:988
var exitCode = StartProcess("adb", processSettings);
// Check exit code for success indicators
if (exitCode == 0)
{
Information("ADB key successfully pushed.");
pushSuccess = true;
break;
}
retries++;
Information($"Push attempt {retries} failed. Retrying in 1 second...");
System.Threading.Thread.Sleep(1000);
}
if (!pushSuccess)
{
throw new Exception("Failed to push ADB keys after multiple attempts.");
}
// Set proper permissions on the device key file
AdbShell("chmod 600 /data/misc/adb/adb_keys", settings);
// Restart ADB on device to apply changes
Information("Restarting ADB daemon on the device...");
AdbShell("stop adbd", settings);
System.Threading.Thread.Sleep(2000);
AdbShell("start adbd", settings);
System.Threading.Thread.Sleep(2000);
// Verify connectivity after all changes
var deviceCheck = StartProcess("adb", new ProcessSettings {
Arguments = "devices",
RedirectStandardOutput = true
});
View on GitHub (pinned to f377ff1c5e)
Solutions
- Confirm the emulator/device is online: `adb devices` should list it without 'unauthorized'.
- Restart adbd on the device (the script does this after a successful push; do it manually if needed) and re-run.
- If 'unauthorized', accept the RSA fingerprint dialog on the device/emulator UI, or ensure the key being pushed matches the one adb is using.
- Increase the retry count or add a longer backoff for flaky USB/emulator connections.
Defensive patterns
Strategy: retry
Validate before calling
// Confirm device reachable + authorized before pushing
var state = SafeAdbShell("getprop sys.boot_completed", settings).FirstOrDefault();
if (state != "1") throw new Exception("Device not booted; cannot push ADB keys."); Try / catch
int maxPushRetries = 5;
bool pushSuccess = false;
for (int i = 0; i < maxPushRetries && !pushSuccess; i++) {
try {
AdbPush(adbKeyPubFile, "/data/misc/adb/adb_keys", settings);
pushSuccess = true;
} catch (Exception ex) when (i < maxPushRetries - 1) {
Warning($"Push attempt {i+1} failed: {ex.Message}");
System.Threading.Thread.Sleep(1000 * (i + 1));
}
} Prevention
- Verify `adb devices` shows the target as 'device' (not 'unauthorized') before pushing.
- Restart adbd on the device if authorization is stuck.
- Use exponential backoff between push retries for flaky connections.
When it happens
Trigger: Every `adb push` attempt in the loop fails (returns non-zero or throws) and pushSuccess never flips to true before retries is exhausted.
Common situations: The emulator is not actually running or not reachable via ADB; ADB authorization is pending and the device rejects the push; the destination path /data/misc/adb is not writable (e.g. on a production build); adbd is in a bad state.
Related errors
- All key generation methods failed. Unable to create ADB keys
- ADB keys were not created successfully.
- The emulator did not finish booting in time.
- Environment variable 'ANDROID_SDK_ROOT' or 'ANDROID_HOME' mu
- JAVA_HOME environment variable isn't set. Set it to your JDK
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e504c0f978171efc.
Report an issue: GitHub.