Android Studio终端中如何正确设置ExoPlayer FFmpeg扩展环境变量?
Hey there, let’s get this sorted out—those "not recognized" errors are happening because you’re using Unix-style command syntax in a Windows terminal (Android Studio’s default terminal on Windows is usually Command Prompt or PowerShell, which follow different variable-setting rules than Linux/macOS). Here’s how to fix it based on your terminal type:
For Windows Command Prompt (Cmd)
First navigate to your ExoPlayer checkout directory:
cd "<path to exoplayer checkout>"Keep the quotes around your path if it includes spaces, and replace
<path to exoplayer checkout>with your actual folder location.Set the
EXOPLAYER_ROOTvariable using Windows Cmd’s syntax:set EXOPLAYER_ROOT=%cd%%cd%automatically grabs the full path of your current directory.Define the FFmpeg extension path:
set FFMPEG_EXT_PATH=%EXOPLAYER_ROOT%\extensions\ffmpeg\src\mainVerify the variables are set correctly:
echo %EXOPLAYER_ROOT% echo %FFMPEG_EXT_PATH%
For Windows PowerShell
If you’re using PowerShell instead of Cmd, use these commands:
Navigate to your ExoPlayer directory:
cd "<path to exoplayer checkout>"Set the root variable with PowerShell’s location command:
$EXOPLAYER_ROOT = Get-LocationBuild the FFmpeg path using PowerShell’s path-joining tool:
$FFMPEG_EXT_PATH = Join-Path $EXOPLAYER_ROOT "extensions\ffmpeg\src\main"Check if the variables work as expected:
echo $EXOPLAYER_ROOT echo $FFMPEG_EXT_PATH
For Linux/macOS or WSL Terminal
If you’re using a Unix-like terminal (like on Mac, or Windows Subsystem for Linux), your original command just needs to separate commands with && to run them in sequence:
cd "<path to exoplayer checkout>" && EXOPLAYER_ROOT="$(pwd)" && FFMPEG_EXT_PATH="${EXOPLAYER_ROOT}/extensions/ffmpeg/src/main"
Alternatively, run them one line at a time for clarity:
cd "<path to exoplayer checkout>" EXOPLAYER_ROOT="$(pwd)" FFMPEG_EXT_PATH="${EXOPLAYER_ROOT}/extensions/ffmpeg/src/main"
Bonus: Making Variables Permanent (Optional)
If you set variables in Windows System Properties but Android Studio’s terminal still doesn’t recognize them, you need to restart Android Studio—the terminal inherits environment variables when the app launches, so changes won’t take effect until you restart it.
For Unix-like systems, you can add the variable definitions to your shell config file (e.g., ~/.bashrc or ~/.zshrc) to have them available every time you open a terminal.
Don’t forget to double-check your ExoPlayer checkout path—typos in the path are a common hidden culprit!
内容的提问来源于stack exchange,提问作者Abdullah Khan

