执行eas build --local构建Android时SDK路径未找到如何修复?
Android本地构建(
eas build --local)SDK路径问题修复方案 问题描述
执行eas build --local构建Android时触发异常,错误信息如下:
eas-build-local-nodejs/6d58e91b-2d03-4868-bb8c-bd07da09061f/build/node_modules/expo-modules-autolinking/scripts/android/autolinking_implementation.gradle' line: 356 [RUN_GRADLEW] * What went wrong: [RUN_GRADLEW] A problem occurred evaluating project ':expo'. [RUN_GRADLEW] > [RUN_GRADLEW] A problem occurred configuring project ':expo-modules-core'. [RUN_GRADLEW] > Failed to notify project evaluation listener. [RUN_GRADLEW] > SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your project's local properties file
环境信息
- Gradle 8
- Expo 49
项目配置
package.json依赖
"dependencies": { "@babel/plugin-proposal-unicode-property-regex": "^7.16.7", "@expo/config": "~8.1.1", "@expo/vector-icons": "^13.0.0", "@react-native-async-storage/async-storage": "1.18.2", "@react-native-community/masked-view": "0.1.10", "@react-native-community/netinfo": "9.3.10", "@react-navigation/native": "^5.1.5", "@react-navigation/stack": "^5.6.0", "@stripe/stripe-react-native": "0.28.0", "@types/node": "^13.11.0", "@types/react-native-tab-view": "^2.3.0", "@types/react-redux": "^7.1.7", "@use-expo/font": "^2.0.0", "@amazon-cognito-identity-js": "^6.3.6", "@aws-amplify": "^4.3.4", "aws-amplify-react-native": "^5.0.3", "aws-sdk": "^2.1022.0", "expo": "^49.0.0", "expo-background-fetch": "~11.3.0", "expo-build-properties": "^0.8.3", "expo-constants": "~14.4.2", "expo-device": "~5.4.0", "expo-font": "~11.4.0", "expo-image-picker": "~14.3.2", "expo-linking": "~5.0.2", "expo-localization": "~14.3.0", "expo-notifications": "~0.20.1", "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "expo-task-manager": "~11.3.0", "expo-tracking-transparency": "~3.1.0", "expo-web-browser": "~12.3.2", "i18n-js": "^3.8.0", "patch-package": "^6.5.0", "prop-types": "^15.7.2", "react": "18.2.0", "react-native": "0.72.5", "react-native-dotenv": "^0.2.0", "react-native-elements": "^2.3.2", "react-native-email-link": "^1.14.1", "react-native-gallery-swiper": "^1.26.4", "react-native-gesture-handler": "~2.12.0", "react-native-get-random-values": "~1.9.0", "react-native-gifted-chat": "^0.16.3", "react-native-google-places-autocomplete": "^1.7.1", "react-native-htmlview": "^0.16.0", "react-native-image-slider-box": "^2.0.6", "react-native-mime-types": "^2.3.0", "react-native-pager-view": "6.2.0", "react-native-picker-select": "^8.0.4", "react-native-purchases": "5.0.2", "react-native-reanimated": "~3.3.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-sectioned-multi-select": "0.9.1", "react-native-tab-view": "^3.5.2", "react-native-typescript-transformer": "^1.2.13", "react-redux": "^7.2.0", "redux": "^4.0.5", "sentry-expo": "^7.0.1" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-typescript": "^7.9.0", "@types/jest": "^29.5.5", "@types/react": "~18.2.14", "@types/react-native-dotenv": "^0.2.0", "@typescript-eslint/eslint-plugin": "^3.0.0", "@typescript-eslint/parser": "^3.0.0", "audit-ci": "^6.6.1", "babel-eslint": "^10.1.0", "babel-preset-expo": "^9.5.0", "eslint": "^6.8.0", "eslint-config-prettier": "^6.10.1", "eslint-plugin-import": "^2.20.2", "eslint-plugin-jsx-a11y": "^6.2.3", "eslint-plugin-prettier": "^3.1.2", "eslint-plugin-react": "^7.20.0", "eslint-plugin-react-hooks": "^2.5.1", "eslint-plugin-react-native": "^3.8.1", "expo-dev-client": "~2.4.11", "ghooks": "^2.0.4", "jest": "^29.2.1", "prettier": "^2.0.2", "ts-jest": "24.0.0", "typescript": "^5.1.3" }
eas.json配置
{ "cli": { "version": ">= 0.1.0" }, "build": { "development": { "developmentClient": true, "distribution": "internal", "channel": "development" }, "preview": { "distribution": "internal" }, "production": { "ios": { "cocoapods": "1.11.2" }, "android": { "buildType": "apk" }, "env": { "ANDROID_SDK_ROOT": "/Home/Sdk", "GOOGLE_SERVICES_FILE": "./google-service.json" } } }, "submit": { "production": {} } }
已尝试expo doctor排查,未解决问题。
修复方案
1. 验证SDK路径正确性
先确认你在eas.json中配置的/Home/Sdk是否为本地Android SDK的真实路径:
- macOS默认路径:
~/Library/Android/sdk - Linux默认路径:
~/Android/Sdk - Windows默认路径:
C:\Users\<你的用户名>\AppData\Local\Android\Sdk
确保路径存在,且能正常访问platforms、tools等核心目录。
2. 全局配置环境变量
仅在production环境配置SDK路径无法覆盖所有构建场景,建议全局设置环境变量:
- macOS/Linux:在
~/.zshrc、~/.bash_profile或~/.profile中添加:
添加后执行export ANDROID_HOME=/你的真实SDK路径 export ANDROID_SDK_ROOT=$ANDROID_HOME export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-toolssource ~/.zshrc(对应你的shell类型)使配置生效。 - Windows:在系统环境变量中新增
ANDROID_HOME和ANDROID_SDK_ROOT,值为SDK路径;再将%ANDROID_HOME%\tools和%ANDROID_HOME%\platform-tools添加到Path变量中。
3. 配置local.properties文件
在项目的android目录下创建或修改local.properties文件,添加:
sdk.dir=/你的真实SDK路径
Windows系统需转义路径分隔符,例如:C:\\Users\\用户名\\AppData\\Local\\Android\\Sdk
4. 统一所有构建环境的SDK配置
将SDK路径配置添加到eas.json的所有构建环境中,确保开发、预览、生产构建都能读取到:
"build": { "development": { "developmentClient": true, "distribution": "internal", "channel": "development", "env": { "ANDROID_SDK_ROOT": "/你的真实SDK路径" } }, "preview": { "distribution": "internal", "env": { "ANDROID_SDK_ROOT": "/你的真实SDK路径" } }, "production": { // 原有配置... } }
5. 验证配置有效性
执行以下命令确认环境变量是否生效:
- macOS/Linux:
echo $ANDROID_SDK_ROOT - Windows:
echo %ANDROID_SDK_ROOT%
同时检查android/local.properties中的路径是否正确。
内容的提问来源于stack exchange,提问作者Tamás Czakó
相关产品推荐
相关产品推荐

