gpt4 book ai didi

android - 在 Linux 上为 Android 构建 Ionic 应用程序失败,退出代码 2 : Failed to find 'ANDROID_HOME'

转载 作者:太空宇宙 更新时间:2023-11-03 12:50:01 24 4
gpt4 key购买 nike

我正在尝试在适用于 Android 的 Linux/Ubuntu 14.04 上构建默认示例应用。

我在执行 sudo ionic build android 时收到一条标准错误消息:

Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.

(查看下面的完整日志)

但如果我这样做

echo $ANDROID_HOME && echo $JAVA_HOME && echo $ANT_HOME

/home/user3123726/Android/Sdk

/usr/lib/jvm/java-8-oracle

/usr/bin/ant

并且命令android和cordova也可用。

  • Android SDK 与当前可用的所有平台目标一起安装(加上 Android SDK 工具、平台工具和构建工具)
  • 已安装 npm 3.3.9 和 Node 4.2.2
  • Cordova 5.3.3 是通过 npm 安装的
  • Ionic 1.7.7 是通过 npm 安装的
  • Apache Ant 1.9.3

ANDROID_HOME 也在 .bashrc 上定义:

export ANDROID_HOME=/home/user3123726/Android/Sdk

export PATH=${PATH}:/home/user3123726/Android/Sdk/platform-tools:/home/user3123726/Android/Sdk/tools

我不知道构建过程失败的原因是什么。感谢任何帮助 - 谢谢!

这里是 ionic 项目创建的完整日志(主要是创建、添加平台和构建):

ionic start myApp tabs

Downloading: https://github.com/driftyco/ionic-app-base/archive/master.zip

[=============================] 100% 0.0s

Downloading: https://github.com/driftyco/ionic-starter-tabs/archive/master.zip

[=============================] 100% 0.0s

Updated the hooks directory to have execute permissions Update Config.xml Initializing cordova project

Your Ionic project is ready to go! Some quick tips: [... shortened]

cd myApp

sudo ionic platform add android

Updated the hooks directory to have execute permissions

Downloading Default Ionic Resources

Downloading: https://github.com/driftyco/ionic-default-resources/archive/master.zip

[=============================] 100% 0.0s

Done adding default Ionic resources

Adding icons for platform: android

Adding android project...

Creating Cordova project for the Android platform:

Path: platforms/android

Package: com.ionicframework.myapp809922

Name: myApp

Activity: MainActivity

Android target: android-22

Copying template files...

Android project created with cordova-android@4.1.1

Running command: /home/user3123726/testing/myApp/hooks/after_prepare/010_add_platform_class.js /home/user3123726/testing/myApp

add to body class: platform-android

Saving platform to package.json file

sudo ionic build android

Running command: /home/user3123726/testing/myApp/hooks/after_prepare/010_add_platform_class.js /home/user3123726/testing/myApp

add to body class: platform-android

Running command: /home/user3123726/testing/myApp/platforms/android/cordova/build

[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.

Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.]

ERROR building one of the platforms: Error: /home/user3123726/testing/myApp/platforms/android/cordova/build: Command failed with exit code 2

You may not have the required environment or OS to build this project

Error: /home/user3123726/testing/myApp/platforms/android/cordova/build: Command failed with exit code 2

at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)

at emitTwo (events.js:87:13)

at ChildProcess.emit (events.js:172:7)

at maybeClose (internal/child_process.js:818:16)

at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

最佳答案

修复它:

是权限问题

sudo chown -R $(whoami) /home/user3123726/.cordova

赋予cordova权利

做了

ionic添加平台android

ionic 构建安卓

没有 sudo ;)

关于android - 在 Linux 上为 Android 构建 Ionic 应用程序失败,退出代码 2 : Failed to find 'ANDROID_HOME' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33564738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com