多实例共享Android虚拟设备(AVD)时跨实例启动出现adb未授权错误的技术求助
Having struggled through this exact scenario myself, here's how to resolve the unauthorized error you're seeing when trying to launch shared AVDs from different instances:
Context Recap
You’ve got multiple instances with their own Android SDK installs, and you’ve moved the .android directory (where all AVDs live) to a shared, standalone drive. The problem: create an AVD on one instance, and only that instance can start it successfully. Any other instance throws an unauthorized error when running adb devices -l. Restarting the ADB server or regenerating adb keys hasn’t fixed it.
Root Cause
The core issue is inconsistent ADB key pairs across instances. Each instance generates its own unique adb key pair by default. When you create an AVD on one instance, that instance’s public key gets added to the emulator’s trusted list. Other instances, using their own distinct keys, aren’t recognized as trusted—hence the authorization failure. Your earlier attempts didn’t address this key mismatch.
Step-by-Step Solution
1. Use a Single Shared ADB Key Pair for All Instances
We need every instance to use the same key pair (the one already trusted by your AVDs):
- From the instance that can successfully launch the AVD, copy
adbkeyandadbkey.pubfrom its local~/.android/folder to your shared.androiddirectory (e.g.,/mnt/shared-drive/.android/). - On every other instance, delete the local key files and create symbolic links to the shared versions:
rm ~/.android/adbkey ~/.android/adbkey.pub ln -s /mnt/shared-drive/.android/adbkey ~/.android/adbkey ln -s /mnt/shared-drive/.android/adbkey.pub ~/.android/adbkey.pub
2. Confirm the Emulator Trusts the Shared Key
If you haven’t already, make sure the shared public key is in the emulator’s trusted list:
- Launch the AVD once from the original working instance (this ensures the emulator has accepted the shared key).
- If you still see authorization issues, manually push the shared key to the emulator:
# Start the AVD first emulator -avd test -gpu swiftshader_indirect -show-kernel -snapshot test -port 5542 # Push the trusted key adb root adb push /mnt/shared-drive/.android/adbkey.pub /data/misc/adb/authorized_keys
3. Set Environment Variables to Point to Shared AVDs
Ensure every instance knows where to find the shared AVDs by adding this to each instance’s shell profile (e.g., ~/.bashrc or ~/.zshrc):
export ANDROID_AVD_HOME=/mnt/shared-drive/.android/avd
This overrides the default local AVD path and tells all instances to look in the shared directory.
4. Restart ADB and Verify
On each instance, restart the ADB server to apply the new key setup:
adb kill-server adb start-server
Launch the AVD again, then run adb devices -l—you should now see the emulator listed as authorized.
Why Your Previous Fixes Didn’t Work
- Restarting the ADB server only refreshes the local connection, but doesn’t fix the key mismatch between instances.
- Regenerating adb keys on each instance creates new, untrusted keys that the emulator doesn’t recognize (it only trusts the key from the instance where the AVD was created).
内容的提问来源于stack exchange,提问作者Sabbiu Shah

