{"record":{"id":"e504c0f978171efc","repo":"dotnet/maui","slug":"failed-to-push-adb-keys-after-multiple-attempts","errorCode":null,"errorMessage":"Failed to push ADB keys after multiple attempts.","messagePattern":"Failed to push ADB keys after multiple attempts\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"eng/devices/android.cake","lineNumber":988,"sourceCode":"            \n            var exitCode = StartProcess(\"adb\", processSettings);\n            \n            // Check exit code for success indicators\n            if (exitCode == 0)\n            {\n                Information(\"ADB key successfully pushed.\");\n                pushSuccess = true;\n                break;\n            }\n\n            retries++;\n            Information($\"Push attempt {retries} failed. Retrying in 1 second...\");\n            System.Threading.Thread.Sleep(1000);\n        }\n\n        if (!pushSuccess)\n        {\n            throw new Exception(\"Failed to push ADB keys after multiple attempts.\");\n        }\n\n        // Set proper permissions on the device key file\n        AdbShell(\"chmod 600 /data/misc/adb/adb_keys\", settings);\n\n        // Restart ADB on device to apply changes\n        Information(\"Restarting ADB daemon on the device...\");\n        AdbShell(\"stop adbd\", settings);\n        System.Threading.Thread.Sleep(2000);\n        AdbShell(\"start adbd\", settings);\n        System.Threading.Thread.Sleep(2000);\n\n        // Verify connectivity after all changes\n        var deviceCheck = StartProcess(\"adb\", new ProcessSettings {\n            Arguments = \"devices\",\n            RedirectStandardOutput = true\n        });\n        ","sourceCodeStart":970,"sourceCodeEnd":1006,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/eng/devices/android.cake#L970-L1006","documentation":"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.","triggerScenarios":"Every `adb push` attempt in the loop fails (returns non-zero or throws) and pushSuccess never flips to true before retries is exhausted.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Confirm device reachable + authorized before pushing\nvar state = SafeAdbShell(\"getprop sys.boot_completed\", settings).FirstOrDefault();\nif (state != \"1\") throw new Exception(\"Device not booted; cannot push ADB keys.\");","typeGuard":null,"tryCatchPattern":"int maxPushRetries = 5;\nbool pushSuccess = false;\nfor (int i = 0; i < maxPushRetries && !pushSuccess; i++) {\n    try {\n        AdbPush(adbKeyPubFile, \"/data/misc/adb/adb_keys\", settings);\n        pushSuccess = true;\n    } catch (Exception ex) when (i < maxPushRetries - 1) {\n        Warning($\"Push attempt {i+1} failed: {ex.Message}\");\n        System.Threading.Thread.Sleep(1000 * (i + 1));\n    }\n}","preventionTips":["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."],"tags":["android","adb","adb-keys","push","retry","authorization"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}