Ionic 找不到 android_sdk_root,无法在手机上构建应用程序
Posted
技术标签:
【中文标题】Ionic 找不到 android_sdk_root,无法在手机上构建应用程序【英文标题】:Ionic Failed to find android_sdk_root, cannot build app on phone 【发布时间】:2021-10-21 05:59:30 【问题描述】:当我在 vscode 终端中提示 ionic cordova build android 时,过了一会儿它给了我:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Failed to find 'ANDROID_SDK_ROOT' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd build android exited with exit code 1.
Re-running this command with the --verbose flag may provide more
information.
[VSCode 终端图片][1]
我检查了我的路径,我认为没问题?
[环境变量图片][2]
我可以得到一些帮助吗?
我想在手机上测试我的应用。我的手机已经在 Xamarin 上运行。
编辑(添加详细):
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Failed to find 'ANDROID_SDK_ROOT' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
CordovaError: Failed to find 'ANDROID_SDK_ROOT' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
at C:\Users\CGarcia\Documents\WorkersAppIONIC\ionic-form-ui\platforms\android\cordova\lib\check_reqs.js:260:19
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 1)
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd build android --verbose exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
ionic:utils-process onBeforeExit handler: running 2 functions +1ms
ionic:utils-process error while killing process tree for 6708: Error: Command failed: taskkill /pid 6708 /T /F
ionic:utils-process ERROR: no se encontr� el proceso "6708".
ionic:utils-process
ionic:utils-process at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process at ChildProcess.emit (events.js:315:20)
ionic:utils-process at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
ionic:utils-process killed: false,
ionic:utils-process code: 128,
ionic:utils-process signal: null,
ionic:utils-process cmd: 'taskkill /pid 6708 /T /F'
ionic:utils-process +119ms
ionic:utils-process onBeforeExit handler: error from function: Error: Command failed: taskkill /pid 6708 /T /F
ionic:utils-process ERROR: no se encontr� el proceso "6708".
ionic:utils-process
ionic:utils-process at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process at ChildProcess.emit (events.js:315:20)
ionic:utils-process at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
ionic:utils-process killed: false,
ionic:utils-process code: 128,
ionic:utils-process signal: null,
ionic:utils-process cmd: 'taskkill /pid 6708 /T /F'
ionic:utils-process +3ms
ionic:utils-process error while killing process tree for 8984: Error: Command failed: taskkill /pid 8984 /T /F
ionic:utils-process ERROR: no se encontr� el proceso "8984".
ionic:utils-process
ionic:utils-process at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process at ChildProcess.emit (events.js:315:20)
ionic:utils-process at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
ionic:utils-process killed: false,
ionic:utils-process code: 128,
ionic:utils-process signal: null,
ionic:utils-process cmd: 'taskkill /pid 8984 /T /F'
ionic:utils-process +7ms
ionic:utils-process onBeforeExit handler: error from function: Error: Command failed: taskkill /pid 8984 /T /F
ionic:utils-process ERROR: no se encontr� el proceso "8984".
ionic:utils-process
ionic:utils-process at ChildProcess.exithandler (child_process.js:308:12)
ionic:utils-process at ChildProcess.emit (events.js:315:20)
ionic:utils-process at maybeClose (internal/child_process.js:1048:16)
ionic:utils-process at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
ionic:utils-process killed: false,
ionic:utils-process code: 128,
ionic:utils-process signal: null,
ionic:utils-process cmd: 'taskkill /pid 8984 /T /F'
ionic:utils-process +3ms
ionic:utils-process processExit: exiting (exit code: 1) +3ms
编辑: 现在错误不同了:(直接用verbose)
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=C:\Program Files (x86)\Android\android-sdk\tools (recommended setting)
ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk\tools (DEPRECATED)
Using Android SDK: C:\Program Files (x86)\Android\android-sdk\tools
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
CordovaError: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
at Object.module.exports.check_gradle (C:\Users\CGarcia\Documents\WorkersAppIONIC\ionic-form-ui\platforms\android\cordova\lib\check_reqs.js:131:27)
at ProjectBuilder.prepEnv (C:\Users\CGarcia\Documents\WorkersAppIONIC\ionic-form-ui\platforms\android\cordova\lib\builders\ProjectBuilder.js:262:27)
at Api.module.exports.run (C:\Users\CGarcia\Documents\WorkersAppIONIC\ionic-form-ui\platforms\android\cordova\lib\build.js:168:20)
at C:\Users\CGarcia\Documents\WorkersAppIONIC\ionic-form-ui\platforms\android\cordova\Api.js:253:47
at processTicksAndRejections (internal/process/task_queues.js:93:5)
我在这台计算机上安装了 Android Studio,但从未在该用户上执行过它。我应该打开它吗? [1]:https://i.stack.imgur.com/BO5wx.png [2]:https://i.stack.imgur.com/qQ4VE.png
【问题讨论】:
您能否将C:\Program Files (x86)\Android\android-sdk\tools
添加到Path 变量中。然后在使用--verbose
标志重新启动终端后尝试构建命令。
我用 --verbose 标志编辑了问题并将两个路径都更改为 C:\Program Files (x86)\Android\android-sdk\tools
“将两条路径都更改为..”是什么意思?
我在环境变量的 C:\Program Files (x86)\Android\android-sdk 上有 ANDROID_SDK_ROOT 和 ANDROID_HOME。见图片。我把那些改成了你写给我的。
请按照您的 android sdk 路径 (C:\Program Files (x86)\Android\android-sdk
) 保留 ANDROID_SDK_ROOT 和 ANDROID_HOME。现在将 C:\Program Files (x86)\Android\android-sdk\tools
添加到 Path 变量中(通过选择 Path 并单击 env 变量中的 Edit > New)
【参考方案1】:
我遵循了 Akshaya Jeevan 的提示和 documentation
【讨论】:
以上是关于Ionic 找不到 android_sdk_root,无法在手机上构建应用程序的主要内容,如果未能解决你的问题,请参考以下文章
Ionic/Cordova 应用程序找不到 MainActivity